@vybit/api-sdk 1.0.1 → 1.1.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.
package/README.md CHANGED
@@ -1,15 +1,18 @@
1
1
  # @vybit/api-sdk
2
2
 
3
- � **PLACEHOLDER PACKAGE** - Full implementation coming in future release.
3
+ Developer API SDK for programmatic access to the Vybit notification platform.
4
4
 
5
5
  ## Overview
6
6
 
7
- This package is currently a placeholder for the Vybit REST API SDK. The full implementation will be available in a future release once the main Vybit application API is finalized.
7
+ The **@vybit/api-sdk** provides a complete TypeScript/JavaScript SDK for the Vybit Developer API, enabling you to build custom integrations, automation workflows, and notification management tools.
8
8
 
9
- ## Current Status
10
-
11
- -  **@vybit/oauth2-sdk** - Fully functional OAuth2 authentication
12
- - **@vybit/api-sdk** - Placeholder (this package)
9
+ Use this SDK to:
10
+ - Manage vybits (notifications) - create, update, delete
11
+ - Handle vybit subscriptions (follows)
12
+ - Search and manage sounds
13
+ - Retrieve notification logs
14
+ - Manage access permissions (peeps)
15
+ - Monitor API usage and metrics
13
16
 
14
17
  ## Installation
15
18
 
@@ -17,57 +20,309 @@ This package is currently a placeholder for the Vybit REST API SDK. The full imp
17
20
  npm install @vybit/api-sdk
18
21
  ```
19
22
 
20
- > **Note**: This package currently only provides placeholder functionality. For authentication, use `@vybit/oauth2-sdk`.
21
-
22
- ## What's Coming
23
+ ## Quick Start
23
24
 
24
- The full API SDK will include:
25
+ ### 1. Get Your API Key
25
26
 
26
- - **Vybit Management**: Create, update, delete vybits
27
- - **Subscription Management**: Handle vybit subscriptions
28
- - **User Profile**: Manage user account settings
29
- - **Analytics**: Access usage statistics and metrics
30
- - **Media Management**: Upload and manage audio files
31
- - **Webhook Management**: Configure webhook endpoints
27
+ 1. Create a [Vybit developer account](https://developer.vybit.net)
28
+ 2. Generate an API key from your developer dashboard
29
+ 3. Store your API key securely (use environment variables)
32
30
 
33
- ## Current Usage (Placeholder)
31
+ ### 2. Initialize the Client
34
32
 
35
33
  ```typescript
36
34
  import { VybitAPIClient } from '@vybit/api-sdk';
37
35
 
38
- // This currently shows a placeholder warning
39
- const client = new VybitAPIClient();
40
- const result = await client.placeholder();
41
- // Returns: { message: 'API SDK implementation coming soon' }
36
+ const client = new VybitAPIClient({
37
+ apiKey: process.env.VYBIT_API_KEY
38
+ });
39
+ ```
40
+
41
+ ### 3. Make API Calls
42
+
43
+ ```typescript
44
+ // Check API status
45
+ const status = await client.getStatus();
46
+ console.log('API Status:', status.status);
47
+
48
+ // Get your profile
49
+ const profile = await client.getProfile();
50
+ console.log('Account:', profile.name, profile.email);
51
+
52
+ // List your vybits
53
+ const vybits = await client.listVybits({ limit: 10 });
54
+ console.log(`You have ${vybits.length} vybits`);
55
+
56
+ // Create a new vybit (only name is required)
57
+ const vybit = await client.createVybit({
58
+ name: 'Server Alert',
59
+ description: 'Notifications for server errors',
60
+ soundKey: 'sound123abc', // Optional - defaults to system sound
61
+ triggerType: 'webhook', // Optional - defaults to 'webhook'
62
+ access: 'private' // Optional - defaults to 'private'
63
+ });
64
+ console.log('Created vybit:', vybit.key);
65
+
66
+ // Search for sounds
67
+ const sounds = await client.searchSounds({ search: 'notification', limit: 5 });
68
+ sounds.forEach(sound => {
69
+ console.log(`${sound.name} - ${sound.key}`);
70
+ });
71
+ ```
72
+
73
+ ## Core Features
74
+
75
+ ### Vybit Management
76
+
77
+ ```typescript
78
+ // List vybits with pagination and search
79
+ const vybits = await client.listVybits({
80
+ offset: 0,
81
+ limit: 20,
82
+ search: 'alert'
83
+ });
84
+
85
+ // Get specific vybit
86
+ const vybit = await client.getVybit('vybit123abc');
87
+
88
+ // Update vybit
89
+ await client.updateVybit('vybit123abc', {
90
+ name: 'Updated Alert Name',
91
+ status: 'on'
92
+ });
93
+
94
+ // Delete vybit
95
+ await client.deleteVybit('vybit123abc');
42
96
  ```
43
97
 
44
- ## Migration Path
98
+ ### Subscription Management
99
+
100
+ ```typescript
101
+ // Browse public vybits
102
+ const publicVybits = await client.listPublicVybits({ limit: 10 });
103
+
104
+ // Subscribe to a vybit
105
+ const follow = await client.createVybitFollow({
106
+ subscriptionKey: 'sub123abc456'
107
+ });
108
+
109
+ // List your subscriptions
110
+ const follows = await client.listVybitFollows();
45
111
 
46
- When the full API SDK is released:
112
+ // Disable a subscription
113
+ await client.updateVybitFollow(follow.followingKey, { status: 'off' });
114
+
115
+ // Unsubscribe
116
+ await client.deleteVybitFollow(follow.followingKey);
117
+ ```
118
+
119
+ ### Sound Search
120
+
121
+ ```typescript
122
+ // Search for sounds
123
+ const sounds = await client.searchSounds({
124
+ search: 'bell',
125
+ limit: 10
126
+ });
47
127
 
48
- 1. Update to the latest version: `npm update @vybit/api-sdk`
49
- 2. Replace placeholder usage with real API methods
50
- 3. No breaking changes to OAuth2 authentication
128
+ // Get sound details
129
+ const sound = await client.getSound('sound123abc');
51
130
 
52
- ## Using OAuth2 SDK Now
131
+ // Get playback URL (unauthenticated endpoint)
132
+ const playUrl = client.getSoundPlayUrl('sound123abc');
133
+ console.log('Play sound at:', playUrl);
134
+ ```
53
135
 
54
- For current projects, use the OAuth2 SDK for authentication:
136
+ ### Notification Logs
55
137
 
56
138
  ```typescript
57
- import { VybitOAuth2Client } from '@vybit/oauth2-sdk';
139
+ // List all logs
140
+ const logs = await client.listLogs({ limit: 50 });
141
+
142
+ // Get specific log
143
+ const log = await client.getLog('log123abc');
58
144
 
59
- const client = new VybitOAuth2Client({
60
- clientId: 'your-client-id',
61
- clientSecret: 'your-client-secret',
62
- redirectUri: 'https://yourapp.com/callback'
145
+ // List logs for a specific vybit
146
+ const vybitLogs = await client.listVybitLogs('vybit123abc', {
147
+ search: 'error',
148
+ limit: 20
63
149
  });
64
150
 
65
- // Full OAuth2 functionality available
66
- const authUrl = client.getAuthorizationUrl();
67
- const token = await client.exchangeCodeForToken(code);
68
- const vybits = await client.getVybitList();
151
+ // List logs for a subscription
152
+ const followLogs = await client.listVybitFollowLogs('follow123abc');
153
+ ```
154
+
155
+ ### Access Control (Peeps)
156
+
157
+ ```typescript
158
+ // Invite someone to a private vybit
159
+ const peep = await client.createPeep({
160
+ vybKey: 'vybit123abc',
161
+ email: 'friend@example.com'
162
+ });
163
+
164
+ // List peeps for a vybit
165
+ const peeps = await client.listVybitPeeps('vybit123abc');
166
+
167
+ // Accept a peep invitation
168
+ await client.acceptPeep('peep123abc');
169
+
170
+ // Remove access
171
+ await client.deletePeep('peep123abc');
69
172
  ```
70
173
 
174
+ ### Monitoring & Metrics
175
+
176
+ ```typescript
177
+ // Get usage metrics
178
+ const meter = await client.getMeter();
179
+ console.log(`Daily usage: ${meter.count_daily} / ${meter.cap_daily}`);
180
+ console.log(`Monthly usage: ${meter.count_monthly} / ${meter.cap_monthly}`);
181
+ console.log(`Tier: ${meter.tier_id} (Free=0, Bronze=1, Silver=2, Gold=3)`);
182
+ ```
183
+
184
+ ## Rate Limiting
185
+
186
+ The Developer API enforces the following rate limits per API key:
187
+ - **10 requests per second**
188
+ - **300 requests per minute**
189
+ - **5,000 requests per hour**
190
+
191
+ Rate limit errors throw a `VybitAPIError` with status code `429`. The SDK automatically includes rate limit information in error messages.
192
+
193
+ ## Error Handling
194
+
195
+ ```typescript
196
+ import { VybitAPIError, VybitAuthError, VybitValidationError } from '@vybit/core';
197
+
198
+ try {
199
+ const vybit = await client.createVybit({
200
+ name: 'Test Vybit' // Only name is required
201
+ });
202
+ } catch (error) {
203
+ if (error instanceof VybitAuthError) {
204
+ console.error('Authentication failed - check your API key');
205
+ } else if (error instanceof VybitValidationError) {
206
+ console.error('Invalid parameters:', error.message);
207
+ } else if (error instanceof VybitAPIError) {
208
+ console.error(`API error (${error.statusCode}):`, error.message);
209
+ } else {
210
+ console.error('Unexpected error:', error);
211
+ }
212
+ }
213
+ ```
214
+
215
+ ## Environment Management
216
+
217
+ The SDK connects to the production Vybit API at `https://api.vybit.net/v1`.
218
+
219
+ For different environments (development, staging, production), create separate Vybit accounts with their own API keys. This provides better isolation and security.
220
+
221
+ ```typescript
222
+ // Development
223
+ const devClient = new VybitAPIClient({
224
+ apiKey: process.env.VYBIT_DEV_API_KEY
225
+ });
226
+
227
+ // Production
228
+ const prodClient = new VybitAPIClient({
229
+ apiKey: process.env.VYBIT_PROD_API_KEY
230
+ });
231
+ ```
232
+
233
+ ## TypeScript Support
234
+
235
+ The SDK is written in TypeScript and includes comprehensive type definitions:
236
+
237
+ ```typescript
238
+ import {
239
+ VybitAPIClient,
240
+ Vybit,
241
+ VybitCreateParams,
242
+ VybitFollow,
243
+ Sound,
244
+ Log,
245
+ Peep,
246
+ SearchParams
247
+ } from '@vybit/api-sdk';
248
+
249
+ // Full type safety for all API operations
250
+ const params: VybitCreateParams = {
251
+ name: 'My Vybit' // Only name is required, all other fields are optional
252
+ };
253
+
254
+ const vybit: Vybit = await client.createVybit(params);
255
+ ```
256
+
257
+ ## API Documentation
258
+
259
+ Complete OpenAPI 3.0 specification available:
260
+ - **📋 Spec**: [docs/openapi/developer-api.yaml](../../docs/openapi/developer-api.yaml)
261
+ - **📖 Interactive Docs**: Open [docs/openapi/index.html](../../docs/openapi/index.html) in browser
262
+
263
+ The OpenAPI spec provides:
264
+ - Complete endpoint documentation with examples
265
+ - Request/response schemas
266
+ - Code generation for multiple languages
267
+ - Postman/Insomnia collection import
268
+
269
+ ## Complete API Reference
270
+
271
+ ### Status & Utility
272
+ - `getStatus()` - Check API health
273
+ - `getMeter()` - Get usage metrics
274
+
275
+ ### Profile
276
+ - `getProfile()` - Get user profile
277
+
278
+ ### Vybits
279
+ - `listVybits(params?)` - List vybits
280
+ - `getVybit(key)` - Get vybit
281
+ - `createVybit(params)` - Create vybit
282
+ - `updateVybit(key, params)` - Update vybit (PUT)
283
+ - `patchVybit(key, params)` - Update vybit (PATCH)
284
+ - `deleteVybit(key)` - Delete vybit
285
+
286
+ ### Subscriptions
287
+ - `listPublicVybits(params?)` - Browse public vybits
288
+ - `getPublicVybit(key)` - Get public vybit by subscription key
289
+
290
+ ### Vybit Follows
291
+ - `listVybitFollows(params?)` - List subscriptions
292
+ - `getVybitFollow(key)` - Get subscription
293
+ - `createVybitFollow(params)` - Subscribe to vybit
294
+ - `updateVybitFollow(key, params)` - Update subscription
295
+ - `deleteVybitFollow(key)` - Unsubscribe
296
+
297
+ ### Sounds
298
+ - `searchSounds(params?)` - Search sounds
299
+ - `getSound(key)` - Get sound details
300
+ - `getSoundPlayUrl(key)` - Get sound playback URL
301
+
302
+ ### Logs
303
+ - `listLogs(params?)` - List all logs
304
+ - `getLog(logKey)` - Get log entry
305
+ - `listVybitLogs(vybKey, params?)` - List logs for vybit
306
+ - `listVybitFollowLogs(vybFollowKey, params?)` - List logs for subscription
307
+
308
+ ### Peeps
309
+ - `listPeeps(params?)` - List peeps
310
+ - `getPeep(key)` - Get peep
311
+ - `createPeep(params)` - Create peep invitation
312
+ - `acceptPeep(key)` - Accept invitation
313
+ - `deletePeep(key)` - Remove peep
314
+
315
+ ### Vybit Peeps (Nested)
316
+ - `listVybitPeeps(vybKey)` - List peeps for vybit
317
+ - `createVybitPeep(vybKey, params)` - Add peep to vybit
318
+ - `updateVybitPeep(vybKey, key, params)` - Update vybit peep
319
+ - `deleteVybitPeep(vybKey, key)` - Remove peep from vybit
320
+
321
+ ## Related Packages
322
+
323
+ - **[@vybit/oauth2-sdk](../oauth2)** - OAuth 2.0 authentication for user-facing apps
324
+ - **[@vybit/core](../core)** - Shared utilities and types
325
+
71
326
  ## License
72
327
 
73
- MIT
328
+ MIT
@@ -0,0 +1,8 @@
1
+ /**
2
+ * API Client Unit Tests
3
+ *
4
+ * Tests VybitAPIClient methods with mocked fetch.
5
+ * These tests run in CI without requiring an API key.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=api-client.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/api-client.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}