@getvervet/sdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Primate Ventures
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @getvervet/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vervet for your server: a typed client for every `/v1` operation and `signIdentity()`, which
4
+ signs the token the web and mobile SDKs pass so Vervet knows who is asking.
5
+
6
+ **Size budget: under 4 KB gzipped** (about 2 KB today), no runtime dependencies. CI fails a change
7
+ that exceeds it (`pnpm check:sdk-size`). Runs on Node 18+, Deno, Bun and edge
8
+ runtimes (it needs `fetch` and Web Crypto).
9
+
10
+ ```ts
11
+ import { createClient, signIdentity } from '@getvervet/sdk';
12
+
13
+ // After your own sign-in: hand this token to @getvervet/web or the mobile SDK.
14
+ const token = await signIdentity(
15
+ { sub: user.id, email: user.email, name: user.name },
16
+ process.env.VERVET_IDENTITY_SECRET!,
17
+ );
18
+
19
+ const vervet = createClient({ key: process.env.VERVET_SECRET_KEY! });
20
+ const tickets = await vervet.call('listTickets', { input: { state: 'open' } });
21
+ await vervet.call('addTicketMessage', {
22
+ params: { id: tickets.data[0]!.id },
23
+ input: { body: 'On it.' },
24
+ });
25
+ await vervet.call('eraseEndUser', { params: { external_id: user.id } });
26
+ ```
27
+
28
+ - Every write carries an `Idempotency-Key`, so retries never file twice. Rate-limited and
29
+ server-error responses are retried twice, honouring `Retry-After`.
30
+ - Errors throw `VervetError` with `status`, `code`, `message` and, for validation, `field`.
31
+ - Identity tokens are HS256 JWTs that live at most one hour. Keep the identity secret on your
32
+ server.
@@ -0,0 +1,597 @@
1
+ /** The input (query or body) and output of every /v1 operation. */
2
+ export interface Operations {
3
+ createTicket: {
4
+ method: 'POST';
5
+ path: '/v1/tickets';
6
+ input: {
7
+ body: string;
8
+ subject: string;
9
+ email?: string | undefined;
10
+ context?: {
11
+ app_name?: string | undefined;
12
+ app_version?: string | undefined;
13
+ app_build?: string | undefined;
14
+ platform?: 'web' | 'ios' | 'android' | undefined;
15
+ os?: string | undefined;
16
+ os_version?: string | undefined;
17
+ device_model?: string | undefined;
18
+ browser?: string | undefined;
19
+ locale?: string | undefined;
20
+ time_zone?: string | undefined;
21
+ screen?: {
22
+ width: number;
23
+ height: number;
24
+ } | undefined;
25
+ route?: string | undefined;
26
+ url?: string | undefined;
27
+ sdk_version?: string | undefined;
28
+ console_errors?: string[] | undefined;
29
+ network_failures?: {
30
+ status: number;
31
+ url: string;
32
+ method: string;
33
+ }[] | undefined;
34
+ } | undefined;
35
+ };
36
+ output: {
37
+ number: number;
38
+ priority: 'low' | 'normal' | 'high' | 'urgent';
39
+ tags: string[];
40
+ id: string;
41
+ subject: string;
42
+ state: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed';
43
+ assignee_id: string | null;
44
+ end_user_id: string;
45
+ source: 'api' | 'sdk' | 'portal';
46
+ opened_at: string;
47
+ first_response_at: string | null;
48
+ solved_at: string | null;
49
+ closed_at: string | null;
50
+ messages: {
51
+ id: string;
52
+ internal: boolean;
53
+ author_kind: 'operator' | 'end_user' | 'system';
54
+ body: string;
55
+ created_at: string;
56
+ }[];
57
+ };
58
+ };
59
+ listTickets: {
60
+ method: 'GET';
61
+ path: '/v1/tickets';
62
+ input: {
63
+ end_user?: string | undefined;
64
+ cursor?: string | undefined;
65
+ limit?: number | undefined;
66
+ state?: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed' | undefined;
67
+ };
68
+ output: {
69
+ data: {
70
+ number: number;
71
+ priority: 'low' | 'normal' | 'high' | 'urgent';
72
+ tags: string[];
73
+ id: string;
74
+ subject: string;
75
+ state: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed';
76
+ assignee_id: string | null;
77
+ end_user_id: string;
78
+ source: 'api' | 'sdk' | 'portal';
79
+ opened_at: string;
80
+ first_response_at: string | null;
81
+ solved_at: string | null;
82
+ closed_at: string | null;
83
+ }[];
84
+ next_cursor: string | null;
85
+ };
86
+ };
87
+ getTicket: {
88
+ method: 'GET';
89
+ path: '/v1/tickets/{id}';
90
+ input: never;
91
+ output: {
92
+ number: number;
93
+ priority: 'low' | 'normal' | 'high' | 'urgent';
94
+ tags: string[];
95
+ id: string;
96
+ subject: string;
97
+ state: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed';
98
+ assignee_id: string | null;
99
+ end_user_id: string;
100
+ source: 'api' | 'sdk' | 'portal';
101
+ opened_at: string;
102
+ first_response_at: string | null;
103
+ solved_at: string | null;
104
+ closed_at: string | null;
105
+ messages: {
106
+ id: string;
107
+ internal: boolean;
108
+ author_kind: 'operator' | 'end_user' | 'system';
109
+ body: string;
110
+ created_at: string;
111
+ }[];
112
+ };
113
+ };
114
+ addTicketMessage: {
115
+ method: 'POST';
116
+ path: '/v1/tickets/{id}/messages';
117
+ input: {
118
+ body: string;
119
+ internal?: boolean | undefined;
120
+ };
121
+ output: {
122
+ id: string;
123
+ internal: boolean;
124
+ author_kind: 'operator' | 'end_user' | 'system';
125
+ body: string;
126
+ created_at: string;
127
+ };
128
+ };
129
+ updateTicket: {
130
+ method: 'PATCH';
131
+ path: '/v1/tickets/{id}';
132
+ input: {
133
+ priority?: 'low' | 'normal' | 'high' | 'urgent' | undefined;
134
+ tags?: string[] | undefined;
135
+ state?: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed' | undefined;
136
+ assignee_id?: string | null | undefined;
137
+ };
138
+ output: {
139
+ number: number;
140
+ priority: 'low' | 'normal' | 'high' | 'urgent';
141
+ tags: string[];
142
+ id: string;
143
+ subject: string;
144
+ state: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed';
145
+ assignee_id: string | null;
146
+ end_user_id: string;
147
+ source: 'api' | 'sdk' | 'portal';
148
+ opened_at: string;
149
+ first_response_at: string | null;
150
+ solved_at: string | null;
151
+ closed_at: string | null;
152
+ };
153
+ };
154
+ createRequest: {
155
+ method: 'POST';
156
+ path: '/v1/requests';
157
+ input: {
158
+ title: string;
159
+ body?: string | undefined;
160
+ email?: string | undefined;
161
+ };
162
+ output: {
163
+ id: string;
164
+ title: string;
165
+ body: string;
166
+ created_at: string;
167
+ state: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged';
168
+ public: boolean;
169
+ merged_into_id: string | null;
170
+ vote_count: number;
171
+ requester_count: number;
172
+ voted?: boolean | undefined;
173
+ };
174
+ };
175
+ listRequests: {
176
+ method: 'GET';
177
+ path: '/v1/requests';
178
+ input: {
179
+ sort?: 'new' | 'top' | undefined;
180
+ cursor?: string | undefined;
181
+ limit?: number | undefined;
182
+ state?: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged' | undefined;
183
+ similar_to?: string | undefined;
184
+ };
185
+ output: {
186
+ data: {
187
+ id: string;
188
+ title: string;
189
+ body: string;
190
+ created_at: string;
191
+ state: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged';
192
+ public: boolean;
193
+ merged_into_id: string | null;
194
+ vote_count: number;
195
+ requester_count: number;
196
+ voted?: boolean | undefined;
197
+ }[];
198
+ next_cursor: string | null;
199
+ };
200
+ };
201
+ addVote: {
202
+ method: 'POST';
203
+ path: '/v1/requests/{id}/votes';
204
+ input: never;
205
+ output: {
206
+ id: string;
207
+ title: string;
208
+ body: string;
209
+ created_at: string;
210
+ state: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged';
211
+ public: boolean;
212
+ merged_into_id: string | null;
213
+ vote_count: number;
214
+ requester_count: number;
215
+ voted?: boolean | undefined;
216
+ };
217
+ };
218
+ removeVote: {
219
+ method: 'DELETE';
220
+ path: '/v1/requests/{id}/votes';
221
+ input: never;
222
+ output: {
223
+ id: string;
224
+ title: string;
225
+ body: string;
226
+ created_at: string;
227
+ state: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged';
228
+ public: boolean;
229
+ merged_into_id: string | null;
230
+ vote_count: number;
231
+ requester_count: number;
232
+ voted?: boolean | undefined;
233
+ };
234
+ };
235
+ mergeRequest: {
236
+ method: 'POST';
237
+ path: '/v1/requests/{id}/merge';
238
+ input: {
239
+ into_id: string;
240
+ };
241
+ output: {
242
+ id: string;
243
+ title: string;
244
+ body: string;
245
+ created_at: string;
246
+ state: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged';
247
+ public: boolean;
248
+ merged_into_id: string | null;
249
+ vote_count: number;
250
+ requester_count: number;
251
+ voted?: boolean | undefined;
252
+ };
253
+ };
254
+ uploadAttachment: {
255
+ method: 'POST';
256
+ path: '/v1/attachments';
257
+ input: {
258
+ kind: 'screenshot';
259
+ content_type: 'image/png' | 'image/jpeg' | 'image/webp';
260
+ data: string;
261
+ };
262
+ output: {
263
+ kind: 'screenshot';
264
+ id: string;
265
+ expires_at: string;
266
+ };
267
+ };
268
+ createBug: {
269
+ method: 'POST';
270
+ path: '/v1/bugs';
271
+ input: {
272
+ title: string;
273
+ body?: string | undefined;
274
+ email?: string | undefined;
275
+ context?: {
276
+ app_name?: string | undefined;
277
+ app_version?: string | undefined;
278
+ app_build?: string | undefined;
279
+ platform?: 'web' | 'ios' | 'android' | undefined;
280
+ os?: string | undefined;
281
+ os_version?: string | undefined;
282
+ device_model?: string | undefined;
283
+ browser?: string | undefined;
284
+ locale?: string | undefined;
285
+ time_zone?: string | undefined;
286
+ screen?: {
287
+ width: number;
288
+ height: number;
289
+ } | undefined;
290
+ route?: string | undefined;
291
+ url?: string | undefined;
292
+ sdk_version?: string | undefined;
293
+ console_errors?: string[] | undefined;
294
+ network_failures?: {
295
+ status: number;
296
+ url: string;
297
+ method: string;
298
+ }[] | undefined;
299
+ } | undefined;
300
+ screenshot_id?: string | undefined;
301
+ };
302
+ output: {
303
+ id: string;
304
+ title: string;
305
+ body: string;
306
+ created_at: string;
307
+ state: 'in_progress' | 'new' | 'triaged' | 'fixed' | 'wont_fix' | 'duplicate';
308
+ context: {
309
+ app_name?: string | undefined;
310
+ app_version?: string | undefined;
311
+ app_build?: string | undefined;
312
+ platform?: 'web' | 'ios' | 'android' | undefined;
313
+ os?: string | undefined;
314
+ os_version?: string | undefined;
315
+ device_model?: string | undefined;
316
+ browser?: string | undefined;
317
+ locale?: string | undefined;
318
+ time_zone?: string | undefined;
319
+ screen?: {
320
+ width: number;
321
+ height: number;
322
+ } | undefined;
323
+ route?: string | undefined;
324
+ url?: string | undefined;
325
+ sdk_version?: string | undefined;
326
+ console_errors?: string[] | undefined;
327
+ network_failures?: {
328
+ status: number;
329
+ url: string;
330
+ method: string;
331
+ }[] | undefined;
332
+ };
333
+ severity: 'low' | 'high' | 'medium' | 'critical' | null;
334
+ attachments: {
335
+ kind: 'screenshot';
336
+ id: string;
337
+ url: string;
338
+ }[];
339
+ duplicate_of_id: string | null;
340
+ external_issue: {
341
+ key: string;
342
+ url: string;
343
+ provider: 'other' | 'jira' | 'linear' | 'github';
344
+ } | null;
345
+ };
346
+ };
347
+ getBug: {
348
+ method: 'GET';
349
+ path: '/v1/bugs/{id}';
350
+ input: never;
351
+ output: {
352
+ id: string;
353
+ title: string;
354
+ body: string;
355
+ created_at: string;
356
+ state: 'in_progress' | 'new' | 'triaged' | 'fixed' | 'wont_fix' | 'duplicate';
357
+ context: {
358
+ app_name?: string | undefined;
359
+ app_version?: string | undefined;
360
+ app_build?: string | undefined;
361
+ platform?: 'web' | 'ios' | 'android' | undefined;
362
+ os?: string | undefined;
363
+ os_version?: string | undefined;
364
+ device_model?: string | undefined;
365
+ browser?: string | undefined;
366
+ locale?: string | undefined;
367
+ time_zone?: string | undefined;
368
+ screen?: {
369
+ width: number;
370
+ height: number;
371
+ } | undefined;
372
+ route?: string | undefined;
373
+ url?: string | undefined;
374
+ sdk_version?: string | undefined;
375
+ console_errors?: string[] | undefined;
376
+ network_failures?: {
377
+ status: number;
378
+ url: string;
379
+ method: string;
380
+ }[] | undefined;
381
+ };
382
+ severity: 'low' | 'high' | 'medium' | 'critical' | null;
383
+ attachments: {
384
+ kind: 'screenshot';
385
+ id: string;
386
+ url: string;
387
+ }[];
388
+ duplicate_of_id: string | null;
389
+ external_issue: {
390
+ key: string;
391
+ url: string;
392
+ provider: 'other' | 'jira' | 'linear' | 'github';
393
+ } | null;
394
+ };
395
+ };
396
+ getRoadmap: {
397
+ method: 'GET';
398
+ path: '/v1/roadmap';
399
+ input: never;
400
+ output: {
401
+ items: {
402
+ id: string;
403
+ title: string;
404
+ description: string;
405
+ status: 'planned' | 'in_progress' | 'shipped';
406
+ target_month: string | null;
407
+ shipped_at: string | null;
408
+ position: number;
409
+ request_ids: string[];
410
+ }[];
411
+ };
412
+ };
413
+ updateRoadmapItem: {
414
+ method: 'PATCH';
415
+ path: '/v1/roadmap/items/{id}';
416
+ input: {
417
+ title?: string | undefined;
418
+ description?: string | undefined;
419
+ status?: 'planned' | 'in_progress' | 'shipped' | undefined;
420
+ public?: boolean | undefined;
421
+ target_month?: string | null | undefined;
422
+ position?: number | undefined;
423
+ };
424
+ output: {
425
+ id: string;
426
+ title: string;
427
+ description: string;
428
+ status: 'planned' | 'in_progress' | 'shipped';
429
+ target_month: string | null;
430
+ shipped_at: string | null;
431
+ position: number;
432
+ request_ids: string[];
433
+ };
434
+ };
435
+ getConfig: {
436
+ method: 'GET';
437
+ path: '/v1/config';
438
+ input: never;
439
+ output: {
440
+ brand: {
441
+ display_name: string;
442
+ accent_hex: string;
443
+ tab_label: string;
444
+ tab_hidden: boolean;
445
+ hide_vervet_mark: boolean;
446
+ };
447
+ capture: {
448
+ console: boolean;
449
+ network: boolean;
450
+ screenshots: boolean;
451
+ scrub_query_params: string[];
452
+ };
453
+ identity_required: boolean;
454
+ roadmap_public: boolean;
455
+ board_public: boolean;
456
+ };
457
+ };
458
+ listNotices: {
459
+ method: 'GET';
460
+ path: '/v1/notices';
461
+ input: {
462
+ cursor?: string | undefined;
463
+ limit?: number | undefined;
464
+ unread?: 'true' | 'false' | undefined;
465
+ };
466
+ output: {
467
+ data: {
468
+ kind: 'shipped' | 'ticket_reply';
469
+ id: string;
470
+ title: string;
471
+ created_at: string;
472
+ subject_id: string;
473
+ read_at: string | null;
474
+ }[];
475
+ next_cursor: string | null;
476
+ };
477
+ };
478
+ markNoticesRead: {
479
+ method: 'POST';
480
+ path: '/v1/notices/read';
481
+ input: never;
482
+ output: {
483
+ marked: number;
484
+ };
485
+ };
486
+ exportEndUser: {
487
+ method: 'GET';
488
+ path: '/v1/end-users/{external_id}/export';
489
+ input: never;
490
+ output: {
491
+ end_user: {
492
+ email: string | null;
493
+ external_id: string;
494
+ name: string | null;
495
+ };
496
+ tickets: {
497
+ number: number;
498
+ priority: 'low' | 'normal' | 'high' | 'urgent';
499
+ tags: string[];
500
+ id: string;
501
+ subject: string;
502
+ state: 'open' | 'pending' | 'on_hold' | 'solved' | 'closed';
503
+ assignee_id: string | null;
504
+ end_user_id: string;
505
+ source: 'api' | 'sdk' | 'portal';
506
+ opened_at: string;
507
+ first_response_at: string | null;
508
+ solved_at: string | null;
509
+ closed_at: string | null;
510
+ messages: {
511
+ id: string;
512
+ internal: boolean;
513
+ author_kind: 'operator' | 'end_user' | 'system';
514
+ body: string;
515
+ created_at: string;
516
+ }[];
517
+ }[];
518
+ requests: {
519
+ id: string;
520
+ title: string;
521
+ body: string;
522
+ created_at: string;
523
+ state: 'open' | 'under_review' | 'planned' | 'in_progress' | 'shipped' | 'declined' | 'merged';
524
+ public: boolean;
525
+ merged_into_id: string | null;
526
+ vote_count: number;
527
+ requester_count: number;
528
+ voted?: boolean | undefined;
529
+ }[];
530
+ votes: {
531
+ created_at: string;
532
+ request_id: string;
533
+ }[];
534
+ bugs: {
535
+ id: string;
536
+ title: string;
537
+ body: string;
538
+ created_at: string;
539
+ state: 'in_progress' | 'new' | 'triaged' | 'fixed' | 'wont_fix' | 'duplicate';
540
+ context: {
541
+ app_name?: string | undefined;
542
+ app_version?: string | undefined;
543
+ app_build?: string | undefined;
544
+ platform?: 'web' | 'ios' | 'android' | undefined;
545
+ os?: string | undefined;
546
+ os_version?: string | undefined;
547
+ device_model?: string | undefined;
548
+ browser?: string | undefined;
549
+ locale?: string | undefined;
550
+ time_zone?: string | undefined;
551
+ screen?: {
552
+ width: number;
553
+ height: number;
554
+ } | undefined;
555
+ route?: string | undefined;
556
+ url?: string | undefined;
557
+ sdk_version?: string | undefined;
558
+ console_errors?: string[] | undefined;
559
+ network_failures?: {
560
+ status: number;
561
+ url: string;
562
+ method: string;
563
+ }[] | undefined;
564
+ };
565
+ severity: 'low' | 'high' | 'medium' | 'critical' | null;
566
+ attachments: {
567
+ kind: 'screenshot';
568
+ id: string;
569
+ url: string;
570
+ }[];
571
+ duplicate_of_id: string | null;
572
+ external_issue: {
573
+ key: string;
574
+ url: string;
575
+ provider: 'other' | 'jira' | 'linear' | 'github';
576
+ } | null;
577
+ }[];
578
+ };
579
+ };
580
+ eraseEndUser: {
581
+ method: 'DELETE';
582
+ path: '/v1/end-users/{external_id}';
583
+ input: never;
584
+ output: {
585
+ external_id: string;
586
+ erased: true;
587
+ };
588
+ };
589
+ exportTenant: {
590
+ method: 'GET';
591
+ path: '/v1/export';
592
+ input: never;
593
+ output: {
594
+ [x: string]: unknown;
595
+ };
596
+ };
597
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `@getvervet/sdk`: Vervet for tenants' servers (design D3, D13; spec: public-api).
3
+ *
4
+ * - `createClient()` calls every /v1 operation, typed from the one API contract.
5
+ * - `signIdentity()` signs the identity token the web and mobile SDKs pass, so Vervet can link an
6
+ * end user's submissions across sessions and devices.
7
+ *
8
+ * It runs wherever `fetch` and Web Crypto exist: Node 18+, Deno, Bun, edge runtimes.
9
+ */
10
+ import type { Operations } from './contract.gen.js';
11
+ export type { Operations } from './contract.gen.js';
12
+ export declare const SDK_VERSION = "0.1.0";
13
+ export declare const DEFAULT_BASE_URL = "https://getvervet.com";
14
+ type Ops = Operations;
15
+ export type OperationName = keyof Ops;
16
+ type InputOf<K extends OperationName> = Ops[K]['input'];
17
+ /** What an operation returns, as the contract declares it. */
18
+ export type Output<K extends OperationName> = Ops[K]['output'];
19
+ type ParamNames<P extends string> = P extends `${string}{${infer N}}${infer Rest}` ? N | ParamNames<Rest> : never;
20
+ type ParamsOf<K extends OperationName> = [ParamNames<Ops[K]['path']>] extends [never] ? {
21
+ params?: undefined;
22
+ } : {
23
+ params: Record<ParamNames<Ops[K]['path']>, string>;
24
+ };
25
+ type BodyOf<K extends OperationName> = [InputOf<K>] extends [never] ? {
26
+ input?: undefined;
27
+ } : {
28
+ input: InputOf<K>;
29
+ };
30
+ /** Arguments for `client.call(name, args)`: path parameters and the query or body. */
31
+ export type CallArgs<K extends OperationName> = ParamsOf<K> & BodyOf<K> & {
32
+ /** Identifies the end user acting, for calls made with a publishable key. */
33
+ identity?: string;
34
+ /** Sent as `Idempotency-Key`; generated for every write when not given. */
35
+ idempotencyKey?: string;
36
+ };
37
+ export interface ClientOptions {
38
+ /** A secret key (`vv_sk_…`) on a server, or a publishable key (`vv_pk_…`). */
39
+ key: string;
40
+ baseUrl?: string;
41
+ /** For native apps using a publishable key: the app's bundle id. */
42
+ appId?: string;
43
+ /** Retries on 429 and 5xx, honouring `Retry-After`. Default 2. Writes are idempotent. */
44
+ retries?: number;
45
+ fetch?: typeof fetch;
46
+ }
47
+ /** The one error shape for /v1: `{ error: { code, message, field? } }`. */
48
+ export declare class VervetError extends Error {
49
+ readonly status: number;
50
+ readonly code: string;
51
+ readonly field?: string | undefined;
52
+ constructor(message: string, status: number, code: string, field?: string | undefined);
53
+ }
54
+ export interface VervetClient {
55
+ call<K extends OperationName>(name: K, ...args: CallArgsTuple<K>): Promise<Output<K>>;
56
+ }
57
+ type CallArgsTuple<K extends OperationName> = object extends CallArgs<K> ? [args?: CallArgs<K>] : [args: CallArgs<K>];
58
+ export declare function createClient(options: ClientOptions): VervetClient;
59
+ export interface IdentityClaims {
60
+ /** The tenant's own id for this user. */
61
+ sub: string;
62
+ email?: string;
63
+ name?: string;
64
+ }
65
+ /**
66
+ * Sign an identity token (HS256 JWT) with the tenant's identity secret. Call it on your server
67
+ * only, after your own sign-in, and hand the token to the web or mobile SDK. Tokens live at most
68
+ * one hour; Vervet rejects longer ones.
69
+ */
70
+ export declare function signIdentity(claims: IdentityClaims, secret: string, options?: {
71
+ expiresInSeconds?: number;
72
+ now?: number;
73
+ }): Promise<string>;
package/dist/index.js ADDED
@@ -0,0 +1,152 @@
1
+ // src/routes.ts
2
+ var routes = {
3
+ createTicket: ["POST", "/v1/tickets"],
4
+ listTickets: ["GET", "/v1/tickets"],
5
+ getTicket: ["GET", "/v1/tickets/{id}"],
6
+ addTicketMessage: ["POST", "/v1/tickets/{id}/messages"],
7
+ updateTicket: ["PATCH", "/v1/tickets/{id}"],
8
+ createRequest: ["POST", "/v1/requests"],
9
+ listRequests: ["GET", "/v1/requests"],
10
+ addVote: ["POST", "/v1/requests/{id}/votes"],
11
+ removeVote: ["DELETE", "/v1/requests/{id}/votes"],
12
+ mergeRequest: ["POST", "/v1/requests/{id}/merge"],
13
+ uploadAttachment: ["POST", "/v1/attachments"],
14
+ createBug: ["POST", "/v1/bugs"],
15
+ getBug: ["GET", "/v1/bugs/{id}"],
16
+ getRoadmap: ["GET", "/v1/roadmap"],
17
+ updateRoadmapItem: ["PATCH", "/v1/roadmap/items/{id}"],
18
+ getConfig: ["GET", "/v1/config"],
19
+ listNotices: ["GET", "/v1/notices"],
20
+ markNoticesRead: ["POST", "/v1/notices/read"],
21
+ exportEndUser: ["GET", "/v1/end-users/{external_id}/export"],
22
+ eraseEndUser: ["DELETE", "/v1/end-users/{external_id}"],
23
+ exportTenant: ["GET", "/v1/export"]
24
+ };
25
+
26
+ // src/index.ts
27
+ var SDK_VERSION = "0.1.0";
28
+ var DEFAULT_BASE_URL = "https://getvervet.com";
29
+ var VervetError = class extends Error {
30
+ constructor(message, status, code, field) {
31
+ super(message);
32
+ this.status = status;
33
+ this.code = code;
34
+ this.field = field;
35
+ this.name = "VervetError";
36
+ }
37
+ status;
38
+ code;
39
+ field;
40
+ };
41
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
42
+ function buildPath(template, params) {
43
+ return template.replace(/\{(\w+)\}/g, (_, name) => {
44
+ const value = params?.[name];
45
+ if (value === void 0 || value === "") throw new TypeError(`Missing path parameter ${name}.`);
46
+ return encodeURIComponent(value);
47
+ });
48
+ }
49
+ function toQuery(input) {
50
+ if (!input || typeof input !== "object") return "";
51
+ const qs = new URLSearchParams();
52
+ for (const [k, v] of Object.entries(input)) {
53
+ if (v !== void 0 && v !== null) qs.set(k, String(v));
54
+ }
55
+ const s = qs.toString();
56
+ return s ? `?${s}` : "";
57
+ }
58
+ function keyHeader(key) {
59
+ if (typeof key === "string" && key.startsWith("vv_sk_"))
60
+ return ["Authorization", `Bearer ${key}`];
61
+ if (typeof key === "string" && key.startsWith("vv_pk_")) return ["X-Vervet-Key", key];
62
+ throw new TypeError(
63
+ "createClient needs a Vervet key: a secret key (vv_sk_\u2026) on a server, or a publishable key (vv_pk_\u2026)."
64
+ );
65
+ }
66
+ function createClient(options) {
67
+ const [keyName, keyValue] = keyHeader(options.key);
68
+ const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
69
+ const doFetch = options.fetch ?? globalThis.fetch.bind(globalThis);
70
+ const retries = options.retries ?? 2;
71
+ async function call(name, args) {
72
+ const [method, template] = routes[name];
73
+ const a = args ?? {};
74
+ const path = buildPath(template, a.params);
75
+ const url = base + path + (method === "GET" ? toQuery(a.input) : "");
76
+ const headers = {
77
+ [keyName]: keyValue,
78
+ "X-Vervet-Client": `sdk-js/${SDK_VERSION}`
79
+ };
80
+ if (options.appId) headers["X-Vervet-App"] = options.appId;
81
+ if (a.identity) headers["X-Vervet-Identity"] = a.identity;
82
+ let body;
83
+ if (method !== "GET") {
84
+ headers["Idempotency-Key"] = a.idempotencyKey ?? globalThis.crypto.randomUUID();
85
+ if (a.input !== void 0) {
86
+ headers["Content-Type"] = "application/json";
87
+ body = JSON.stringify(a.input);
88
+ }
89
+ }
90
+ for (let attempt = 0; ; attempt++) {
91
+ const res = await doFetch(url, { method, headers, ...body !== void 0 ? { body } : {} });
92
+ if ((res.status === 429 || res.status >= 500) && attempt < retries) {
93
+ const after = Number(res.headers.get("Retry-After"));
94
+ await sleep(
95
+ Number.isFinite(after) && after > 0 ? Math.min(after, 30) * 1e3 : 250 * 2 ** attempt
96
+ );
97
+ continue;
98
+ }
99
+ const text = await res.text();
100
+ let json = void 0;
101
+ try {
102
+ json = text ? JSON.parse(text) : void 0;
103
+ } catch {
104
+ }
105
+ if (!res.ok) {
106
+ const err = json?.error;
107
+ throw new VervetError(
108
+ err?.message ?? `Vervet answered ${res.status}.`,
109
+ res.status,
110
+ err?.code ?? "internal",
111
+ err?.field
112
+ );
113
+ }
114
+ return json;
115
+ }
116
+ }
117
+ return { call };
118
+ }
119
+ var enc = new TextEncoder();
120
+ function b64url(bytes) {
121
+ let s = "";
122
+ for (const b of bytes) s += String.fromCharCode(b);
123
+ return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
124
+ }
125
+ async function signIdentity(claims, secret, options = {}) {
126
+ if (!claims.sub) throw new TypeError("signIdentity needs a sub: your id for this user.");
127
+ if (!secret) throw new TypeError("signIdentity needs the identity secret from your dashboard.");
128
+ const ttl = options.expiresInSeconds ?? 3600;
129
+ if (ttl <= 0 || ttl > 3600) throw new RangeError("expiresInSeconds must be between 1 and 3600.");
130
+ const now = Math.floor((options.now ?? Date.now()) / 1e3);
131
+ const payload = { sub: claims.sub, exp: now + ttl, iat: now };
132
+ if (claims.email) payload.email = claims.email;
133
+ if (claims.name) payload.name = claims.name;
134
+ const head = b64url(enc.encode(JSON.stringify({ alg: "HS256", typ: "JWT" })));
135
+ const body = b64url(enc.encode(JSON.stringify(payload)));
136
+ const key = await globalThis.crypto.subtle.importKey(
137
+ "raw",
138
+ enc.encode(secret),
139
+ { name: "HMAC", hash: "SHA-256" },
140
+ false,
141
+ ["sign"]
142
+ );
143
+ const sig = await globalThis.crypto.subtle.sign("HMAC", key, enc.encode(`${head}.${body}`));
144
+ return `${head}.${body}.${b64url(new Uint8Array(sig))}`;
145
+ }
146
+ export {
147
+ DEFAULT_BASE_URL,
148
+ SDK_VERSION,
149
+ VervetError,
150
+ createClient,
151
+ signIdentity
152
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Method and path of every /v1 operation, kept as plain data so the SDK carries no schema library
3
+ * at runtime. A test holds this table equal to `@vervet/api-contract`, so the two cannot drift.
4
+ */
5
+ export declare const routes: {
6
+ readonly createTicket: readonly ["POST", "/v1/tickets"];
7
+ readonly listTickets: readonly ["GET", "/v1/tickets"];
8
+ readonly getTicket: readonly ["GET", "/v1/tickets/{id}"];
9
+ readonly addTicketMessage: readonly ["POST", "/v1/tickets/{id}/messages"];
10
+ readonly updateTicket: readonly ["PATCH", "/v1/tickets/{id}"];
11
+ readonly createRequest: readonly ["POST", "/v1/requests"];
12
+ readonly listRequests: readonly ["GET", "/v1/requests"];
13
+ readonly addVote: readonly ["POST", "/v1/requests/{id}/votes"];
14
+ readonly removeVote: readonly ["DELETE", "/v1/requests/{id}/votes"];
15
+ readonly mergeRequest: readonly ["POST", "/v1/requests/{id}/merge"];
16
+ readonly uploadAttachment: readonly ["POST", "/v1/attachments"];
17
+ readonly createBug: readonly ["POST", "/v1/bugs"];
18
+ readonly getBug: readonly ["GET", "/v1/bugs/{id}"];
19
+ readonly getRoadmap: readonly ["GET", "/v1/roadmap"];
20
+ readonly updateRoadmapItem: readonly ["PATCH", "/v1/roadmap/items/{id}"];
21
+ readonly getConfig: readonly ["GET", "/v1/config"];
22
+ readonly listNotices: readonly ["GET", "/v1/notices"];
23
+ readonly markNoticesRead: readonly ["POST", "/v1/notices/read"];
24
+ readonly exportEndUser: readonly ["GET", "/v1/end-users/{external_id}/export"];
25
+ readonly eraseEndUser: readonly ["DELETE", "/v1/end-users/{external_id}"];
26
+ readonly exportTenant: readonly ["GET", "/v1/export"];
27
+ };
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@getvervet/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Vervet for tenants' servers: a typed /v1 client and signIdentity() for verified end users.",
6
+ "license": "MIT",
7
+ "homepage": "https://getvervet.com/docs/platforms/server",
8
+ "keywords": [
9
+ "vervet",
10
+ "support",
11
+ "feedback",
12
+ "feature-requests",
13
+ "sdk"
14
+ ],
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md"
30
+ ],
31
+ "sideEffects": false,
32
+ "devDependencies": {
33
+ "zod": "^3.25",
34
+ "@vervet/api-contract": "0.0.0"
35
+ },
36
+ "vervet": {
37
+ "budget": {
38
+ "entry": "src/index.ts",
39
+ "platform": "node",
40
+ "gzipKb": 4
41
+ }
42
+ },
43
+ "scripts": {
44
+ "build": "tsx build.ts",
45
+ "gen:types": "tsx scripts/gen-types.ts",
46
+ "typecheck": "tsc -p tsconfig.json --noEmit"
47
+ },
48
+ "types": "./dist/index.d.ts"
6
49
  }