@licensechain/nodejs-sdk 1.0.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 +21 -0
- package/README.md +500 -0
- package/dist/api-client.d.ts +13 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +52 -0
- package/dist/api-client.js.map +1 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +60 -0
- package/dist/client.js.map +1 -0
- package/dist/configuration.d.ts +26 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +63 -0
- package/dist/configuration.js.map +1 -0
- package/dist/exceptions.d.ts +46 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +105 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/http-core.d.ts +36 -0
- package/dist/http-core.d.ts.map +1 -0
- package/dist/http-core.js +119 -0
- package/dist/http-core.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/license-assertion.d.ts +15 -0
- package/dist/license-assertion.d.ts.map +1 -0
- package/dist/license-assertion.js +59 -0
- package/dist/license-assertion.js.map +1 -0
- package/dist/license-validator.d.ts +53 -0
- package/dist/license-validator.d.ts.map +1 -0
- package/dist/license-validator.js +208 -0
- package/dist/license-validator.js.map +1 -0
- package/dist/services/license-service.d.ts +55 -0
- package/dist/services/license-service.d.ts.map +1 -0
- package/dist/services/license-service.js +85 -0
- package/dist/services/license-service.js.map +1 -0
- package/dist/services/product-service.d.ts +48 -0
- package/dist/services/product-service.d.ts.map +1 -0
- package/dist/services/product-service.js +53 -0
- package/dist/services/product-service.js.map +1 -0
- package/dist/services/user-service.d.ts +43 -0
- package/dist/services/user-service.d.ts.map +1 -0
- package/dist/services/user-service.js +58 -0
- package/dist/services/user-service.js.map +1 -0
- package/dist/services/webhook-service.d.ts +37 -0
- package/dist/services/webhook-service.d.ts.map +1 -0
- package/dist/services/webhook-service.js +57 -0
- package/dist/services/webhook-service.js.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +54 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +396 -0
- package/dist/utils.js.map +1 -0
- package/dist/webhook-handler.d.ts +40 -0
- package/dist/webhook-handler.d.ts.map +1 -0
- package/dist/webhook-handler.js +160 -0
- package/dist/webhook-handler.js.map +1 -0
- package/dist/webhook-verifier.d.ts +41 -0
- package/dist/webhook-verifier.d.ts.map +1 -0
- package/dist/webhook-verifier.js +153 -0
- package/dist/webhook-verifier.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LicenseChain LLC
|
|
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
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
# LicenseChain Node.js SDK
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://nodejs.org/)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://www.npmjs.com/package/licensechain-sdk)
|
|
7
|
+
|
|
8
|
+
Official Node.js SDK for LicenseChain - Secure license management for Node.js applications.
|
|
9
|
+
|
|
10
|
+
> Note: Prefer **LicenseChain-JavaScript-SDK** for browser/isomorphic runtimes; this package is the Node.js server-oriented SDK. See [docs.licensechain.app](https://docs.licensechain.app/).
|
|
11
|
+
## API Base
|
|
12
|
+
|
|
13
|
+
- Canonical API base: `https://api.licensechain.app/v1`
|
|
14
|
+
- API docs: [docs.licensechain.app](https://docs.licensechain.app/)
|
|
15
|
+
## 🚀 Features
|
|
16
|
+
|
|
17
|
+
- **🔐 Secure Authentication** - User registration, login, and session management
|
|
18
|
+
- **📜 License Management** - Create, validate, update, and revoke licenses
|
|
19
|
+
- **🛡️ Hardware ID Validation** - Prevent license sharing and unauthorized access
|
|
20
|
+
- **🔔 Webhook Support** - Real-time license events and notifications
|
|
21
|
+
- **📊 Analytics Integration** - Track license usage and performance metrics
|
|
22
|
+
- **⚡ High Performance** - Optimized for production workloads
|
|
23
|
+
- **🔄 Async Operations** - Non-blocking HTTP requests and data processing
|
|
24
|
+
- **🛠️ Easy Integration** - Simple API with comprehensive documentation
|
|
25
|
+
|
|
26
|
+
## 📦 Installation
|
|
27
|
+
|
|
28
|
+
### Method 1: npm (Recommended)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Install via npm
|
|
32
|
+
npm install licensechain-sdk
|
|
33
|
+
|
|
34
|
+
# Or via yarn
|
|
35
|
+
yarn add licensechain-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Method 2: pnpm
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Install via pnpm
|
|
42
|
+
pnpm add licensechain-sdk
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Method 3: Manual Installation
|
|
46
|
+
|
|
47
|
+
1. Download the latest release from [GitHub Releases](https://github.com/LicenseChain/LicenseChain-NodeJS-SDK/releases)
|
|
48
|
+
2. Extract to your project directory
|
|
49
|
+
3. Install dependencies
|
|
50
|
+
|
|
51
|
+
## 🚀 Quick Start
|
|
52
|
+
|
|
53
|
+
### Basic Setup
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import LicenseChain from 'licensechain-sdk';
|
|
57
|
+
|
|
58
|
+
// Initialize the client
|
|
59
|
+
const client = new LicenseChain({
|
|
60
|
+
apiKey: 'your-api-key',
|
|
61
|
+
appName: 'your-app-name',
|
|
62
|
+
version: '1.0.0',
|
|
63
|
+
baseUrl: 'https://api.licensechain.app/v1'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Connect to LicenseChain
|
|
67
|
+
try {
|
|
68
|
+
await client.connect();
|
|
69
|
+
console.log('Connected to LicenseChain successfully!');
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Failed to connect:', error.message);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### User Authentication
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// Register a new user
|
|
79
|
+
try {
|
|
80
|
+
const user = await client.register('username', 'password', 'email@example.com');
|
|
81
|
+
console.log('User registered successfully!');
|
|
82
|
+
console.log('User ID:', user.id);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('Registration failed:', error.message);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Login existing user
|
|
88
|
+
try {
|
|
89
|
+
const user = await client.login('username', 'password');
|
|
90
|
+
console.log('User logged in successfully!');
|
|
91
|
+
console.log('Session ID:', user.sessionId);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Login failed:', error.message);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### License Management
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// Validate a license
|
|
101
|
+
try {
|
|
102
|
+
const license = await client.validateLicense('LICENSE-KEY-HERE');
|
|
103
|
+
console.log('License is valid!');
|
|
104
|
+
console.log('License Key:', license.key);
|
|
105
|
+
console.log('Status:', license.status);
|
|
106
|
+
console.log('Expires:', license.expires);
|
|
107
|
+
console.log('Features:', license.features.join(', '));
|
|
108
|
+
console.log('User:', license.user);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error('License validation failed:', error.message);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get user's licenses
|
|
114
|
+
try {
|
|
115
|
+
const licenses = await client.getUserLicenses();
|
|
116
|
+
console.log(`Found ${licenses.length} licenses:`);
|
|
117
|
+
licenses.forEach((license, index) => {
|
|
118
|
+
console.log(` ${index + 1}. ${license.key} - ${license.status} (Expires: ${license.expires})`);
|
|
119
|
+
});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('Failed to get licenses:', error.message);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Hardware ID Validation
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Get hardware ID (automatically generated)
|
|
129
|
+
const hardwareId = client.getHardwareId();
|
|
130
|
+
console.log('Hardware ID:', hardwareId);
|
|
131
|
+
|
|
132
|
+
// Validate hardware ID with license
|
|
133
|
+
try {
|
|
134
|
+
const isValid = await client.validateHardwareId('LICENSE-KEY-HERE', hardwareId);
|
|
135
|
+
if (isValid) {
|
|
136
|
+
console.log('Hardware ID is valid for this license!');
|
|
137
|
+
} else {
|
|
138
|
+
console.log('Hardware ID is not valid for this license.');
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error('Hardware ID validation failed:', error.message);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Webhook Integration
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
// Set up webhook handler
|
|
149
|
+
client.setWebhookHandler((event, data) => {
|
|
150
|
+
console.log('Webhook received:', event);
|
|
151
|
+
|
|
152
|
+
switch (event) {
|
|
153
|
+
case 'license.created':
|
|
154
|
+
console.log('New license created:', data.licenseKey);
|
|
155
|
+
break;
|
|
156
|
+
case 'license.updated':
|
|
157
|
+
console.log('License updated:', data.licenseKey);
|
|
158
|
+
break;
|
|
159
|
+
case 'license.revoked':
|
|
160
|
+
console.log('License revoked:', data.licenseKey);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Start webhook listener
|
|
166
|
+
await client.startWebhookListener();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 📚 API Endpoints
|
|
170
|
+
|
|
171
|
+
All endpoints target the LicenseChain HTTP API at `https://api.licensechain.app/v1`. The client accepts either the canonical `/v1` base or the root host and normalizes requests to the same API version.
|
|
172
|
+
|
|
173
|
+
### Base URL
|
|
174
|
+
- **Production**: `https://api.licensechain.app/v1`
|
|
175
|
+
- **Development**: `https://api.licensechain.app/v1`
|
|
176
|
+
|
|
177
|
+
### Available Endpoints
|
|
178
|
+
|
|
179
|
+
| Method | Endpoint | Description |
|
|
180
|
+
|--------|----------|-------------|
|
|
181
|
+
| `GET` | `/v1/health` | Health check |
|
|
182
|
+
| `POST` | `/v1/auth/login` | User login |
|
|
183
|
+
| `POST` | `/v1/auth/register` | User registration |
|
|
184
|
+
| `GET` | `/v1/apps` | List applications |
|
|
185
|
+
| `POST` | `/v1/apps` | Create application |
|
|
186
|
+
| `GET` | `/v1/licenses` | List licenses |
|
|
187
|
+
| `POST` | `/v1/licenses/verify` | Verify license |
|
|
188
|
+
| `GET` | `/v1/webhooks` | List webhooks |
|
|
189
|
+
| `POST` | `/v1/webhooks` | Create webhook |
|
|
190
|
+
| `GET` | `/v1/analytics` | Get analytics |
|
|
191
|
+
|
|
192
|
+
**Note**: The SDK automatically prepends `/v1` to all endpoints, so you only need to specify the path (e.g., `/auth/login` instead of `/v1/auth/login`).
|
|
193
|
+
|
|
194
|
+
## 📚 API Reference
|
|
195
|
+
|
|
196
|
+
### LicenseChain Client
|
|
197
|
+
|
|
198
|
+
#### Constructor
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const client = new LicenseChain({
|
|
202
|
+
apiKey: 'your-api-key',
|
|
203
|
+
appName: 'your-app-name',
|
|
204
|
+
version: '1.0.0',
|
|
205
|
+
baseUrl: 'https://api.licensechain.app/v1' // Optional
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### Methods
|
|
210
|
+
|
|
211
|
+
##### Connection Management
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// Connect to LicenseChain
|
|
215
|
+
await client.connect();
|
|
216
|
+
|
|
217
|
+
// Disconnect from LicenseChain
|
|
218
|
+
await client.disconnect();
|
|
219
|
+
|
|
220
|
+
// Check connection status
|
|
221
|
+
const isConnected = client.isConnected();
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
##### User Authentication
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
// Register a new user
|
|
228
|
+
const user = await client.register(username, password, email);
|
|
229
|
+
|
|
230
|
+
// Login existing user
|
|
231
|
+
const user = await client.login(username, password);
|
|
232
|
+
|
|
233
|
+
// Logout current user
|
|
234
|
+
await client.logout();
|
|
235
|
+
|
|
236
|
+
// Get current user info
|
|
237
|
+
const user = await client.getCurrentUser();
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
##### License Management
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
// Validate a license
|
|
244
|
+
const license = await client.validateLicense(licenseKey);
|
|
245
|
+
|
|
246
|
+
// Get user's licenses
|
|
247
|
+
const licenses = await client.getUserLicenses();
|
|
248
|
+
|
|
249
|
+
// Create a new license
|
|
250
|
+
const license = await client.createLicense(userId, features, expires);
|
|
251
|
+
|
|
252
|
+
// Update a license
|
|
253
|
+
const license = await client.updateLicense(licenseKey, updates);
|
|
254
|
+
|
|
255
|
+
// Revoke a license
|
|
256
|
+
await client.revokeLicense(licenseKey);
|
|
257
|
+
|
|
258
|
+
// Extend a license
|
|
259
|
+
const license = await client.extendLicense(licenseKey, days);
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
##### Hardware ID Management
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
// Get hardware ID
|
|
266
|
+
const hardwareId = client.getHardwareId();
|
|
267
|
+
|
|
268
|
+
// Validate hardware ID
|
|
269
|
+
const isValid = await client.validateHardwareId(licenseKey, hardwareId);
|
|
270
|
+
|
|
271
|
+
// Bind hardware ID to license
|
|
272
|
+
await client.bindHardwareId(licenseKey, hardwareId);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
##### Webhook Management
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
// Set webhook handler
|
|
279
|
+
client.setWebhookHandler(handler);
|
|
280
|
+
|
|
281
|
+
// Start webhook listener
|
|
282
|
+
await client.startWebhookListener();
|
|
283
|
+
|
|
284
|
+
// Stop webhook listener
|
|
285
|
+
await client.stopWebhookListener();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
##### Analytics
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
// Track event
|
|
292
|
+
await client.trackEvent(eventName, properties);
|
|
293
|
+
|
|
294
|
+
// Get analytics data
|
|
295
|
+
const analytics = await client.getAnalytics(timeRange);
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## 🔧 Configuration
|
|
299
|
+
|
|
300
|
+
### Environment Variables
|
|
301
|
+
|
|
302
|
+
Set these in your environment or through your build process:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
# Required
|
|
306
|
+
export LICENSECHAIN_API_KEY=your-api-key
|
|
307
|
+
export LICENSECHAIN_APP_NAME=your-app-name
|
|
308
|
+
export LICENSECHAIN_APP_VERSION=1.0.0
|
|
309
|
+
|
|
310
|
+
# Optional
|
|
311
|
+
export LICENSECHAIN_BASE_URL=https://api.licensechain.app/v1
|
|
312
|
+
export LICENSECHAIN_DEBUG=true
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Advanced Configuration
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
const client = new LicenseChain({
|
|
319
|
+
apiKey: 'your-api-key',
|
|
320
|
+
appName: 'your-app-name',
|
|
321
|
+
version: '1.0.0',
|
|
322
|
+
baseUrl: 'https://api.licensechain.app/v1',
|
|
323
|
+
timeout: 30000, // Request timeout in milliseconds
|
|
324
|
+
retries: 3, // Number of retry attempts
|
|
325
|
+
debug: false, // Enable debug logging
|
|
326
|
+
userAgent: 'MyApp/1.0.0' // Custom user agent
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## 🛡️ Security Features
|
|
331
|
+
|
|
332
|
+
### Hardware ID Protection
|
|
333
|
+
|
|
334
|
+
The SDK automatically generates and manages hardware IDs to prevent license sharing:
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
// Hardware ID is automatically generated and stored
|
|
338
|
+
const hardwareId = client.getHardwareId();
|
|
339
|
+
|
|
340
|
+
// Validate against license
|
|
341
|
+
const isValid = await client.validateHardwareId(licenseKey, hardwareId);
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Secure Communication
|
|
345
|
+
|
|
346
|
+
- All API requests use HTTPS
|
|
347
|
+
- API keys are securely stored and transmitted
|
|
348
|
+
- Session tokens are automatically managed
|
|
349
|
+
- Webhook signatures are verified
|
|
350
|
+
|
|
351
|
+
### License Validation
|
|
352
|
+
|
|
353
|
+
- Real-time license validation
|
|
354
|
+
- Hardware ID binding
|
|
355
|
+
- Expiration checking
|
|
356
|
+
- Feature-based access control
|
|
357
|
+
|
|
358
|
+
## 📊 Analytics and Monitoring
|
|
359
|
+
|
|
360
|
+
### Event Tracking
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
// Track custom events
|
|
364
|
+
await client.trackEvent('app.started', {
|
|
365
|
+
level: 1,
|
|
366
|
+
playerCount: 10
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Track license events
|
|
370
|
+
await client.trackEvent('license.validated', {
|
|
371
|
+
licenseKey: 'LICENSE-KEY',
|
|
372
|
+
features: 'premium,unlimited'
|
|
373
|
+
});
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Performance Monitoring
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
// Get performance metrics
|
|
380
|
+
const metrics = await client.getPerformanceMetrics();
|
|
381
|
+
console.log('API Response Time:', metrics.averageResponseTime + 'ms');
|
|
382
|
+
console.log('Success Rate:', (metrics.successRate * 100).toFixed(2) + '%');
|
|
383
|
+
console.log('Error Count:', metrics.errorCount);
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
## 🔄 Error Handling
|
|
387
|
+
|
|
388
|
+
### Custom Error Types
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
try {
|
|
392
|
+
const license = await client.validateLicense('invalid-key');
|
|
393
|
+
} catch (error) {
|
|
394
|
+
if (error instanceof LicenseChainError) {
|
|
395
|
+
switch (error.type) {
|
|
396
|
+
case 'INVALID_LICENSE':
|
|
397
|
+
console.error('License key is invalid');
|
|
398
|
+
break;
|
|
399
|
+
case 'EXPIRED_LICENSE':
|
|
400
|
+
console.error('License has expired');
|
|
401
|
+
break;
|
|
402
|
+
case 'NETWORK_ERROR':
|
|
403
|
+
console.error('Network connection failed');
|
|
404
|
+
break;
|
|
405
|
+
default:
|
|
406
|
+
console.error('LicenseChain error:', error.message);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Retry Logic
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
// Automatic retry for network errors
|
|
416
|
+
const client = new LicenseChain({
|
|
417
|
+
apiKey: 'your-api-key',
|
|
418
|
+
appName: 'your-app-name',
|
|
419
|
+
version: '1.0.0',
|
|
420
|
+
retries: 3, // Retry up to 3 times
|
|
421
|
+
timeout: 30000 // Wait 30 seconds for each request
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## 🧪 Testing
|
|
426
|
+
|
|
427
|
+
### Unit Tests
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
# Run tests
|
|
431
|
+
npm test
|
|
432
|
+
|
|
433
|
+
# Run tests with coverage
|
|
434
|
+
npm run test:coverage
|
|
435
|
+
|
|
436
|
+
# Run tests in watch mode
|
|
437
|
+
npm run test:watch
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Integration Tests
|
|
441
|
+
|
|
442
|
+
```bash
|
|
443
|
+
# Test with real API
|
|
444
|
+
npm run test:integration
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
## 📝 Examples
|
|
448
|
+
|
|
449
|
+
See the `examples/` directory for complete examples:
|
|
450
|
+
|
|
451
|
+
- `basic-usage.js` - Basic SDK usage
|
|
452
|
+
- `advanced-features.js` - Advanced features and configuration
|
|
453
|
+
- `webhook-integration.js` - Webhook handling
|
|
454
|
+
|
|
455
|
+
## 🤝 Contributing
|
|
456
|
+
|
|
457
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
458
|
+
|
|
459
|
+
### Development Setup
|
|
460
|
+
|
|
461
|
+
1. Clone the repository
|
|
462
|
+
2. Install Node.js 16 or later
|
|
463
|
+
3. Install dependencies: `npm install`
|
|
464
|
+
4. Build: `npm run build`
|
|
465
|
+
5. Test: `npm test`
|
|
466
|
+
|
|
467
|
+
## 📄 License
|
|
468
|
+
|
|
469
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
470
|
+
|
|
471
|
+
## 🆘 Support
|
|
472
|
+
|
|
473
|
+
- **Documentation**: [https://docs.licensechain.app/sdks/nodejs](https://docs.licensechain.app/sdks/nodejs)
|
|
474
|
+
- **Issues**: [GitHub Issues](https://github.com/LicenseChain/LicenseChain-NodeJS-SDK/issues)
|
|
475
|
+
- **Discord**: [LicenseChain Discord](https://discord.gg/licensechain)
|
|
476
|
+
- **Email**: support@licensechain.app
|
|
477
|
+
|
|
478
|
+
## 🔗 Related Projects
|
|
479
|
+
|
|
480
|
+
- [LicenseChain JavaScript SDK](https://github.com/LicenseChain/LicenseChain-JavaScript-SDK)
|
|
481
|
+
- [LicenseChain Python SDK](https://github.com/LicenseChain/LicenseChain-Python-SDK)
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
**Made with ❤️ for the Node.js community**
|
|
485
|
+
|
|
486
|
+
## LicenseChain API (v1)
|
|
487
|
+
|
|
488
|
+
This SDK targets the **LicenseChain HTTP API v1** implemented by the LicenseChain API service.
|
|
489
|
+
|
|
490
|
+
- **Production base URL:** https://api.licensechain.app/v1
|
|
491
|
+
- **API reference:** [docs.licensechain.app](https://docs.licensechain.app/)
|
|
492
|
+
- **Baseline REST mapping (documented for integrators):**
|
|
493
|
+
- GET /health
|
|
494
|
+
- POST /auth/register
|
|
495
|
+
- POST /licenses/verify
|
|
496
|
+
- PATCH /licenses/:id/revoke
|
|
497
|
+
- PATCH /licenses/:id/activate
|
|
498
|
+
- PATCH /licenses/:id/extend
|
|
499
|
+
- GET /analytics/stats
|
|
500
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Configuration } from './configuration';
|
|
2
|
+
export declare class ApiClient {
|
|
3
|
+
private readonly core;
|
|
4
|
+
constructor(config: Configuration);
|
|
5
|
+
get<T = any>(endpoint: string, params?: Record<string, any>): Promise<T>;
|
|
6
|
+
post<T = any>(endpoint: string, data?: any): Promise<T>;
|
|
7
|
+
put<T = any>(endpoint: string, data?: any): Promise<T>;
|
|
8
|
+
patch<T = any>(endpoint: string, data?: any): Promise<T>;
|
|
9
|
+
delete<T = any>(endpoint: string, data?: any): Promise<T>;
|
|
10
|
+
ping(): Promise<any>;
|
|
11
|
+
health(): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;gBAEhC,MAAM,EAAE,aAAa;IAsB3B,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIxE,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIvD,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAItD,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIxD,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzD,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAIpB,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;CAG7B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiClient = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const exceptions_1 = require("./exceptions");
|
|
6
|
+
const http_core_1 = require("./http-core");
|
|
7
|
+
class ApiClient {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.core = new http_core_1.LicenseChainHttpCore({
|
|
10
|
+
apiKey: config.getApiKey(),
|
|
11
|
+
baseUrl: config.getBaseUrl(),
|
|
12
|
+
deserialize: utils_1.jsonDeserialize,
|
|
13
|
+
exceptions: {
|
|
14
|
+
authentication: (message) => new exceptions_1.AuthenticationException(message),
|
|
15
|
+
network: (message) => new exceptions_1.NetworkException(message),
|
|
16
|
+
notFound: (message) => new exceptions_1.NotFoundException(message),
|
|
17
|
+
rateLimit: (message) => new exceptions_1.RateLimitException(message),
|
|
18
|
+
server: (message) => new exceptions_1.ServerException(message),
|
|
19
|
+
validation: (message) => new exceptions_1.ValidationException(message),
|
|
20
|
+
},
|
|
21
|
+
platform: 'nodejs-sdk',
|
|
22
|
+
retries: config.getRetries(),
|
|
23
|
+
retryWithBackoff: utils_1.retryWithBackoff,
|
|
24
|
+
serialize: utils_1.jsonSerialize,
|
|
25
|
+
timeout: config.getTimeout(),
|
|
26
|
+
userAgent: 'LicenseChain-NodeJS-SDK/1.0.0',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async get(endpoint, params) {
|
|
30
|
+
return this.core.get(endpoint, params);
|
|
31
|
+
}
|
|
32
|
+
async post(endpoint, data) {
|
|
33
|
+
return this.core.post(endpoint, data);
|
|
34
|
+
}
|
|
35
|
+
async put(endpoint, data) {
|
|
36
|
+
return this.core.put(endpoint, data);
|
|
37
|
+
}
|
|
38
|
+
async patch(endpoint, data) {
|
|
39
|
+
return this.core.patch(endpoint, data);
|
|
40
|
+
}
|
|
41
|
+
async delete(endpoint, data) {
|
|
42
|
+
return this.core.delete(endpoint, data);
|
|
43
|
+
}
|
|
44
|
+
async ping() {
|
|
45
|
+
return this.get('/health');
|
|
46
|
+
}
|
|
47
|
+
async health() {
|
|
48
|
+
return this.get('/health');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ApiClient = ApiClient;
|
|
52
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":";;;AACA,mCAA2E;AAC3E,6CAOsB;AACtB,2CAAmD;AAEnD,MAAa,SAAS;IAGpB,YAAY,MAAqB;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,gCAAoB,CAAC;YACnC,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE;YAC1B,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE;YAC5B,WAAW,EAAE,uBAAe;YAC5B,UAAU,EAAE;gBACV,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,oCAAuB,CAAC,OAAO,CAAC;gBACjE,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,6BAAgB,CAAC,OAAO,CAAC;gBACnD,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,8BAAiB,CAAC,OAAO,CAAC;gBACrD,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,+BAAkB,CAAC,OAAO,CAAC;gBACvD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,4BAAe,CAAC,OAAO,CAAC;gBACjD,UAAU,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,gCAAmB,CAAC,OAAO,CAAC;aAC1D;YACD,QAAQ,EAAE,YAAY;YACtB,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE;YAC5B,gBAAgB,EAAhB,wBAAgB;YAChB,SAAS,EAAE,qBAAa;YACxB,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE;YAC5B,SAAS,EAAE,+BAA+B;SAC3C,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG,CAAU,QAAgB,EAAE,MAA4B;QAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAI,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,IAAI,CAAU,QAAgB,EAAE,IAAU;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,GAAG,CAAU,QAAgB,EAAE,IAAU;QAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,KAAK,CAAU,QAAgB,EAAE,IAAU;QAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CAAU,QAAgB,EAAE,IAAU;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;CACF;AApDD,8BAoDC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Configuration, ConfigurationOptions } from './configuration';
|
|
2
|
+
import { LicenseService } from './services/license-service';
|
|
3
|
+
import { UserService } from './services/user-service';
|
|
4
|
+
import { ProductService } from './services/product-service';
|
|
5
|
+
import { WebhookService } from './services/webhook-service';
|
|
6
|
+
export declare class LicenseChainClient {
|
|
7
|
+
private config;
|
|
8
|
+
private apiClient;
|
|
9
|
+
private licenses;
|
|
10
|
+
private users;
|
|
11
|
+
private products;
|
|
12
|
+
private webhooks;
|
|
13
|
+
constructor(config: Configuration | ConfigurationOptions);
|
|
14
|
+
getConfiguration(): Configuration;
|
|
15
|
+
getLicenses(): LicenseService;
|
|
16
|
+
getUsers(): UserService;
|
|
17
|
+
getProducts(): ProductService;
|
|
18
|
+
getWebhooks(): WebhookService;
|
|
19
|
+
ping(): Promise<any>;
|
|
20
|
+
health(): Promise<any>;
|
|
21
|
+
static create(apiKey: string, baseUrl?: string): LicenseChainClient;
|
|
22
|
+
static fromEnvironment(): LicenseChainClient;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,QAAQ,CAAiB;gBAErB,MAAM,EAAE,aAAa,GAAG,oBAAoB;IAkBxD,gBAAgB,IAAI,aAAa;IAIjC,WAAW,IAAI,cAAc;IAI7B,QAAQ,IAAI,WAAW;IAIvB,WAAW,IAAI,cAAc;IAI7B,WAAW,IAAI,cAAc;IAIvB,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAIpB,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;IAI5B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,kBAAkB;IAOnE,MAAM,CAAC,eAAe,IAAI,kBAAkB;CAG7C"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LicenseChainClient = void 0;
|
|
4
|
+
const configuration_1 = require("./configuration");
|
|
5
|
+
const api_client_1 = require("./api-client");
|
|
6
|
+
const license_service_1 = require("./services/license-service");
|
|
7
|
+
const user_service_1 = require("./services/user-service");
|
|
8
|
+
const product_service_1 = require("./services/product-service");
|
|
9
|
+
const webhook_service_1 = require("./services/webhook-service");
|
|
10
|
+
const exceptions_1 = require("./exceptions");
|
|
11
|
+
class LicenseChainClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
if (config instanceof configuration_1.Configuration) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.config = new configuration_1.Configuration(config);
|
|
18
|
+
}
|
|
19
|
+
if (!this.config.isValid()) {
|
|
20
|
+
throw new exceptions_1.ConfigurationException('API key is required');
|
|
21
|
+
}
|
|
22
|
+
this.apiClient = new api_client_1.ApiClient(this.config);
|
|
23
|
+
this.licenses = new license_service_1.LicenseService(this.apiClient);
|
|
24
|
+
this.users = new user_service_1.UserService(this.apiClient);
|
|
25
|
+
this.products = new product_service_1.ProductService(this.apiClient);
|
|
26
|
+
this.webhooks = new webhook_service_1.WebhookService(this.apiClient);
|
|
27
|
+
}
|
|
28
|
+
getConfiguration() {
|
|
29
|
+
return this.config;
|
|
30
|
+
}
|
|
31
|
+
getLicenses() {
|
|
32
|
+
return this.licenses;
|
|
33
|
+
}
|
|
34
|
+
getUsers() {
|
|
35
|
+
return this.users;
|
|
36
|
+
}
|
|
37
|
+
getProducts() {
|
|
38
|
+
return this.products;
|
|
39
|
+
}
|
|
40
|
+
getWebhooks() {
|
|
41
|
+
return this.webhooks;
|
|
42
|
+
}
|
|
43
|
+
async ping() {
|
|
44
|
+
return this.apiClient.ping();
|
|
45
|
+
}
|
|
46
|
+
async health() {
|
|
47
|
+
return this.apiClient.health();
|
|
48
|
+
}
|
|
49
|
+
static create(apiKey, baseUrl) {
|
|
50
|
+
return new LicenseChainClient({
|
|
51
|
+
apiKey,
|
|
52
|
+
baseUrl: baseUrl || 'https://api.licensechain.app/v1'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
static fromEnvironment() {
|
|
56
|
+
return new LicenseChainClient(configuration_1.Configuration.fromEnvironment());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.LicenseChainClient = LicenseChainClient;
|
|
60
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,mDAAsE;AACtE,6CAAyC;AACzC,gEAA4D;AAC5D,0DAAsD;AACtD,gEAA4D;AAC5D,gEAA4D;AAC5D,6CAAsD;AAEtD,MAAa,kBAAkB;IAQ7B,YAAY,MAA4C;QACtD,IAAI,MAAM,YAAY,6BAAa,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,mCAAsB,CAAC,qBAAqB,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,KAAK,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,OAAgB;QAC5C,OAAO,IAAI,kBAAkB,CAAC;YAC5B,MAAM;YACN,OAAO,EAAE,OAAO,IAAI,iCAAiC;SACtD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,kBAAkB,CAAC,6BAAa,CAAC,eAAe,EAAE,CAAC,CAAC;IACjE,CAAC;CACF;AAhED,gDAgEC"}
|