@cstar.help/js 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,451 +0,0 @@
1
- /** Every webhook event type cStar can dispatch. */
2
- type WebhookEventType = 'article.created' | 'article.deleted' | 'article.published' | 'article.updated' | 'boss.damaged' | 'boss.defeated' | 'boss.spawned' | 'community_post.commented' | 'community_post.created' | 'community_post.deleted' | 'community_post.status_changed' | 'community_post.updated' | 'community_post.voted' | 'customer.created' | 'customer.deleted' | 'customer.updated' | 'customer_group.created' | 'customer_group.deleted' | 'customer_group.updated' | 'player.achievement_unlocked' | 'player.level_up' | 'player.quest_completed' | 'player.streak_milestone' | 'player.xp_gained' | 'social.high_five_sent' | 'social.one_up_sent' | 'survey.submitted' | 'ticket.assigned' | 'ticket.closed' | 'ticket.created' | 'ticket.deleted' | 'ticket.message_added' | 'ticket.updated';
3
- /** Payload for `article.created` events. */
4
- interface ArticleCreatedPayload {
5
- article: {
6
- id: string;
7
- title: string;
8
- slug: string;
9
- is_public: boolean;
10
- created_at: string;
11
- };
12
- }
13
- /** Payload for `article.deleted` events. */
14
- interface ArticleDeletedPayload {
15
- id: string;
16
- }
17
- /** Payload for `article.published` events. */
18
- interface ArticlePublishedPayload {
19
- article: {
20
- id: string;
21
- title: string;
22
- slug: string;
23
- is_public: boolean;
24
- published_at: string;
25
- };
26
- }
27
- /** Payload for `article.updated` events. */
28
- interface ArticleUpdatedPayload {
29
- article: {
30
- id: string;
31
- title: string;
32
- slug: string;
33
- is_public: boolean;
34
- };
35
- }
36
- /** Payload for `boss.damaged` events. */
37
- interface BossDamagedPayload {
38
- boss: {
39
- id: string;
40
- current_hp: number;
41
- };
42
- damage: number;
43
- by: {
44
- agent_id: string;
45
- name: string;
46
- };
47
- }
48
- /** Payload for `boss.defeated` events. */
49
- interface BossDefeatedPayload {
50
- boss: {
51
- id: string;
52
- name: string;
53
- };
54
- final_blow_by: {
55
- agent_id: string;
56
- name: string;
57
- };
58
- team_xp_awarded: number;
59
- }
60
- /** Payload for `boss.spawned` events. */
61
- interface BossSpawnedPayload {
62
- boss: {
63
- id: string;
64
- name: string;
65
- level: number;
66
- max_hp: number;
67
- };
68
- }
69
- /** Payload for `community_post.commented` events. */
70
- interface CommunityPostCommentedPayload {
71
- comment: {
72
- id: string;
73
- post_id: string;
74
- content: string;
75
- author_id: string;
76
- created_at: string;
77
- };
78
- }
79
- /** Payload for `community_post.created` events. */
80
- interface CommunityPostCreatedPayload {
81
- post: {
82
- id: string;
83
- prefixed_id: string;
84
- title: string;
85
- status: string;
86
- visibility: string;
87
- topic: string;
88
- created_at: string;
89
- };
90
- }
91
- /** Payload for `community_post.deleted` events. */
92
- interface CommunityPostDeletedPayload {
93
- post: {
94
- id: string;
95
- prefixed_id?: string;
96
- title?: string;
97
- };
98
- }
99
- /** Payload for `community_post.status_changed` events. */
100
- interface CommunityPostStatusChangedPayload {
101
- post: {
102
- id: string;
103
- title: string;
104
- status: string;
105
- visibility: string;
106
- };
107
- }
108
- /** Payload for `community_post.updated` events. */
109
- interface CommunityPostUpdatedPayload {
110
- post: {
111
- id: string;
112
- title: string;
113
- status: string;
114
- visibility: string;
115
- };
116
- }
117
- /** Payload for `community_post.voted` events. */
118
- interface CommunityPostVotedPayload {
119
- post: {
120
- id: string;
121
- vote_count: number;
122
- };
123
- voter: {
124
- id: string;
125
- };
126
- direction: string;
127
- }
128
- /** Payload for `customer.created` events. */
129
- interface CustomerCreatedPayload {
130
- customer: {
131
- id: string;
132
- name: string;
133
- email: string;
134
- status: string;
135
- tags: Array<string>;
136
- created_at: string;
137
- };
138
- }
139
- /** Payload for `customer.deleted` events. */
140
- interface CustomerDeletedPayload {
141
- id: string;
142
- }
143
- /** Payload for `customer.updated` events. */
144
- interface CustomerUpdatedPayload {
145
- customer: {
146
- id: string;
147
- name: string;
148
- email: string;
149
- status: string;
150
- tags: Array<string>;
151
- };
152
- changes: {
153
- tags: {
154
- from: Array<string>;
155
- to: Array<string>;
156
- };
157
- };
158
- }
159
- /** Payload for `customer_group.created` events. */
160
- interface CustomerGroupCreatedPayload {
161
- group: {
162
- id: string;
163
- name: string;
164
- color: string;
165
- member_count: number;
166
- };
167
- }
168
- /** Payload for `customer_group.deleted` events. */
169
- interface CustomerGroupDeletedPayload {
170
- customer_group: {
171
- id: string;
172
- };
173
- }
174
- /** Payload for `customer_group.updated` events. */
175
- interface CustomerGroupUpdatedPayload {
176
- group: {
177
- id: string;
178
- name: string;
179
- color: string;
180
- member_count: number;
181
- };
182
- }
183
- /** Payload for `player.achievement_unlocked` events. */
184
- interface PlayerAchievementUnlockedPayload {
185
- player: {
186
- agent_id: string;
187
- name: string;
188
- };
189
- achievement: {
190
- id: string;
191
- name: string;
192
- xp: number;
193
- };
194
- }
195
- /** Payload for `player.level_up` events. */
196
- interface PlayerLevelUpPayload {
197
- player: {
198
- agent_id: string;
199
- name: string;
200
- };
201
- level: {
202
- from: number;
203
- to: number;
204
- };
205
- title_unlocked: string;
206
- }
207
- /** Payload for `player.quest_completed` events. */
208
- interface PlayerQuestCompletedPayload {
209
- player: {
210
- agent_id: string;
211
- name: string;
212
- };
213
- quest: {
214
- id: string;
215
- name: string;
216
- xp: number;
217
- };
218
- }
219
- /** Payload for `player.streak_milestone` events. */
220
- interface PlayerStreakMilestonePayload {
221
- player: {
222
- agent_id: string;
223
- name: string;
224
- };
225
- streak_days: number;
226
- milestone: number;
227
- }
228
- /** Payload for `player.xp_gained` events. */
229
- interface PlayerXpGainedPayload {
230
- player: {
231
- agent_id: string;
232
- name: string;
233
- };
234
- amount: number;
235
- reason: string;
236
- ticket_id: string;
237
- }
238
- /** Payload for `social.high_five_sent` events. */
239
- interface SocialHighFiveSentPayload {
240
- from_team: {
241
- id: string;
242
- name: string;
243
- };
244
- to_team: {
245
- id: string;
246
- name: string;
247
- };
248
- message: string;
249
- }
250
- /** Payload for `social.one_up_sent` events. */
251
- interface SocialOneUpSentPayload {
252
- from: {
253
- agent_id: string;
254
- name: string;
255
- };
256
- to: {
257
- agent_id: string;
258
- name: string;
259
- };
260
- ticket_id: string;
261
- message: string;
262
- }
263
- /** Payload for `survey.submitted` events. */
264
- interface SurveySubmittedPayload {
265
- survey: {
266
- id: string;
267
- ticket_id: string;
268
- score: number;
269
- comment: string;
270
- submitted_at: string;
271
- };
272
- customer: {
273
- id: string;
274
- email: string;
275
- };
276
- }
277
- /** Payload for `ticket.assigned` events. */
278
- interface TicketAssignedPayload {
279
- ticket: {
280
- id: string;
281
- prefixed_id: string;
282
- };
283
- assignee: {
284
- id: string;
285
- name: string;
286
- email: string;
287
- };
288
- previous_assignee: null;
289
- }
290
- /** Payload for `ticket.closed` events. */
291
- interface TicketClosedPayload {
292
- ticket: {
293
- id: string;
294
- prefixed_id: string;
295
- title: string;
296
- status: string;
297
- priority: string;
298
- channel: string;
299
- resolved_at: string;
300
- };
301
- }
302
- /** Payload for `ticket.created` events. */
303
- interface TicketCreatedPayload {
304
- ticket: {
305
- id: string;
306
- prefixed_id: string;
307
- title: string;
308
- status: string;
309
- priority: string;
310
- channel: string;
311
- customer_id: string;
312
- created_at: string;
313
- };
314
- customer: {
315
- id: string;
316
- name: string;
317
- email: string;
318
- };
319
- }
320
- /** Payload for `ticket.deleted` events. */
321
- interface TicketDeletedPayload {
322
- id: string;
323
- }
324
- /** Payload for `ticket.message_added` events. */
325
- interface TicketMessageAddedPayload {
326
- ticket: {
327
- id: string;
328
- dashboard_url: string | null;
329
- };
330
- message: {
331
- id: string;
332
- sender: string;
333
- sender_name: string | null;
334
- content: string;
335
- created_at: string;
336
- };
337
- customer?: {
338
- id: string;
339
- name: string | null;
340
- email: string | null;
341
- };
342
- }
343
- /** Payload for `ticket.updated` events. */
344
- interface TicketUpdatedPayload {
345
- ticket: {
346
- id: string;
347
- prefixed_id: string;
348
- title: string;
349
- status: string;
350
- priority: string;
351
- channel: string;
352
- };
353
- changes: {
354
- priority: {
355
- from: string;
356
- to: string;
357
- };
358
- };
359
- }
360
- /** Maps each event type to its payload interface — used internally for the discriminated union. */
361
- interface WebhookEventDataMap {
362
- 'article.created': ArticleCreatedPayload;
363
- 'article.deleted': ArticleDeletedPayload;
364
- 'article.published': ArticlePublishedPayload;
365
- 'article.updated': ArticleUpdatedPayload;
366
- 'boss.damaged': BossDamagedPayload;
367
- 'boss.defeated': BossDefeatedPayload;
368
- 'boss.spawned': BossSpawnedPayload;
369
- 'community_post.commented': CommunityPostCommentedPayload;
370
- 'community_post.created': CommunityPostCreatedPayload;
371
- 'community_post.deleted': CommunityPostDeletedPayload;
372
- 'community_post.status_changed': CommunityPostStatusChangedPayload;
373
- 'community_post.updated': CommunityPostUpdatedPayload;
374
- 'community_post.voted': CommunityPostVotedPayload;
375
- 'customer.created': CustomerCreatedPayload;
376
- 'customer.deleted': CustomerDeletedPayload;
377
- 'customer.updated': CustomerUpdatedPayload;
378
- 'customer_group.created': CustomerGroupCreatedPayload;
379
- 'customer_group.deleted': CustomerGroupDeletedPayload;
380
- 'customer_group.updated': CustomerGroupUpdatedPayload;
381
- 'player.achievement_unlocked': PlayerAchievementUnlockedPayload;
382
- 'player.level_up': PlayerLevelUpPayload;
383
- 'player.quest_completed': PlayerQuestCompletedPayload;
384
- 'player.streak_milestone': PlayerStreakMilestonePayload;
385
- 'player.xp_gained': PlayerXpGainedPayload;
386
- 'social.high_five_sent': SocialHighFiveSentPayload;
387
- 'social.one_up_sent': SocialOneUpSentPayload;
388
- 'survey.submitted': SurveySubmittedPayload;
389
- 'ticket.assigned': TicketAssignedPayload;
390
- 'ticket.closed': TicketClosedPayload;
391
- 'ticket.created': TicketCreatedPayload;
392
- 'ticket.deleted': TicketDeletedPayload;
393
- 'ticket.message_added': TicketMessageAddedPayload;
394
- 'ticket.updated': TicketUpdatedPayload;
395
- }
396
- /** A webhook event delivered to your endpoint. */
397
- interface WebhookEvent<T extends WebhookEventType = WebhookEventType> {
398
- /** Unique event ID (idempotency key). */
399
- id: string;
400
- /** Event type. */
401
- type: T;
402
- /** When the event was created (ISO 8601). */
403
- created_at: string;
404
- /** Team that owns this event. */
405
- team_id: string;
406
- /** Event-specific payload. */
407
- data: WebhookEventDataMap[T];
408
- }
409
-
410
- /** Thrown when webhook signature verification fails. */
411
- declare class WebhookSignatureVerificationError extends Error {
412
- constructor(message: string);
413
- }
414
- /**
415
- * Verify a webhook signature and parse the event (synchronous, Node.js only).
416
- *
417
- * Uses Node.js `crypto` module for timing-safe HMAC comparison.
418
- * For browser/edge environments, use `constructEventAsync()`.
419
- *
420
- * @param rawBody - Raw request body as a string (NOT parsed JSON)
421
- * @param signature - Value of the `X-Signature` header
422
- * @param secret - Your webhook endpoint's secret (`whsec_*`)
423
- * @returns Parsed and verified webhook event
424
- * @throws {WebhookSignatureVerificationError} If verification fails
425
- */
426
- declare function constructEvent(rawBody: string, signature: string, secret: string): WebhookEvent;
427
- /**
428
- * Verify a webhook signature and parse the event (async, works everywhere).
429
- *
430
- * Uses the Web Crypto API — compatible with browsers, Deno, Cloudflare Workers,
431
- * and Node.js 18+.
432
- *
433
- * @param rawBody - Raw request body as a string (NOT parsed JSON)
434
- * @param signature - Value of the `X-Signature` header
435
- * @param secret - Your webhook endpoint's secret (`whsec_*`)
436
- * @returns Parsed and verified webhook event
437
- * @throws {WebhookSignatureVerificationError} If verification fails
438
- */
439
- declare function constructEventAsync(rawBody: string, signature: string, secret: string): Promise<WebhookEvent>;
440
- /**
441
- * Verify an HMAC-SHA256 signature (synchronous, Node.js only).
442
- * Uses timing-safe comparison to prevent timing attacks.
443
- */
444
- declare function verifySignature(rawBody: string, signature: string, secret: string): boolean;
445
- /**
446
- * Verify an HMAC-SHA256 signature (async, works everywhere).
447
- * Uses the Web Crypto API with constant-time comparison.
448
- */
449
- declare function verifySignatureAsync(rawBody: string, signature: string, secret: string): Promise<boolean>;
450
-
451
- export { type WebhookEvent, WebhookSignatureVerificationError, constructEvent, constructEventAsync, verifySignature, verifySignatureAsync };