@prism-draft/sdk 0.0.0-stage → 0.2.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.js ADDED
@@ -0,0 +1,1926 @@
1
+ // src/client.ts
2
+ import createOpenApiClient from "openapi-fetch";
3
+
4
+ // src/generated/resources.ts
5
+ class ApiKeys {
6
+ client;
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ async list(input, init) {
11
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/api-keys", {
12
+ params: { path: { workspaceId: input.workspaceId } },
13
+ signal: init?.signal,
14
+ timeoutMs: init?.timeoutMs
15
+ });
16
+ return data;
17
+ }
18
+ async create(input, init) {
19
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/api-keys", {
20
+ params: { path: { workspaceId: input.workspaceId } },
21
+ body: input.body,
22
+ signal: init?.signal,
23
+ timeoutMs: init?.timeoutMs
24
+ });
25
+ return data;
26
+ }
27
+ async revoke(input, init) {
28
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/api-keys/{keyId}", {
29
+ params: { path: { workspaceId: input.workspaceId, keyId: input.keyId } },
30
+ signal: init?.signal,
31
+ timeoutMs: init?.timeoutMs
32
+ });
33
+ return data;
34
+ }
35
+ async rotate(input, init) {
36
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/api-keys/{keyId}/rotate", {
37
+ params: { path: { workspaceId: input.workspaceId, keyId: input.keyId } },
38
+ signal: init?.signal,
39
+ timeoutMs: init?.timeoutMs
40
+ });
41
+ return data;
42
+ }
43
+ }
44
+
45
+ class ArticleGroups {
46
+ client;
47
+ constructor(client) {
48
+ this.client = client;
49
+ }
50
+ async list(input, init) {
51
+ const { data } = await this.client.GET("/api/article-groups", {
52
+ params: { query: { workspaceId: input.workspaceId, projectId: input.projectId, categoryId: input.categoryId, category: input.category, status: input.status, language: input.language, q: input.q, createdBy: input.createdBy, limit: input.limit, offset: input.offset } },
53
+ signal: init?.signal,
54
+ timeoutMs: init?.timeoutMs
55
+ });
56
+ return data;
57
+ }
58
+ async get(input, init) {
59
+ const { data } = await this.client.GET("/api/article-groups/{translationGroupId}", {
60
+ params: { path: { translationGroupId: input.translationGroupId } },
61
+ signal: init?.signal,
62
+ timeoutMs: init?.timeoutMs
63
+ });
64
+ return data;
65
+ }
66
+ async delete(input, init) {
67
+ const { data } = await this.client.DELETE("/api/article-groups/{translationGroupId}", {
68
+ params: { path: { translationGroupId: input.translationGroupId } },
69
+ signal: init?.signal,
70
+ timeoutMs: init?.timeoutMs
71
+ });
72
+ return data;
73
+ }
74
+ async approve(input, init) {
75
+ const { data } = await this.client.POST("/api/article-groups/{translationGroupId}/approve", {
76
+ params: { path: { translationGroupId: input.translationGroupId } },
77
+ body: input.body ?? {},
78
+ signal: init?.signal,
79
+ timeoutMs: init?.timeoutMs
80
+ });
81
+ return data;
82
+ }
83
+ async publish(input, init) {
84
+ const { data } = await this.client.POST("/api/article-groups/{translationGroupId}/publish", {
85
+ params: { path: { translationGroupId: input.translationGroupId } },
86
+ body: input.body ?? {},
87
+ signal: init?.signal,
88
+ timeoutMs: init?.timeoutMs
89
+ });
90
+ return data;
91
+ }
92
+ async unpublish(input, init) {
93
+ const { data } = await this.client.POST("/api/article-groups/{translationGroupId}/unpublish", {
94
+ params: { path: { translationGroupId: input.translationGroupId } },
95
+ body: input.body ?? {},
96
+ signal: init?.signal,
97
+ timeoutMs: init?.timeoutMs
98
+ });
99
+ return data;
100
+ }
101
+ }
102
+
103
+ class Articles {
104
+ client;
105
+ constructor(client) {
106
+ this.client = client;
107
+ }
108
+ async create(input, init) {
109
+ const { data } = await this.client.POST("/api/articles", {
110
+ body: input.body,
111
+ signal: init?.signal,
112
+ timeoutMs: init?.timeoutMs
113
+ });
114
+ return data;
115
+ }
116
+ async list(input, init) {
117
+ const { data } = await this.client.GET("/api/articles", {
118
+ params: { query: { workspaceId: input.workspaceId, projectId: input.projectId, categoryId: input.categoryId, category: input.category, status: input.status, language: input.language, slug: input.slug, q: input.q, createdBy: input.createdBy, limit: input.limit, offset: input.offset } },
119
+ signal: init?.signal,
120
+ timeoutMs: init?.timeoutMs
121
+ });
122
+ return data;
123
+ }
124
+ async duplicate(input, init) {
125
+ const { data } = await this.client.POST("/api/articles/{articleId}/duplicate", {
126
+ params: { path: { articleId: input.articleId } },
127
+ body: input.body ?? {},
128
+ signal: init?.signal,
129
+ timeoutMs: init?.timeoutMs
130
+ });
131
+ return data;
132
+ }
133
+ async get(input, init) {
134
+ const { data } = await this.client.GET("/api/articles/{articleId}", {
135
+ params: { path: { articleId: input.articleId }, query: { stripLead: input.stripLead } },
136
+ signal: init?.signal,
137
+ timeoutMs: init?.timeoutMs
138
+ });
139
+ return data;
140
+ }
141
+ async update(input, init) {
142
+ const { data } = await this.client.PATCH("/api/articles/{articleId}", {
143
+ params: { path: { articleId: input.articleId } },
144
+ body: input.body ?? {},
145
+ signal: init?.signal,
146
+ timeoutMs: init?.timeoutMs
147
+ });
148
+ return data;
149
+ }
150
+ async delete(input, init) {
151
+ const { data } = await this.client.DELETE("/api/articles/{articleId}", {
152
+ params: { path: { articleId: input.articleId } },
153
+ signal: init?.signal,
154
+ timeoutMs: init?.timeoutMs
155
+ });
156
+ return data;
157
+ }
158
+ async submit(input, init) {
159
+ const { data } = await this.client.POST("/api/articles/{articleId}/submit", {
160
+ params: { path: { articleId: input.articleId } },
161
+ signal: init?.signal,
162
+ timeoutMs: init?.timeoutMs
163
+ });
164
+ return data;
165
+ }
166
+ async approve(input, init) {
167
+ const { data } = await this.client.POST("/api/articles/{articleId}/approve", {
168
+ params: { path: { articleId: input.articleId } },
169
+ body: input.body ?? {},
170
+ signal: init?.signal,
171
+ timeoutMs: init?.timeoutMs
172
+ });
173
+ return data;
174
+ }
175
+ async reject(input, init) {
176
+ const { data } = await this.client.POST("/api/articles/{articleId}/reject", {
177
+ params: { path: { articleId: input.articleId } },
178
+ body: input.body ?? {},
179
+ signal: init?.signal,
180
+ timeoutMs: init?.timeoutMs
181
+ });
182
+ return data;
183
+ }
184
+ async requestChanges(input, init) {
185
+ const { data } = await this.client.POST("/api/articles/{articleId}/request-changes", {
186
+ params: { path: { articleId: input.articleId } },
187
+ body: input.body ?? {},
188
+ signal: init?.signal,
189
+ timeoutMs: init?.timeoutMs
190
+ });
191
+ return data;
192
+ }
193
+ async publish(input, init) {
194
+ const { data } = await this.client.POST("/api/articles/{articleId}/publish", {
195
+ params: { path: { articleId: input.articleId } },
196
+ body: input.body ?? {},
197
+ signal: init?.signal,
198
+ timeoutMs: init?.timeoutMs
199
+ });
200
+ return data;
201
+ }
202
+ async unpublish(input, init) {
203
+ const { data } = await this.client.POST("/api/articles/{articleId}/unpublish", {
204
+ params: { path: { articleId: input.articleId } },
205
+ signal: init?.signal,
206
+ timeoutMs: init?.timeoutMs
207
+ });
208
+ return data;
209
+ }
210
+ async transitionTranslations(input, init) {
211
+ const { data } = await this.client.POST("/api/articles/{articleId}/translations/{action}", {
212
+ params: { path: { articleId: input.articleId, action: input.action } },
213
+ body: input.body ?? {},
214
+ signal: init?.signal,
215
+ timeoutMs: init?.timeoutMs
216
+ });
217
+ return data;
218
+ }
219
+ async listReviews(input, init) {
220
+ const { data } = await this.client.GET("/api/articles/{articleId}/reviews", {
221
+ params: { path: { articleId: input.articleId } },
222
+ signal: init?.signal,
223
+ timeoutMs: init?.timeoutMs
224
+ });
225
+ return data;
226
+ }
227
+ async listVersions(input, init) {
228
+ const { data } = await this.client.GET("/api/articles/{articleId}/versions", {
229
+ params: { path: { articleId: input.articleId } },
230
+ signal: init?.signal,
231
+ timeoutMs: init?.timeoutMs
232
+ });
233
+ return data;
234
+ }
235
+ async getVersion(input, init) {
236
+ const { data } = await this.client.GET("/api/articles/{articleId}/versions/{version}", {
237
+ params: { path: { articleId: input.articleId, version: input.version } },
238
+ signal: init?.signal,
239
+ timeoutMs: init?.timeoutMs
240
+ });
241
+ return data;
242
+ }
243
+ async getSources(input, init) {
244
+ const { data } = await this.client.GET("/api/articles/{articleId}/sources", {
245
+ params: { path: { articleId: input.articleId } },
246
+ signal: init?.signal,
247
+ timeoutMs: init?.timeoutMs
248
+ });
249
+ return data;
250
+ }
251
+ async restoreVersion(input, init) {
252
+ const { data } = await this.client.POST("/api/articles/{articleId}/versions/{version}/restore", {
253
+ params: { path: { articleId: input.articleId, version: input.version } },
254
+ signal: init?.signal,
255
+ timeoutMs: init?.timeoutMs
256
+ });
257
+ return data;
258
+ }
259
+ async listComments(input, init) {
260
+ const { data } = await this.client.GET("/api/articles/{articleId}/comments", {
261
+ params: { path: { articleId: input.articleId }, query: { status: input.status } },
262
+ signal: init?.signal,
263
+ timeoutMs: init?.timeoutMs
264
+ });
265
+ return data;
266
+ }
267
+ async addComment(input, init) {
268
+ const { data } = await this.client.POST("/api/articles/{articleId}/comments", {
269
+ params: { path: { articleId: input.articleId } },
270
+ body: input.body,
271
+ signal: init?.signal,
272
+ timeoutMs: init?.timeoutMs
273
+ });
274
+ return data;
275
+ }
276
+ async resolveComment(input, init) {
277
+ const { data } = await this.client.POST("/api/articles/{articleId}/comments/{commentId}/resolve", {
278
+ params: { path: { articleId: input.articleId, commentId: input.commentId } },
279
+ signal: init?.signal,
280
+ timeoutMs: init?.timeoutMs
281
+ });
282
+ return data;
283
+ }
284
+ async reopenComment(input, init) {
285
+ const { data } = await this.client.POST("/api/articles/{articleId}/comments/{commentId}/reopen", {
286
+ params: { path: { articleId: input.articleId, commentId: input.commentId } },
287
+ signal: init?.signal,
288
+ timeoutMs: init?.timeoutMs
289
+ });
290
+ return data;
291
+ }
292
+ async checkDuplicates(input, init) {
293
+ const { data } = await this.client.GET("/api/projects/{projectId}/duplicate-check", {
294
+ params: { path: { projectId: input.projectId }, query: { title: input.title, slug: input.slug, language: input.language } },
295
+ signal: init?.signal,
296
+ timeoutMs: init?.timeoutMs
297
+ });
298
+ return data;
299
+ }
300
+ async setHeroFromUrl(input, init) {
301
+ const { data } = await this.client.POST("/api/articles/{articleId}/hero", {
302
+ params: { path: { articleId: input.articleId } },
303
+ body: input.body,
304
+ signal: init?.signal,
305
+ timeoutMs: init?.timeoutMs
306
+ });
307
+ return data;
308
+ }
309
+ async setHeroFromFile(input, init) {
310
+ const { data } = await this.client.PUT("/api/articles/{articleId}/hero/file", {
311
+ params: { path: { articleId: input.articleId }, query: { altText: input.altText } },
312
+ body: input.body,
313
+ bodySerializer: (body) => body,
314
+ headers: { "content-type": input.contentType },
315
+ signal: init?.signal,
316
+ timeoutMs: init?.timeoutMs
317
+ });
318
+ return data;
319
+ }
320
+ async detachHeroFromBody(input, init) {
321
+ const { data } = await this.client.POST("/api/articles/{articleId}/hero/detach-from-body", {
322
+ params: { path: { articleId: input.articleId } },
323
+ signal: init?.signal,
324
+ timeoutMs: init?.timeoutMs
325
+ });
326
+ return data;
327
+ }
328
+ }
329
+
330
+ class Billing {
331
+ client;
332
+ constructor(client) {
333
+ this.client = client;
334
+ }
335
+ async listCreditPackages(init) {
336
+ const { data } = await this.client.GET("/api/credit-packages", {
337
+ signal: init?.signal,
338
+ timeoutMs: init?.timeoutMs
339
+ });
340
+ return data;
341
+ }
342
+ async getCredits(input, init) {
343
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/credits", {
344
+ params: { path: { workspaceId: input.workspaceId } },
345
+ signal: init?.signal,
346
+ timeoutMs: init?.timeoutMs
347
+ });
348
+ return data;
349
+ }
350
+ async adjustCredits(input, init) {
351
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/credits/adjust", {
352
+ params: { path: { workspaceId: input.workspaceId } },
353
+ body: input.body,
354
+ signal: init?.signal,
355
+ timeoutMs: init?.timeoutMs
356
+ });
357
+ return data;
358
+ }
359
+ async listPlans(init) {
360
+ const { data } = await this.client.GET("/api/plans", {
361
+ signal: init?.signal,
362
+ timeoutMs: init?.timeoutMs
363
+ });
364
+ return data;
365
+ }
366
+ async getSubscription(input, init) {
367
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/subscription", {
368
+ params: { path: { workspaceId: input.workspaceId } },
369
+ signal: init?.signal,
370
+ timeoutMs: init?.timeoutMs
371
+ });
372
+ return data;
373
+ }
374
+ async startSubscriptionCheckout(input, init) {
375
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/subscription/checkout", {
376
+ params: { path: { workspaceId: input.workspaceId } },
377
+ body: input.body,
378
+ signal: init?.signal,
379
+ timeoutMs: init?.timeoutMs
380
+ });
381
+ return data;
382
+ }
383
+ async openPortal(input, init) {
384
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/subscription/portal", {
385
+ params: { path: { workspaceId: input.workspaceId } },
386
+ body: input.body ?? {},
387
+ signal: init?.signal,
388
+ timeoutMs: init?.timeoutMs
389
+ });
390
+ return data;
391
+ }
392
+ async startCheckout(input, init) {
393
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/checkout", {
394
+ params: { path: { workspaceId: input.workspaceId } },
395
+ body: input.body,
396
+ signal: init?.signal,
397
+ timeoutMs: init?.timeoutMs
398
+ });
399
+ return data;
400
+ }
401
+ }
402
+
403
+ class Blog {
404
+ client;
405
+ constructor(client) {
406
+ this.client = client;
407
+ }
408
+ async listPosts(input, init) {
409
+ const { data } = await this.client.GET("/api/blog/posts", {
410
+ params: { query: { locale: input.locale, limit: input.limit, offset: input.offset, category: input.category } },
411
+ signal: init?.signal,
412
+ timeoutMs: init?.timeoutMs
413
+ });
414
+ return data;
415
+ }
416
+ async listCategories(input, init) {
417
+ const { data } = await this.client.GET("/api/blog/categories", {
418
+ params: { query: { locale: input.locale } },
419
+ signal: init?.signal,
420
+ timeoutMs: init?.timeoutMs
421
+ });
422
+ return data;
423
+ }
424
+ async getPost(input, init) {
425
+ const { data } = await this.client.GET("/api/blog/posts/{slug}", {
426
+ params: { path: { slug: input.slug }, query: { language: input.language } },
427
+ signal: init?.signal,
428
+ timeoutMs: init?.timeoutMs
429
+ });
430
+ return data;
431
+ }
432
+ async getPostEdit(input, init) {
433
+ const { data } = await this.client.GET("/api/blog/posts/{slug}/edit", {
434
+ params: { path: { slug: input.slug }, query: { language: input.language } },
435
+ signal: init?.signal,
436
+ timeoutMs: init?.timeoutMs
437
+ });
438
+ return data;
439
+ }
440
+ }
441
+
442
+ class BrandVoices {
443
+ client;
444
+ constructor(client) {
445
+ this.client = client;
446
+ }
447
+ async list(input, init) {
448
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/brand-voices", {
449
+ params: { path: { workspaceId: input.workspaceId }, query: { projectId: input.projectId } },
450
+ signal: init?.signal,
451
+ timeoutMs: init?.timeoutMs
452
+ });
453
+ return data;
454
+ }
455
+ async create(input, init) {
456
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/brand-voices", {
457
+ params: { path: { workspaceId: input.workspaceId } },
458
+ body: input.body,
459
+ signal: init?.signal,
460
+ timeoutMs: init?.timeoutMs
461
+ });
462
+ return data;
463
+ }
464
+ async update(input, init) {
465
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/brand-voices/{voiceId}", {
466
+ params: { path: { workspaceId: input.workspaceId, voiceId: input.voiceId } },
467
+ body: input.body ?? {},
468
+ signal: init?.signal,
469
+ timeoutMs: init?.timeoutMs
470
+ });
471
+ return data;
472
+ }
473
+ async delete(input, init) {
474
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/brand-voices/{voiceId}", {
475
+ params: { path: { workspaceId: input.workspaceId, voiceId: input.voiceId } },
476
+ signal: init?.signal,
477
+ timeoutMs: init?.timeoutMs
478
+ });
479
+ return data;
480
+ }
481
+ }
482
+
483
+ class Briefs {
484
+ client;
485
+ constructor(client) {
486
+ this.client = client;
487
+ }
488
+ async draft(input, init) {
489
+ const { data } = await this.client.POST("/api/projects/{projectId}/brief", {
490
+ params: { path: { projectId: input.projectId } },
491
+ body: input.body,
492
+ signal: init?.signal,
493
+ timeoutMs: init?.timeoutMs
494
+ });
495
+ return data;
496
+ }
497
+ async list(input, init) {
498
+ const { data } = await this.client.GET("/api/projects/{projectId}/briefs", {
499
+ params: { path: { projectId: input.projectId } },
500
+ signal: init?.signal,
501
+ timeoutMs: init?.timeoutMs
502
+ });
503
+ return data;
504
+ }
505
+ async create(input, init) {
506
+ const { data } = await this.client.POST("/api/projects/{projectId}/briefs", {
507
+ params: { path: { projectId: input.projectId } },
508
+ body: input.body,
509
+ signal: init?.signal,
510
+ timeoutMs: init?.timeoutMs
511
+ });
512
+ return data;
513
+ }
514
+ async get(input, init) {
515
+ const { data } = await this.client.GET("/api/briefs/{briefId}", {
516
+ params: { path: { briefId: input.briefId } },
517
+ signal: init?.signal,
518
+ timeoutMs: init?.timeoutMs
519
+ });
520
+ return data;
521
+ }
522
+ async update(input, init) {
523
+ const { data } = await this.client.PATCH("/api/briefs/{briefId}", {
524
+ params: { path: { briefId: input.briefId } },
525
+ body: input.body ?? {},
526
+ signal: init?.signal,
527
+ timeoutMs: init?.timeoutMs
528
+ });
529
+ return data;
530
+ }
531
+ async delete(input, init) {
532
+ const { data } = await this.client.DELETE("/api/briefs/{briefId}", {
533
+ params: { path: { briefId: input.briefId } },
534
+ signal: init?.signal,
535
+ timeoutMs: init?.timeoutMs
536
+ });
537
+ return data;
538
+ }
539
+ }
540
+
541
+ class Calendar {
542
+ client;
543
+ constructor(client) {
544
+ this.client = client;
545
+ }
546
+ async list(input, init) {
547
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/calendar", {
548
+ params: { path: { workspaceId: input.workspaceId }, query: { from: input.from, to: input.to } },
549
+ signal: init?.signal,
550
+ timeoutMs: init?.timeoutMs
551
+ });
552
+ return data;
553
+ }
554
+ async create(input, init) {
555
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/calendar", {
556
+ params: { path: { workspaceId: input.workspaceId } },
557
+ body: input.body,
558
+ signal: init?.signal,
559
+ timeoutMs: init?.timeoutMs
560
+ });
561
+ return data;
562
+ }
563
+ async update(input, init) {
564
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/calendar/{itemId}", {
565
+ params: { path: { workspaceId: input.workspaceId, itemId: input.itemId } },
566
+ body: input.body ?? {},
567
+ signal: init?.signal,
568
+ timeoutMs: init?.timeoutMs
569
+ });
570
+ return data;
571
+ }
572
+ async delete(input, init) {
573
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/calendar/{itemId}", {
574
+ params: { path: { workspaceId: input.workspaceId, itemId: input.itemId } },
575
+ signal: init?.signal,
576
+ timeoutMs: init?.timeoutMs
577
+ });
578
+ return data;
579
+ }
580
+ }
581
+
582
+ class Categories {
583
+ client;
584
+ constructor(client) {
585
+ this.client = client;
586
+ }
587
+ async list(input, init) {
588
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/categories", {
589
+ params: { path: { workspaceId: input.workspaceId } },
590
+ signal: init?.signal,
591
+ timeoutMs: init?.timeoutMs
592
+ });
593
+ return data;
594
+ }
595
+ async create(input, init) {
596
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/categories", {
597
+ params: { path: { workspaceId: input.workspaceId } },
598
+ body: input.body,
599
+ signal: init?.signal,
600
+ timeoutMs: init?.timeoutMs
601
+ });
602
+ return data;
603
+ }
604
+ async update(input, init) {
605
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/categories/{categoryId}", {
606
+ params: { path: { workspaceId: input.workspaceId, categoryId: input.categoryId } },
607
+ body: input.body ?? {},
608
+ signal: init?.signal,
609
+ timeoutMs: init?.timeoutMs
610
+ });
611
+ return data;
612
+ }
613
+ async delete(input, init) {
614
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/categories/{categoryId}", {
615
+ params: { path: { workspaceId: input.workspaceId, categoryId: input.categoryId } },
616
+ signal: init?.signal,
617
+ timeoutMs: init?.timeoutMs
618
+ });
619
+ return data;
620
+ }
621
+ async setForArticle(input, init) {
622
+ const { data } = await this.client.PUT("/api/articles/{articleId}/categories", {
623
+ params: { path: { articleId: input.articleId } },
624
+ body: input.body,
625
+ signal: init?.signal,
626
+ timeoutMs: init?.timeoutMs
627
+ });
628
+ return data;
629
+ }
630
+ async suggestForArticle(input, init) {
631
+ const { data } = await this.client.POST("/api/articles/{articleId}/categories/suggest", {
632
+ params: { path: { articleId: input.articleId } },
633
+ signal: init?.signal,
634
+ timeoutMs: init?.timeoutMs
635
+ });
636
+ return data;
637
+ }
638
+ async suggestForProject(input, init) {
639
+ const { data } = await this.client.POST("/api/projects/{projectId}/categories/suggest", {
640
+ params: { path: { projectId: input.projectId } },
641
+ signal: init?.signal,
642
+ timeoutMs: init?.timeoutMs
643
+ });
644
+ return data;
645
+ }
646
+ async translate(input, init) {
647
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/categories/{categoryId}/translate", {
648
+ params: { path: { workspaceId: input.workspaceId, categoryId: input.categoryId } },
649
+ body: input.body,
650
+ signal: init?.signal,
651
+ timeoutMs: init?.timeoutMs
652
+ });
653
+ return data;
654
+ }
655
+ }
656
+
657
+ class ContentTemplates {
658
+ client;
659
+ constructor(client) {
660
+ this.client = client;
661
+ }
662
+ async list(input, init) {
663
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/content-templates", {
664
+ params: { path: { workspaceId: input.workspaceId } },
665
+ signal: init?.signal,
666
+ timeoutMs: init?.timeoutMs
667
+ });
668
+ return data;
669
+ }
670
+ async create(input, init) {
671
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/content-templates", {
672
+ params: { path: { workspaceId: input.workspaceId } },
673
+ body: input.body,
674
+ signal: init?.signal,
675
+ timeoutMs: init?.timeoutMs
676
+ });
677
+ return data;
678
+ }
679
+ async update(input, init) {
680
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/content-templates/{templateId}", {
681
+ params: { path: { workspaceId: input.workspaceId, templateId: input.templateId } },
682
+ body: input.body ?? {},
683
+ signal: init?.signal,
684
+ timeoutMs: init?.timeoutMs
685
+ });
686
+ return data;
687
+ }
688
+ async delete(input, init) {
689
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/content-templates/{templateId}", {
690
+ params: { path: { workspaceId: input.workspaceId, templateId: input.templateId } },
691
+ signal: init?.signal,
692
+ timeoutMs: init?.timeoutMs
693
+ });
694
+ return data;
695
+ }
696
+ }
697
+
698
+ class Dashboard {
699
+ client;
700
+ constructor(client) {
701
+ this.client = client;
702
+ }
703
+ async getAnalytics(input, init) {
704
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/analytics", {
705
+ params: { path: { workspaceId: input.workspaceId }, query: { days: input.days } },
706
+ signal: init?.signal,
707
+ timeoutMs: init?.timeoutMs
708
+ });
709
+ return data;
710
+ }
711
+ async getTrends(input, init) {
712
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/trends", {
713
+ params: { path: { workspaceId: input.workspaceId }, query: { days: input.days } },
714
+ signal: init?.signal,
715
+ timeoutMs: init?.timeoutMs
716
+ });
717
+ return data;
718
+ }
719
+ async getArticleCounts(input, init) {
720
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/article-counts", {
721
+ params: { path: { workspaceId: input.workspaceId } },
722
+ signal: init?.signal,
723
+ timeoutMs: init?.timeoutMs
724
+ });
725
+ return data;
726
+ }
727
+ async listJobs(input, init) {
728
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/jobs", {
729
+ params: { path: { workspaceId: input.workspaceId }, query: { limit: input.limit, failedWithinDays: input.failedWithinDays } },
730
+ signal: init?.signal,
731
+ timeoutMs: init?.timeoutMs
732
+ });
733
+ return data;
734
+ }
735
+ async listAudit(input, init) {
736
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/audit", {
737
+ params: { path: { workspaceId: input.workspaceId }, query: { limit: input.limit, offset: input.offset, action: input.action, actorId: input.actorId, from: input.from, to: input.to } },
738
+ signal: init?.signal,
739
+ timeoutMs: init?.timeoutMs
740
+ });
741
+ return data;
742
+ }
743
+ async getCreditBurn(input, init) {
744
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/credit-burn", {
745
+ params: { path: { workspaceId: input.workspaceId }, query: { days: input.days } },
746
+ signal: init?.signal,
747
+ timeoutMs: init?.timeoutMs
748
+ });
749
+ return data;
750
+ }
751
+ }
752
+
753
+ class Generation {
754
+ client;
755
+ constructor(client) {
756
+ this.client = client;
757
+ }
758
+ async estimate(input, init) {
759
+ const { data } = await this.client.GET("/api/articles/{articleId}/estimate", {
760
+ params: { path: { articleId: input.articleId } },
761
+ signal: init?.signal,
762
+ timeoutMs: init?.timeoutMs
763
+ });
764
+ return data;
765
+ }
766
+ async getOutline(input, init) {
767
+ const { data } = await this.client.GET("/api/articles/{articleId}/outline", {
768
+ params: { path: { articleId: input.articleId } },
769
+ signal: init?.signal,
770
+ timeoutMs: init?.timeoutMs
771
+ });
772
+ return data;
773
+ }
774
+ async approveOutline(input, init) {
775
+ const { data } = await this.client.POST("/api/articles/{articleId}/outline/approve", {
776
+ params: { path: { articleId: input.articleId } },
777
+ body: input.body ?? {},
778
+ signal: init?.signal,
779
+ timeoutMs: init?.timeoutMs
780
+ });
781
+ return data;
782
+ }
783
+ async aiEdit(input, init) {
784
+ const { data } = await this.client.POST("/api/articles/{articleId}/ai-edit", {
785
+ params: { path: { articleId: input.articleId } },
786
+ body: input.body,
787
+ signal: init?.signal,
788
+ timeoutMs: init?.timeoutMs
789
+ });
790
+ return data;
791
+ }
792
+ async start(input, init) {
793
+ const { data } = await this.client.POST("/api/articles/{articleId}/generate", {
794
+ params: { path: { articleId: input.articleId } },
795
+ body: input.body ?? {},
796
+ signal: init?.signal,
797
+ timeoutMs: init?.timeoutMs
798
+ });
799
+ return data;
800
+ }
801
+ async getStatus(input, init) {
802
+ const { data } = await this.client.GET("/api/articles/{articleId}/status", {
803
+ params: { path: { articleId: input.articleId } },
804
+ signal: init?.signal,
805
+ timeoutMs: init?.timeoutMs
806
+ });
807
+ return data;
808
+ }
809
+ async cancel(input, init) {
810
+ const { data } = await this.client.POST("/api/articles/{articleId}/cancel", {
811
+ params: { path: { articleId: input.articleId } },
812
+ signal: init?.signal,
813
+ timeoutMs: init?.timeoutMs
814
+ });
815
+ return data;
816
+ }
817
+ async regenerateImage(input, init) {
818
+ const { data } = await this.client.POST("/api/articles/{articleId}/regenerate-image", {
819
+ params: { path: { articleId: input.articleId } },
820
+ body: input.body,
821
+ signal: init?.signal,
822
+ timeoutMs: init?.timeoutMs
823
+ });
824
+ return data;
825
+ }
826
+ async updateAsset(input, init) {
827
+ const { data } = await this.client.PATCH("/api/articles/{articleId}/assets/{assetId}", {
828
+ params: { path: { articleId: input.articleId, assetId: input.assetId } },
829
+ body: input.body ?? {},
830
+ signal: init?.signal,
831
+ timeoutMs: init?.timeoutMs
832
+ });
833
+ return data;
834
+ }
835
+ async deleteAsset(input, init) {
836
+ const { data } = await this.client.DELETE("/api/articles/{articleId}/assets/{assetId}", {
837
+ params: { path: { articleId: input.articleId, assetId: input.assetId } },
838
+ signal: init?.signal,
839
+ timeoutMs: init?.timeoutMs
840
+ });
841
+ return data;
842
+ }
843
+ }
844
+
845
+ class Ideas {
846
+ client;
847
+ constructor(client) {
848
+ this.client = client;
849
+ }
850
+ async list(input, init) {
851
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/ideas", {
852
+ params: { path: { workspaceId: input.workspaceId }, query: { projectId: input.projectId } },
853
+ signal: init?.signal,
854
+ timeoutMs: init?.timeoutMs
855
+ });
856
+ return data;
857
+ }
858
+ async create(input, init) {
859
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/ideas", {
860
+ params: { path: { workspaceId: input.workspaceId } },
861
+ body: input.body,
862
+ signal: init?.signal,
863
+ timeoutMs: init?.timeoutMs
864
+ });
865
+ return data;
866
+ }
867
+ async update(input, init) {
868
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/ideas/{ideaId}", {
869
+ params: { path: { workspaceId: input.workspaceId, ideaId: input.ideaId } },
870
+ body: input.body ?? {},
871
+ signal: init?.signal,
872
+ timeoutMs: init?.timeoutMs
873
+ });
874
+ return data;
875
+ }
876
+ async delete(input, init) {
877
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/ideas/{ideaId}", {
878
+ params: { path: { workspaceId: input.workspaceId, ideaId: input.ideaId } },
879
+ signal: init?.signal,
880
+ timeoutMs: init?.timeoutMs
881
+ });
882
+ return data;
883
+ }
884
+ async generate(input, init) {
885
+ const { data } = await this.client.POST("/api/projects/{projectId}/ideas/generate", {
886
+ params: { path: { projectId: input.projectId } },
887
+ signal: init?.signal,
888
+ timeoutMs: init?.timeoutMs
889
+ });
890
+ return data;
891
+ }
892
+ }
893
+
894
+ class Integrations {
895
+ client;
896
+ constructor(client) {
897
+ this.client = client;
898
+ }
899
+ async list(input, init) {
900
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/integrations", {
901
+ params: { path: { workspaceId: input.workspaceId } },
902
+ signal: init?.signal,
903
+ timeoutMs: init?.timeoutMs
904
+ });
905
+ return data;
906
+ }
907
+ async create(input, init) {
908
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/integrations", {
909
+ params: { path: { workspaceId: input.workspaceId } },
910
+ body: input.body,
911
+ signal: init?.signal,
912
+ timeoutMs: init?.timeoutMs
913
+ });
914
+ return data;
915
+ }
916
+ async update(input, init) {
917
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/integrations/{integrationId}", {
918
+ params: { path: { workspaceId: input.workspaceId, integrationId: input.integrationId } },
919
+ body: input.body ?? {},
920
+ signal: init?.signal,
921
+ timeoutMs: init?.timeoutMs
922
+ });
923
+ return data;
924
+ }
925
+ async delete(input, init) {
926
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/integrations/{integrationId}", {
927
+ params: { path: { workspaceId: input.workspaceId, integrationId: input.integrationId } },
928
+ signal: init?.signal,
929
+ timeoutMs: init?.timeoutMs
930
+ });
931
+ return data;
932
+ }
933
+ }
934
+
935
+ class Invitations {
936
+ client;
937
+ constructor(client) {
938
+ this.client = client;
939
+ }
940
+ async list(input, init) {
941
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/invitations", {
942
+ params: { path: { workspaceId: input.workspaceId } },
943
+ signal: init?.signal,
944
+ timeoutMs: init?.timeoutMs
945
+ });
946
+ return data;
947
+ }
948
+ async revoke(input, init) {
949
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/invitations/{invitationId}", {
950
+ params: { path: { workspaceId: input.workspaceId, invitationId: input.invitationId } },
951
+ signal: init?.signal,
952
+ timeoutMs: init?.timeoutMs
953
+ });
954
+ return data;
955
+ }
956
+ async resend(input, init) {
957
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/invitations/{invitationId}/resend", {
958
+ params: { path: { workspaceId: input.workspaceId, invitationId: input.invitationId } },
959
+ body: input.body ?? {},
960
+ signal: init?.signal,
961
+ timeoutMs: init?.timeoutMs
962
+ });
963
+ return data;
964
+ }
965
+ }
966
+
967
+ class Knowledge {
968
+ client;
969
+ constructor(client) {
970
+ this.client = client;
971
+ }
972
+ async list(input, init) {
973
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/projects/{projectId}/knowledge", {
974
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
975
+ signal: init?.signal,
976
+ timeoutMs: init?.timeoutMs
977
+ });
978
+ return data;
979
+ }
980
+ async create(input, init) {
981
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/projects/{projectId}/knowledge", {
982
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
983
+ body: input.body,
984
+ signal: init?.signal,
985
+ timeoutMs: init?.timeoutMs
986
+ });
987
+ return data;
988
+ }
989
+ async uploadContent(input, init) {
990
+ const { data } = await this.client.PUT("/api/workspaces/{workspaceId}/knowledge/{sourceId}/content", {
991
+ params: { path: { workspaceId: input.workspaceId, sourceId: input.sourceId } },
992
+ body: input.body,
993
+ bodySerializer: (body) => body,
994
+ headers: { "content-type": input.contentType },
995
+ signal: init?.signal,
996
+ timeoutMs: init?.timeoutMs
997
+ });
998
+ return data;
999
+ }
1000
+ async reingest(input, init) {
1001
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/knowledge/{sourceId}/reingest", {
1002
+ params: { path: { workspaceId: input.workspaceId, sourceId: input.sourceId } },
1003
+ signal: init?.signal,
1004
+ timeoutMs: init?.timeoutMs
1005
+ });
1006
+ return data;
1007
+ }
1008
+ async delete(input, init) {
1009
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/knowledge/{sourceId}", {
1010
+ params: { path: { workspaceId: input.workspaceId, sourceId: input.sourceId } },
1011
+ signal: init?.signal,
1012
+ timeoutMs: init?.timeoutMs
1013
+ });
1014
+ return data;
1015
+ }
1016
+ }
1017
+
1018
+ class Links {
1019
+ client;
1020
+ constructor(client) {
1021
+ this.client = client;
1022
+ }
1023
+ async list(input, init) {
1024
+ const { data } = await this.client.GET("/api/articles/{articleId}/links", {
1025
+ params: { path: { articleId: input.articleId } },
1026
+ signal: init?.signal,
1027
+ timeoutMs: init?.timeoutMs
1028
+ });
1029
+ return data;
1030
+ }
1031
+ async generate(input, init) {
1032
+ const { data } = await this.client.POST("/api/articles/{articleId}/links", {
1033
+ params: { path: { articleId: input.articleId } },
1034
+ signal: init?.signal,
1035
+ timeoutMs: init?.timeoutMs
1036
+ });
1037
+ return data;
1038
+ }
1039
+ async decide(input, init) {
1040
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/links/{suggestionId}", {
1041
+ params: { path: { workspaceId: input.workspaceId, suggestionId: input.suggestionId } },
1042
+ body: input.body,
1043
+ signal: init?.signal,
1044
+ timeoutMs: init?.timeoutMs
1045
+ });
1046
+ return data;
1047
+ }
1048
+ }
1049
+
1050
+ class Permissions {
1051
+ client;
1052
+ constructor(client) {
1053
+ this.client = client;
1054
+ }
1055
+ async list(init) {
1056
+ const { data } = await this.client.GET("/api/permissions", {
1057
+ signal: init?.signal,
1058
+ timeoutMs: init?.timeoutMs
1059
+ });
1060
+ return data;
1061
+ }
1062
+ }
1063
+
1064
+ class Projects {
1065
+ client;
1066
+ constructor(client) {
1067
+ this.client = client;
1068
+ }
1069
+ async list(input, init) {
1070
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/projects", {
1071
+ params: { path: { workspaceId: input.workspaceId }, query: { includeArchived: input.includeArchived } },
1072
+ signal: init?.signal,
1073
+ timeoutMs: init?.timeoutMs
1074
+ });
1075
+ return data;
1076
+ }
1077
+ async create(input, init) {
1078
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/projects", {
1079
+ params: { path: { workspaceId: input.workspaceId } },
1080
+ body: input.body,
1081
+ signal: init?.signal,
1082
+ timeoutMs: init?.timeoutMs
1083
+ });
1084
+ return data;
1085
+ }
1086
+ async get(input, init) {
1087
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/projects/{projectId}", {
1088
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1089
+ signal: init?.signal,
1090
+ timeoutMs: init?.timeoutMs
1091
+ });
1092
+ return data;
1093
+ }
1094
+ async update(input, init) {
1095
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/projects/{projectId}", {
1096
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1097
+ body: input.body ?? {},
1098
+ signal: init?.signal,
1099
+ timeoutMs: init?.timeoutMs
1100
+ });
1101
+ return data;
1102
+ }
1103
+ async delete(input, init) {
1104
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/projects/{projectId}", {
1105
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1106
+ signal: init?.signal,
1107
+ timeoutMs: init?.timeoutMs
1108
+ });
1109
+ return data;
1110
+ }
1111
+ async archive(input, init) {
1112
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/projects/{projectId}/archive", {
1113
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1114
+ signal: init?.signal,
1115
+ timeoutMs: init?.timeoutMs
1116
+ });
1117
+ return data;
1118
+ }
1119
+ async restore(input, init) {
1120
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/projects/{projectId}/restore", {
1121
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1122
+ signal: init?.signal,
1123
+ timeoutMs: init?.timeoutMs
1124
+ });
1125
+ return data;
1126
+ }
1127
+ async listMembers(input, init) {
1128
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/projects/{projectId}/members", {
1129
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1130
+ signal: init?.signal,
1131
+ timeoutMs: init?.timeoutMs
1132
+ });
1133
+ return data;
1134
+ }
1135
+ async addMember(input, init) {
1136
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/projects/{projectId}/members", {
1137
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId } },
1138
+ body: input.body,
1139
+ signal: init?.signal,
1140
+ timeoutMs: init?.timeoutMs
1141
+ });
1142
+ return data;
1143
+ }
1144
+ async setMemberRole(input, init) {
1145
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/projects/{projectId}/members/{projectMemberId}", {
1146
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId, projectMemberId: input.projectMemberId } },
1147
+ body: input.body,
1148
+ signal: init?.signal,
1149
+ timeoutMs: init?.timeoutMs
1150
+ });
1151
+ return data;
1152
+ }
1153
+ async removeMember(input, init) {
1154
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/projects/{projectId}/members/{projectMemberId}", {
1155
+ params: { path: { workspaceId: input.workspaceId, projectId: input.projectId, projectMemberId: input.projectMemberId } },
1156
+ signal: init?.signal,
1157
+ timeoutMs: init?.timeoutMs
1158
+ });
1159
+ return data;
1160
+ }
1161
+ }
1162
+
1163
+ class Roles {
1164
+ client;
1165
+ constructor(client) {
1166
+ this.client = client;
1167
+ }
1168
+ async list(input, init) {
1169
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/roles", {
1170
+ params: { path: { workspaceId: input.workspaceId } },
1171
+ signal: init?.signal,
1172
+ timeoutMs: init?.timeoutMs
1173
+ });
1174
+ return data;
1175
+ }
1176
+ async create(input, init) {
1177
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/roles", {
1178
+ params: { path: { workspaceId: input.workspaceId } },
1179
+ body: input.body,
1180
+ signal: init?.signal,
1181
+ timeoutMs: init?.timeoutMs
1182
+ });
1183
+ return data;
1184
+ }
1185
+ async update(input, init) {
1186
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/roles/{roleId}", {
1187
+ params: { path: { workspaceId: input.workspaceId, roleId: input.roleId } },
1188
+ body: input.body ?? {},
1189
+ signal: init?.signal,
1190
+ timeoutMs: init?.timeoutMs
1191
+ });
1192
+ return data;
1193
+ }
1194
+ async delete(input, init) {
1195
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/roles/{roleId}", {
1196
+ params: { path: { workspaceId: input.workspaceId, roleId: input.roleId } },
1197
+ signal: init?.signal,
1198
+ timeoutMs: init?.timeoutMs
1199
+ });
1200
+ return data;
1201
+ }
1202
+ async duplicate(input, init) {
1203
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/roles/{roleId}/duplicate", {
1204
+ params: { path: { workspaceId: input.workspaceId, roleId: input.roleId } },
1205
+ body: input.body,
1206
+ signal: init?.signal,
1207
+ timeoutMs: init?.timeoutMs
1208
+ });
1209
+ return data;
1210
+ }
1211
+ }
1212
+
1213
+ class SiteAnalyses {
1214
+ client;
1215
+ constructor(client) {
1216
+ this.client = client;
1217
+ }
1218
+ async start(input, init) {
1219
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/site-analyses", {
1220
+ params: { path: { workspaceId: input.workspaceId } },
1221
+ body: input.body,
1222
+ signal: init?.signal,
1223
+ timeoutMs: init?.timeoutMs
1224
+ });
1225
+ return data;
1226
+ }
1227
+ async get(input, init) {
1228
+ const { data } = await this.client.GET("/api/site-analyses/{analysisId}", {
1229
+ params: { path: { analysisId: input.analysisId } },
1230
+ signal: init?.signal,
1231
+ timeoutMs: init?.timeoutMs
1232
+ });
1233
+ return data;
1234
+ }
1235
+ async apply(input, init) {
1236
+ const { data } = await this.client.POST("/api/site-analyses/{analysisId}/apply", {
1237
+ params: { path: { analysisId: input.analysisId } },
1238
+ body: input.body,
1239
+ signal: init?.signal,
1240
+ timeoutMs: init?.timeoutMs
1241
+ });
1242
+ return data;
1243
+ }
1244
+ }
1245
+
1246
+ class Social {
1247
+ client;
1248
+ constructor(client) {
1249
+ this.client = client;
1250
+ }
1251
+ async generate(input, init) {
1252
+ const { data } = await this.client.POST("/api/articles/{articleId}/social", {
1253
+ params: { path: { articleId: input.articleId } },
1254
+ signal: init?.signal,
1255
+ timeoutMs: init?.timeoutMs
1256
+ });
1257
+ return data;
1258
+ }
1259
+ async list(input, init) {
1260
+ const { data } = await this.client.GET("/api/articles/{articleId}/social", {
1261
+ params: { path: { articleId: input.articleId } },
1262
+ signal: init?.signal,
1263
+ timeoutMs: init?.timeoutMs
1264
+ });
1265
+ return data;
1266
+ }
1267
+ }
1268
+
1269
+ class Translations {
1270
+ client;
1271
+ constructor(client) {
1272
+ this.client = client;
1273
+ }
1274
+ async estimate(input, init) {
1275
+ const { data } = await this.client.GET("/api/articles/{articleId}/translations/estimate", {
1276
+ params: { path: { articleId: input.articleId }, query: { language: input.language } },
1277
+ signal: init?.signal,
1278
+ timeoutMs: init?.timeoutMs
1279
+ });
1280
+ return data;
1281
+ }
1282
+ async create(input, init) {
1283
+ const { data } = await this.client.POST("/api/articles/{articleId}/translations", {
1284
+ params: { path: { articleId: input.articleId } },
1285
+ body: input.body,
1286
+ signal: init?.signal,
1287
+ timeoutMs: init?.timeoutMs
1288
+ });
1289
+ return data;
1290
+ }
1291
+ }
1292
+
1293
+ class Usage {
1294
+ client;
1295
+ constructor(client) {
1296
+ this.client = client;
1297
+ }
1298
+ async listTransactions(input, init) {
1299
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/transactions", {
1300
+ params: { path: { workspaceId: input.workspaceId }, query: { limit: input.limit } },
1301
+ signal: init?.signal,
1302
+ timeoutMs: init?.timeoutMs
1303
+ });
1304
+ return data;
1305
+ }
1306
+ async get(input, init) {
1307
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/usage", {
1308
+ params: { path: { workspaceId: input.workspaceId }, query: { from: input.from, to: input.to, projectId: input.projectId, userId: input.userId, type: input.type, provider: input.provider, limit: input.limit } },
1309
+ signal: init?.signal,
1310
+ timeoutMs: init?.timeoutMs
1311
+ });
1312
+ return data;
1313
+ }
1314
+ async listPayments(input, init) {
1315
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/payments", {
1316
+ params: { path: { workspaceId: input.workspaceId } },
1317
+ signal: init?.signal,
1318
+ timeoutMs: init?.timeoutMs
1319
+ });
1320
+ return data;
1321
+ }
1322
+ async listQuotas(input, init) {
1323
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/quotas", {
1324
+ params: { path: { workspaceId: input.workspaceId } },
1325
+ signal: init?.signal,
1326
+ timeoutMs: init?.timeoutMs
1327
+ });
1328
+ return data;
1329
+ }
1330
+ async setQuota(input, init) {
1331
+ const { data } = await this.client.PUT("/api/workspaces/{workspaceId}/quotas", {
1332
+ params: { path: { workspaceId: input.workspaceId } },
1333
+ body: input.body,
1334
+ signal: init?.signal,
1335
+ timeoutMs: init?.timeoutMs
1336
+ });
1337
+ return data;
1338
+ }
1339
+ }
1340
+
1341
+ class Webhooks {
1342
+ client;
1343
+ constructor(client) {
1344
+ this.client = client;
1345
+ }
1346
+ async list(input, init) {
1347
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/webhooks", {
1348
+ params: { path: { workspaceId: input.workspaceId }, query: { deliveryStatus: input.deliveryStatus } },
1349
+ signal: init?.signal,
1350
+ timeoutMs: init?.timeoutMs
1351
+ });
1352
+ return data;
1353
+ }
1354
+ async create(input, init) {
1355
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/webhooks", {
1356
+ params: { path: { workspaceId: input.workspaceId } },
1357
+ body: input.body,
1358
+ signal: init?.signal,
1359
+ timeoutMs: init?.timeoutMs
1360
+ });
1361
+ return data;
1362
+ }
1363
+ async delete(input, init) {
1364
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/webhooks/{endpointId}", {
1365
+ params: { path: { workspaceId: input.workspaceId, endpointId: input.endpointId } },
1366
+ signal: init?.signal,
1367
+ timeoutMs: init?.timeoutMs
1368
+ });
1369
+ return data;
1370
+ }
1371
+ }
1372
+
1373
+ class Workspaces {
1374
+ client;
1375
+ constructor(client) {
1376
+ this.client = client;
1377
+ }
1378
+ async list(init) {
1379
+ const { data } = await this.client.GET("/api/workspaces", {
1380
+ signal: init?.signal,
1381
+ timeoutMs: init?.timeoutMs
1382
+ });
1383
+ return data;
1384
+ }
1385
+ async create(input, init) {
1386
+ const { data } = await this.client.POST("/api/workspaces", {
1387
+ body: input.body,
1388
+ signal: init?.signal,
1389
+ timeoutMs: init?.timeoutMs
1390
+ });
1391
+ return data;
1392
+ }
1393
+ async get(input, init) {
1394
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}", {
1395
+ params: { path: { workspaceId: input.workspaceId } },
1396
+ signal: init?.signal,
1397
+ timeoutMs: init?.timeoutMs
1398
+ });
1399
+ return data;
1400
+ }
1401
+ async update(input, init) {
1402
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}", {
1403
+ params: { path: { workspaceId: input.workspaceId } },
1404
+ body: input.body ?? {},
1405
+ signal: init?.signal,
1406
+ timeoutMs: init?.timeoutMs
1407
+ });
1408
+ return data;
1409
+ }
1410
+ async listMembers(input, init) {
1411
+ const { data } = await this.client.GET("/api/workspaces/{workspaceId}/members", {
1412
+ params: { path: { workspaceId: input.workspaceId } },
1413
+ signal: init?.signal,
1414
+ timeoutMs: init?.timeoutMs
1415
+ });
1416
+ return data;
1417
+ }
1418
+ async addMember(input, init) {
1419
+ const { data } = await this.client.POST("/api/workspaces/{workspaceId}/members", {
1420
+ params: { path: { workspaceId: input.workspaceId } },
1421
+ body: input.body,
1422
+ signal: init?.signal,
1423
+ timeoutMs: init?.timeoutMs
1424
+ });
1425
+ return data;
1426
+ }
1427
+ async setMemberRoles(input, init) {
1428
+ const { data } = await this.client.PATCH("/api/workspaces/{workspaceId}/members/{memberId}", {
1429
+ params: { path: { workspaceId: input.workspaceId, memberId: input.memberId } },
1430
+ body: input.body,
1431
+ signal: init?.signal,
1432
+ timeoutMs: init?.timeoutMs
1433
+ });
1434
+ return data;
1435
+ }
1436
+ async removeMember(input, init) {
1437
+ const { data } = await this.client.DELETE("/api/workspaces/{workspaceId}/members/{memberId}", {
1438
+ params: { path: { workspaceId: input.workspaceId, memberId: input.memberId } },
1439
+ signal: init?.signal,
1440
+ timeoutMs: init?.timeoutMs
1441
+ });
1442
+ return data;
1443
+ }
1444
+ }
1445
+
1446
+ class PrismDraftResources {
1447
+ apiKeys;
1448
+ articleGroups;
1449
+ articles;
1450
+ billing;
1451
+ blog;
1452
+ brandVoices;
1453
+ briefs;
1454
+ calendar;
1455
+ categories;
1456
+ contentTemplates;
1457
+ dashboard;
1458
+ generation;
1459
+ ideas;
1460
+ integrations;
1461
+ invitations;
1462
+ knowledge;
1463
+ links;
1464
+ permissions;
1465
+ projects;
1466
+ roles;
1467
+ siteAnalyses;
1468
+ social;
1469
+ translations;
1470
+ usage;
1471
+ webhooks;
1472
+ workspaces;
1473
+ constructor(client) {
1474
+ this.apiKeys = new ApiKeys(client);
1475
+ this.articleGroups = new ArticleGroups(client);
1476
+ this.articles = new Articles(client);
1477
+ this.billing = new Billing(client);
1478
+ this.blog = new Blog(client);
1479
+ this.brandVoices = new BrandVoices(client);
1480
+ this.briefs = new Briefs(client);
1481
+ this.calendar = new Calendar(client);
1482
+ this.categories = new Categories(client);
1483
+ this.contentTemplates = new ContentTemplates(client);
1484
+ this.dashboard = new Dashboard(client);
1485
+ this.generation = new Generation(client);
1486
+ this.ideas = new Ideas(client);
1487
+ this.integrations = new Integrations(client);
1488
+ this.invitations = new Invitations(client);
1489
+ this.knowledge = new Knowledge(client);
1490
+ this.links = new Links(client);
1491
+ this.permissions = new Permissions(client);
1492
+ this.projects = new Projects(client);
1493
+ this.roles = new Roles(client);
1494
+ this.siteAnalyses = new SiteAnalyses(client);
1495
+ this.social = new Social(client);
1496
+ this.translations = new Translations(client);
1497
+ this.usage = new Usage(client);
1498
+ this.webhooks = new Webhooks(client);
1499
+ this.workspaces = new Workspaces(client);
1500
+ }
1501
+ }
1502
+
1503
+ // src/errors.ts
1504
+ class PrismDraftError extends Error {
1505
+ status;
1506
+ code;
1507
+ details;
1508
+ constructor(status, code, message, details) {
1509
+ super(message);
1510
+ this.name = "PrismDraftError";
1511
+ this.status = status;
1512
+ this.code = code;
1513
+ this.details = details;
1514
+ }
1515
+ }
1516
+
1517
+ class PrismDraftTimeoutError extends Error {
1518
+ timeoutMs;
1519
+ constructor(timeoutMs) {
1520
+ super(`The request did not finish within ${timeoutMs} ms`);
1521
+ this.name = "PrismDraftTimeoutError";
1522
+ this.timeoutMs = timeoutMs;
1523
+ }
1524
+ }
1525
+
1526
+ class WebhookSignatureError extends Error {
1527
+ constructor(message = "The webhook signature is not valid") {
1528
+ super(message);
1529
+ this.name = "WebhookSignatureError";
1530
+ }
1531
+ }
1532
+
1533
+ class WebhookPayloadError extends WebhookSignatureError {
1534
+ reason;
1535
+ constructor(reason, message) {
1536
+ super(message);
1537
+ this.name = "WebhookPayloadError";
1538
+ this.reason = reason;
1539
+ }
1540
+ }
1541
+
1542
+ class UnknownWebhookEventError extends Error {
1543
+ event;
1544
+ constructor(event) {
1545
+ super(`Unknown webhook event "${event}"`);
1546
+ this.name = "UnknownWebhookEventError";
1547
+ this.event = event;
1548
+ }
1549
+ }
1550
+
1551
+ // src/middleware.ts
1552
+ var throwOnError = {
1553
+ async onResponse({ response }) {
1554
+ if (response.ok)
1555
+ return;
1556
+ const text = await response.clone().text();
1557
+ let parsed;
1558
+ try {
1559
+ parsed = text.length > 0 ? JSON.parse(text) : undefined;
1560
+ } catch {
1561
+ parsed = undefined;
1562
+ }
1563
+ const body = parsed?.error;
1564
+ if (typeof body?.code === "string" && typeof body.message === "string") {
1565
+ throw new PrismDraftError(response.status, body.code, body.message, body.details);
1566
+ }
1567
+ throw new PrismDraftError(response.status, "INTERNAL_ERROR", response.statusText || `HTTP ${response.status}`);
1568
+ }
1569
+ };
1570
+ var rejectUnsafePathParams = {
1571
+ onRequest({ params }) {
1572
+ for (const [name, value] of Object.entries(params.path ?? {})) {
1573
+ const text = String(value);
1574
+ if (text === "" || text === "." || text === "..") {
1575
+ throw new TypeError(`Path parameter "${name}" must not be empty, "." or ".." (got ${JSON.stringify(text)})`);
1576
+ }
1577
+ }
1578
+ return;
1579
+ }
1580
+ };
1581
+ var rejectNonJsonBody = {
1582
+ async onResponse({ response }) {
1583
+ if (!response.ok)
1584
+ return;
1585
+ const text = await response.clone().text();
1586
+ if (text.length === 0)
1587
+ return;
1588
+ try {
1589
+ JSON.parse(text);
1590
+ } catch {
1591
+ throw new PrismDraftError(response.status, "INVALID_RESPONSE", "The API returned a non-JSON body");
1592
+ }
1593
+ return;
1594
+ }
1595
+ };
1596
+
1597
+ // src/retry.ts
1598
+ var RETRYABLE_STATUS = new Set([429, 502, 503, 504]);
1599
+ var DEFAULT_MAX_RETRY_DELAY_MS = 8000;
1600
+ var BASE_WAIT_MS = 250;
1601
+ var MAX_TIMER_MS = 2 ** 31 - 1;
1602
+ function assertDuration(name, value) {
1603
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
1604
+ throw new TypeError(`PrismDraft: ${name} must be a finite number above 0, got ${String(value)}`);
1605
+ }
1606
+ }
1607
+ function anySignal(signals) {
1608
+ if (typeof AbortSignal.any === "function")
1609
+ return AbortSignal.any(signals);
1610
+ const controller = new AbortController;
1611
+ for (const signal of signals) {
1612
+ if (signal.aborted) {
1613
+ controller.abort(signal.reason);
1614
+ break;
1615
+ }
1616
+ signal.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
1617
+ }
1618
+ return controller.signal;
1619
+ }
1620
+ var defaultSleep = (ms, signal) => new Promise((resolve) => {
1621
+ const timer = setTimeout(resolve, ms);
1622
+ signal?.addEventListener("abort", () => clearTimeout(timer), { once: true });
1623
+ });
1624
+ function retryAfterMs(response) {
1625
+ const raw = response.headers.get("retry-after")?.trim();
1626
+ if (raw === undefined || raw === "")
1627
+ return;
1628
+ const ms = /^\d+(\.\d+)?$/.test(raw) ? Number(raw) * 1000 : Date.parse(raw) - Date.now();
1629
+ return Number.isFinite(ms) && ms > 0 ? ms : undefined;
1630
+ }
1631
+ function wait(sleep, ms, signal) {
1632
+ return new Promise((resolve, reject) => {
1633
+ if (signal.aborted)
1634
+ return reject(signal.reason);
1635
+ const onAbort = () => reject(signal.reason);
1636
+ signal.addEventListener("abort", onAbort, { once: true });
1637
+ sleep(ms, signal).then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
1638
+ });
1639
+ }
1640
+ function releaseWhenSettled(response, release) {
1641
+ if (response.body === null) {
1642
+ release();
1643
+ return response;
1644
+ }
1645
+ const reader = response.body.getReader();
1646
+ const body = new ReadableStream({
1647
+ async pull(controller) {
1648
+ try {
1649
+ const { done, value } = await reader.read();
1650
+ if (done) {
1651
+ release();
1652
+ controller.close();
1653
+ } else {
1654
+ controller.enqueue(value);
1655
+ }
1656
+ } catch (error) {
1657
+ release();
1658
+ controller.error(error);
1659
+ }
1660
+ },
1661
+ cancel(reason) {
1662
+ release();
1663
+ return reader.cancel(reason);
1664
+ }
1665
+ });
1666
+ return new Response(body, response);
1667
+ }
1668
+ function retryingFetch(inner, options = {}) {
1669
+ const maxRetries = options.maxRetries ?? 2;
1670
+ const sleep = options.sleep ?? defaultSleep;
1671
+ const maxDelay = options.maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;
1672
+ assertDuration("maxRetryDelayMs", maxDelay);
1673
+ if (options.timeoutMs !== undefined)
1674
+ assertDuration("timeoutMs", options.timeoutMs);
1675
+ return async (input) => {
1676
+ const idempotent = input.method === "GET" || input.method === "HEAD";
1677
+ const timeoutMs = input.timeoutMs ?? options.timeoutMs;
1678
+ if (timeoutMs !== undefined)
1679
+ assertDuration("timeoutMs", timeoutMs);
1680
+ for (let attempt = 0;; attempt++) {
1681
+ input.signal.throwIfAborted();
1682
+ let request = idempotent ? input.clone() : input;
1683
+ let timer;
1684
+ let timeout;
1685
+ if (timeoutMs !== undefined) {
1686
+ const expiry = new AbortController;
1687
+ timeout = expiry;
1688
+ timer = setTimeout(() => expiry.abort(new PrismDraftTimeoutError(timeoutMs)), Math.min(timeoutMs, MAX_TIMER_MS));
1689
+ timer.unref?.();
1690
+ try {
1691
+ request = new Request(request, { signal: anySignal([input.signal, expiry.signal]) });
1692
+ } catch (error) {
1693
+ clearTimeout(timer);
1694
+ throw error;
1695
+ }
1696
+ }
1697
+ const release = () => clearTimeout(timer);
1698
+ const backoff = Math.min(BASE_WAIT_MS * 2 ** attempt, maxDelay);
1699
+ let delay;
1700
+ try {
1701
+ const response = await inner(request);
1702
+ if (!idempotent || !RETRYABLE_STATUS.has(response.status) || attempt >= maxRetries) {
1703
+ return releaseWhenSettled(response, release);
1704
+ }
1705
+ const asked = retryAfterMs(response);
1706
+ if (asked !== undefined && asked > maxDelay)
1707
+ return releaseWhenSettled(response, release);
1708
+ if (response.status === 429 && asked === undefined) {
1709
+ return releaseWhenSettled(response, release);
1710
+ }
1711
+ delay = asked ?? backoff;
1712
+ } catch (error) {
1713
+ clearTimeout(timer);
1714
+ if (input.signal.aborted)
1715
+ throw input.signal.reason;
1716
+ const failure = timeout?.signal.aborted ? timeout.signal.reason : error;
1717
+ if (!idempotent || attempt >= maxRetries)
1718
+ throw failure;
1719
+ delay = backoff;
1720
+ }
1721
+ clearTimeout(timer);
1722
+ await wait(sleep, delay, input.signal);
1723
+ }
1724
+ };
1725
+ }
1726
+
1727
+ // src/client.ts
1728
+ var DEFAULT_BASE_URL = "https://api.prism-draft.com";
1729
+ function isHttpUrl(value) {
1730
+ try {
1731
+ const { protocol } = new URL(value);
1732
+ return protocol === "http:" || protocol === "https:";
1733
+ } catch {
1734
+ return false;
1735
+ }
1736
+ }
1737
+ var RESERVED_INIT_KEYS = ["body", "method", "headers", "signal"];
1738
+ function withRequestInit(inner, requestInit) {
1739
+ if (requestInit === undefined)
1740
+ return inner;
1741
+ const init = { ...requestInit };
1742
+ for (const key of RESERVED_INIT_KEYS)
1743
+ delete init[key];
1744
+ return (input) => inner(input, init);
1745
+ }
1746
+
1747
+ class PrismDraft extends PrismDraftResources {
1748
+ raw;
1749
+ constructor(options) {
1750
+ if (typeof options.apiKey !== "string" || options.apiKey.trim() === "") {
1751
+ throw new TypeError("PrismDraft: apiKey is empty (is the environment variable set?)");
1752
+ }
1753
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
1754
+ if (!isHttpUrl(baseUrl)) {
1755
+ throw new TypeError(`PrismDraft: baseUrl must be an absolute http(s) URL, got "${baseUrl}"`);
1756
+ }
1757
+ const raw = createOpenApiClient({
1758
+ baseUrl,
1759
+ headers: { authorization: `Bearer ${options.apiKey}` },
1760
+ fetch: retryingFetch(withRequestInit(options.fetch ?? fetch, options.requestInit), {
1761
+ maxRetries: options.maxRetries ?? 2,
1762
+ timeoutMs: options.timeoutMs,
1763
+ maxRetryDelayMs: options.maxRetryDelayMs
1764
+ })
1765
+ });
1766
+ raw.use(rejectUnsafePathParams, throwOnError, rejectNonJsonBody);
1767
+ super(raw);
1768
+ this.raw = raw;
1769
+ }
1770
+ }
1771
+ // src/webhook-events.ts
1772
+ var WEBHOOK_EVENTS = [
1773
+ "article.created",
1774
+ "article.generation.started",
1775
+ "article.generation.completed",
1776
+ "article.generation.failed",
1777
+ "article.approved",
1778
+ "article.rejected",
1779
+ "article.published",
1780
+ "article.updated",
1781
+ "article.unpublished",
1782
+ "image.generated",
1783
+ "image.regenerated",
1784
+ "credits.purchased",
1785
+ "credits.granted",
1786
+ "credits.consumed"
1787
+ ];
1788
+ var ARTICLE_SNAPSHOT_KEYS = [
1789
+ "articleId",
1790
+ "workspaceId",
1791
+ "projectId",
1792
+ "slug",
1793
+ "status",
1794
+ "primaryLanguage",
1795
+ "translationGroupId",
1796
+ "title"
1797
+ ];
1798
+ var WEBHOOK_EVENT_KEYS = {
1799
+ "article.created": ["articleId", "projectId", "title"],
1800
+ "article.generation.started": ["articleId", "jobId", "estimatedCredits"],
1801
+ "article.generation.completed": ["articleId", "jobId", "consumedCredits"],
1802
+ "article.generation.failed": ["articleId", "jobId", "error"],
1803
+ "article.approved": ["articleId", "reviewId", "previousStatus"],
1804
+ "article.rejected": ["articleId", "reviewId", "decision"],
1805
+ "article.published": ARTICLE_SNAPSHOT_KEYS,
1806
+ "article.updated": [...ARTICLE_SNAPSHOT_KEYS, "changed", "previousSlug"],
1807
+ "article.unpublished": [...ARTICLE_SNAPSHOT_KEYS, "previousStatus", "reason"],
1808
+ "image.generated": ["articleId", "assetId", "type"],
1809
+ "image.regenerated": ["articleId", "assetId", "type"],
1810
+ "credits.purchased": ["creditAmount", "stripeEventId"],
1811
+ "credits.granted": ["creditAmount", "stripeEventId"],
1812
+ "credits.consumed": ["articleId", "jobId", "credits"]
1813
+ };
1814
+
1815
+ // src/webhooks.ts
1816
+ var WEBHOOK_SIGNATURE_HEADER = "x-prism-draft-signature";
1817
+ var DEFAULT_TOLERANCE_SECONDS = 300;
1818
+ var encoder = new TextEncoder;
1819
+ function hexToBytes(hex) {
1820
+ if (hex.length === 0 || hex.length % 2 !== 0 || !/^[0-9a-f]+$/i.test(hex))
1821
+ return null;
1822
+ const bytes = new Uint8Array(hex.length / 2);
1823
+ for (let index = 0;index < bytes.length; index++) {
1824
+ bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
1825
+ }
1826
+ return bytes;
1827
+ }
1828
+ function parseSignature(header) {
1829
+ const fields = new Map;
1830
+ for (const part of header.split(",")) {
1831
+ const at = part.indexOf("=");
1832
+ if (at < 0)
1833
+ continue;
1834
+ const name = part.slice(0, at).trim();
1835
+ if (fields.has(name))
1836
+ return null;
1837
+ fields.set(name, part.slice(at + 1).trim());
1838
+ }
1839
+ return fields;
1840
+ }
1841
+ async function verifyWebhookSignature(input) {
1842
+ const tolerance = input.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
1843
+ if (typeof tolerance !== "number" || !Number.isFinite(tolerance) || tolerance < 0) {
1844
+ throw new RangeError("toleranceSeconds must be a finite number of seconds, 0 or more");
1845
+ }
1846
+ const now = input.now ?? Math.floor(Date.now() / 1000);
1847
+ if (input.secret.length === 0)
1848
+ return false;
1849
+ const fields = parseSignature(input.signature);
1850
+ if (fields === null)
1851
+ return false;
1852
+ const timestamp = Number(fields.get("t"));
1853
+ const provided = hexToBytes(fields.get("v1") ?? "");
1854
+ if (!Number.isInteger(timestamp) || provided === null)
1855
+ return false;
1856
+ if (Math.abs(now - timestamp) > tolerance)
1857
+ return false;
1858
+ const body = typeof input.rawBody === "string" ? encoder.encode(input.rawBody) : input.rawBody;
1859
+ const prefix = encoder.encode(`${timestamp}.`);
1860
+ const message = new Uint8Array(prefix.length + body.length);
1861
+ message.set(prefix, 0);
1862
+ message.set(body, prefix.length);
1863
+ const key = await crypto.subtle.importKey("raw", encoder.encode(input.secret), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
1864
+ return crypto.subtle.verify("HMAC", key, provided, message);
1865
+ }
1866
+ async function constructWebhookEvent(input) {
1867
+ if (!await verifyWebhookSignature(input))
1868
+ throw new WebhookSignatureError;
1869
+ const text = typeof input.rawBody === "string" ? input.rawBody : new TextDecoder().decode(input.rawBody);
1870
+ let envelope;
1871
+ try {
1872
+ envelope = JSON.parse(text);
1873
+ } catch {
1874
+ throw new WebhookPayloadError("not_json", "The webhook body is not JSON");
1875
+ }
1876
+ const { event, data } = envelope ?? {};
1877
+ if (typeof event !== "string" || typeof data !== "object" || data === null) {
1878
+ throw new WebhookPayloadError("not_envelope", "The webhook body is not an { event, data } envelope");
1879
+ }
1880
+ if (!WEBHOOK_EVENTS.includes(event)) {
1881
+ throw new UnknownWebhookEventError(event);
1882
+ }
1883
+ return { event, data };
1884
+ }
1885
+ export {
1886
+ ApiKeys,
1887
+ ArticleGroups,
1888
+ Articles,
1889
+ Billing,
1890
+ Blog,
1891
+ BrandVoices,
1892
+ Briefs,
1893
+ Calendar,
1894
+ Categories,
1895
+ ContentTemplates,
1896
+ DEFAULT_BASE_URL,
1897
+ Dashboard,
1898
+ Generation,
1899
+ Ideas,
1900
+ Integrations,
1901
+ Invitations,
1902
+ Knowledge,
1903
+ Links,
1904
+ Permissions,
1905
+ PrismDraft,
1906
+ PrismDraftError,
1907
+ PrismDraftResources,
1908
+ PrismDraftTimeoutError,
1909
+ Projects,
1910
+ Roles,
1911
+ SiteAnalyses,
1912
+ Social,
1913
+ Translations,
1914
+ UnknownWebhookEventError,
1915
+ Usage,
1916
+ WEBHOOK_EVENTS,
1917
+ WEBHOOK_SIGNATURE_HEADER,
1918
+ WebhookPayloadError,
1919
+ WebhookSignatureError,
1920
+ Webhooks,
1921
+ Workspaces,
1922
+ constructWebhookEvent,
1923
+ retryingFetch,
1924
+ throwOnError,
1925
+ verifyWebhookSignature
1926
+ };