didox 0.0.6 → 1.0.2

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,70 +1,407 @@
1
- # didox
1
+ # Didox SDK for Node.js
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/didox.svg)](https://badge.fury.io/js/didox)
4
- [![The Beta Company](https://img.shields.io/badge/powered%20by-The%20Beta%20Company-blue)](https://thebetacompany.uz/projects/didox-npm-module)
5
- ---
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-green.svg)](https://nodejs.org)
6
6
 
7
- **didox** is a Node.js module developed to streamline the integration process for developers and their applications with the Electronic Document Management System (EDM) on the [www.didox.uz](https://didox.uz) platform. With this module, you can simplify interactions with Didox, send and receive electronic documents, manage your account, and more.
7
+ A TypeScript SDK for integrating with **Didox**, an electronic document management (EDO) platform in Uzbekistan that enables legally significant exchange of electronic documents between companies.
8
8
 
9
- ## Installation
9
+ ## What is Didox?
10
+
11
+ Didox is an electronic document management platform in the Republic of Uzbekistan that facilitates legally significant electronic document exchange between companies. It provides:
10
12
 
11
- To install the **didox** module, use the following npm command:
13
+ - Secure electronic document signing
14
+ - Legal compliance with Uzbekistan EDO regulations
15
+ - Company-to-company document workflows
16
+ - Digital signature verification
17
+
18
+ ## Installation
12
19
 
13
- ### NPM
14
20
  ```bash
15
21
  npm install didox
16
22
  ```
17
23
 
18
- ### Yarn
19
24
  ```bash
20
25
  yarn add didox
21
26
  ```
22
27
 
23
- ## Environment Variables
28
+ ```bash
29
+ pnpm add didox
30
+ ```
24
31
 
25
- Before using the didox module, make sure to set the following environment variables in your project's .env file:
32
+ ## Quick Start
26
33
 
27
- `TBC_DIDOX_LOGIN`: Your didox login or username.
34
+ ### 1. Initialize the Client
28
35
 
29
- `TBC_DIDOX_PASSWORD`: Your didox password or API key secret.
36
+ ```typescript
37
+ import { DidoxClient } from 'didox';
30
38
 
31
- `TBC_DIDOX_PARTNER_TOKEN`: Your didox partner token ( given by didox.uz ).
39
+ const didox = new DidoxClient({
40
+ partnerToken: 'your-partner-token',
41
+ environment: 'development', // or 'production'
42
+ timeout: 10000 // optional, defaults to 10 seconds
43
+ });
44
+ ```
32
45
 
33
- These environment variables are required for authentication when using the module. Be sure to keep them secure and do not expose them in your code.
46
+ ### 2. Legal Entity Authentication
34
47
 
35
- ## Usage
48
+ ```typescript
49
+ try {
50
+ const result = await didox.auth.loginLegalEntity({
51
+ taxId: '123456789', // exactly 9 digits
52
+ password: 'yourPassword', // minimum 8 characters
53
+ locale: 'ru' // 'ru' or 'uz', defaults to 'ru'
54
+ });
55
+
56
+ console.log('Access token:', result.token);
57
+ console.log('Related companies:', result.related_companies);
58
+
59
+ // Token is automatically stored in the client for subsequent requests
60
+ } catch (error) {
61
+ console.error('Login failed:', error.message);
62
+ }
63
+ ```
36
64
 
37
- ```javascript
38
- const { Account } = require('didox');
65
+ ### 3. Individual to Company Login
39
66
 
40
- async function getAccountInfo ( ) {
41
- const accountInfo = await Account.getInfo();
42
- // Here is your code...
67
+ ```typescript
68
+ try {
69
+ const result = await didox.auth.loginCompanyAsIndividual({
70
+ companyTaxId: '987654321',
71
+ userToken: 'individual-user-token', // from previous login
72
+ locale: 'uz'
73
+ });
74
+
75
+ console.log('Company access token:', result.token);
76
+ console.log('User permissions:', result.permissions);
77
+ } catch (error) {
78
+ console.error('Company login failed:', error.message);
43
79
  }
44
- // Here is your code...
45
80
  ```
46
81
 
47
- ## Documentation
48
- For detailed usage instructions and API documentation, please refer to the [documentation](https://docs.thebetacompany.uz/tbc-didox-npm).
82
+ ## Configuration
83
+
84
+ ### Partner Token
85
+
86
+ The Partner Token is required to authorize API requests. To obtain a Partner Token:
87
+
88
+ 1. Contact a Didox representative
89
+ 2. Provide your company information and use case
90
+ 3. Receive your unique Partner Token for API access
91
+
92
+ ### Environment URLs
93
+
94
+ - **Development**: `https://stage.goodsign.biz/`
95
+ - **Production**: `https://api-partners.didox.uz/`
96
+
97
+ ### Client Options
98
+
99
+ ```typescript
100
+ interface DidoxConfig {
101
+ partnerToken: string; // Required: Your Partner Token
102
+ environment: 'development' | 'production'; // Required: Environment
103
+ timeout?: number; // Optional: Request timeout in ms (default: 10000)
104
+ }
105
+ ```
106
+
107
+ ## Authentication
108
+
109
+ ### Legal Entity Login
110
+
111
+ Authenticate a legal entity using Tax ID and password:
112
+
113
+ ```typescript
114
+ const result = await didox.auth.loginLegalEntity({
115
+ taxId: '123456789', // exactly 9 digits
116
+ password: 'securePass123', // minimum 8 characters
117
+ locale: 'ru' // optional: 'ru' | 'uz'
118
+ });
119
+
120
+ // Access token (UUID, valid for 360 minutes)
121
+ console.log(result.token);
122
+
123
+ // Related companies (if any)
124
+ if (result.related_companies) {
125
+ result.related_companies.forEach(company => {
126
+ console.log(`${company.name} (${company.tin})`);
127
+ console.log('Permissions:', company.permissions);
128
+ });
129
+ }
130
+ ```
131
+
132
+ ### Individual to Company Login
133
+
134
+ Switch context to a specific company using an individual's token:
135
+
136
+ ```typescript
137
+ const result = await didox.auth.loginCompanyAsIndividual({
138
+ companyTaxId: '987654321',
139
+ userToken: 'user-access-token',
140
+ locale: 'uz'
141
+ });
142
+
143
+ console.log('Company token:', result.token);
144
+ console.log('User roles in company:', result.permissions.roles);
145
+ ```
146
+
147
+ ## Account / Profile
148
+
149
+ ### Get Current Profile
150
+
151
+ Retrieve the profile information for the currently authenticated user:
152
+
153
+ ```typescript
154
+ try {
155
+ const profile = await didox.account.getProfile();
156
+
157
+ console.log('Mobile:', profile.mobile); // 998XXXXXXXXX
158
+ console.log('Email:', profile.email); // user@example.com
159
+ console.log('Notifications:', profile.notifications); // 0 or 1
160
+ console.log('Messengers:', profile.messengers); // ['telegram', 'viber']
161
+ } catch (error) {
162
+ if (error instanceof DidoxAuthError) {
163
+ console.error('Authentication required:', error.message);
164
+ }
165
+ }
166
+ ```
167
+
168
+ ### Update Profile
169
+
170
+ Update the current user's profile information:
171
+
172
+ ```typescript
173
+ try {
174
+ const updatedProfile = await didox.account.updateProfile({
175
+ mobile: '998901234567', // format: 998XXXXXXXXX
176
+ email: 'newemail@example.com', // valid email
177
+ password: 'newPassword123', // optional, min 8 chars
178
+ notifications: 1 // 1 = enabled, 0 = disabled
179
+ });
180
+
181
+ console.log('Profile updated successfully');
182
+ console.log('New mobile:', updatedProfile.mobile);
183
+ console.log('New email:', updatedProfile.email);
184
+ console.log('Notifications:', updatedProfile.notifications);
185
+ } catch (error) {
186
+ if (error instanceof DidoxValidationError) {
187
+ console.error('Validation error:', error.message);
188
+ console.error('Field:', error.field);
189
+ }
190
+ }
191
+ ```
192
+
193
+ ## Profile
194
+
195
+ The Profile module provides access to detailed company profile information and management capabilities.
49
196
 
197
+ ### Get Current Profile
50
198
 
51
- # Releases
52
- ### v0.0.5
53
- - ***Updated*** [Documents](https://api-docs.didox.uz/ru/integrators-documents) controller
54
- - Create document now can get AuthData - Login and Password
199
+ Retrieve comprehensive company profile data:
55
200
 
56
- ### v0.0.2
57
- - ***Updated*** [Documents](https://api-docs.didox.uz/ru/integrators-documents) controller
58
- - Get documents count
59
- - Get document information by ID
60
- - Get document privileges ( Льготы ) by ID
61
- - Create document
201
+ ```typescript
202
+ try {
203
+ const profile = await didox.profile.getProfile();
204
+
205
+ console.log('Company:', profile.fullName); // Full company name
206
+ console.log('TIN:', profile.tin); // Tax ID
207
+ console.log('Balance:', profile.balance); // Account balance
208
+ console.log('Director:', profile.director); // Director name
209
+ console.log('Address:', profile.address); // Company address
210
+ console.log('VAT Status:', profile.VATRegStatus); // VAT registration status
211
+ console.log('Messengers:', profile.messengers); // Connected messengers
212
+ } catch (error) {
213
+ if (error instanceof DidoxAuthError) {
214
+ console.error('Authentication required:', error.message);
215
+ }
216
+ }
217
+ ```
218
+
219
+ ### Update Profile
220
+
221
+ Update company profile information with validation:
222
+
223
+ ```typescript
224
+ try {
225
+ const updatedProfile = await didox.profile.updateProfile({
226
+ phone: '998901234567',
227
+ email: 'company@example.com',
228
+ notifications: 1, // Enable notifications
229
+ regionId: 26, // Tashkent region
230
+ directorTin: '123456789', // Director's TIN (9 digits)
231
+ address: 'New company address',
232
+ vatRate: 15 // VAT rate percentage
233
+ });
234
+
235
+ console.log('Profile updated successfully');
236
+ console.log('Updated company:', updatedProfile.name);
237
+ } catch (error) {
238
+ if (error instanceof DidoxValidationError) {
239
+ console.error('Validation error:', error.message);
240
+ console.error('Field:', error.field);
241
+ }
242
+ }
243
+ ```
244
+
245
+ ### Get Profile Operators
246
+
247
+ Retrieve operators associated with the company:
248
+
249
+ ```typescript
250
+ try {
251
+ const operators = await didox.profile.getOperators();
252
+
253
+ Object.entries(operators).forEach(([id, name]) => {
254
+ console.log(`Operator ${id}: ${name}`);
255
+ });
256
+
257
+ // Example output:
258
+ // Operator 202530465: soliqservis.uz
259
+ // Operator 302563857: Faktura.uz
260
+ // Operator 302936161: Didox.uz
261
+ } catch (error) {
262
+ console.error('Failed to get operators:', error.message);
263
+ }
264
+ ```
265
+
266
+ ## Utilities
267
+
268
+ The Utilities module provides helper functions for working with company data and branches.
269
+
270
+ ### Get Branches by TIN
271
+
272
+ Retrieve branch information for a specific company:
273
+
274
+ ```typescript
275
+ try {
276
+ const branches = await didox.utilities.getBranchesByTin({
277
+ tin: '123456789' // Company TIN (9 digits)
278
+ });
279
+
280
+ branches.forEach(branch => {
281
+ console.log(`Branch: ${branch.branchName}`);
282
+ console.log(`Location: ${branch.address}`);
283
+ console.log(`Director: ${branch.directorName}`);
284
+ console.log(`Status: ${branch.isDeleted ? 'Deleted' : 'Active'}`);
285
+ console.log(`Coordinates: ${branch.latitude}, ${branch.longitude}`);
286
+ console.log('---');
287
+ });
288
+ } catch (error) {
289
+ if (error instanceof DidoxValidationError) {
290
+ console.error('Invalid TIN format:', error.message);
291
+ }
292
+ }
293
+ ```
294
+
295
+ ## Error Handling
296
+
297
+ The SDK provides specific error classes for different failure scenarios:
298
+
299
+ ```typescript
300
+ import {
301
+ DidoxValidationError,
302
+ DidoxAuthError,
303
+ DidoxApiError,
304
+ DidoxNetworkError
305
+ } from 'didox';
306
+
307
+ try {
308
+ const result = await didox.auth.loginLegalEntity({
309
+ taxId: '123456789',
310
+ password: 'mypassword'
311
+ });
312
+ } catch (error) {
313
+ if (error instanceof DidoxValidationError) {
314
+ // Input validation failed
315
+ console.error('Validation error:', error.message);
316
+ console.error('Field:', error.field);
317
+
318
+ } else if (error instanceof DidoxAuthError) {
319
+ // Authentication failed (wrong credentials, etc.)
320
+ console.error('Auth error:', error.message);
321
+ console.error('Status code:', error.statusCode);
322
+
323
+ } else if (error instanceof DidoxApiError) {
324
+ // API returned an error response
325
+ console.error('API error:', error.message);
326
+ console.error('Status:', error.statusCode);
327
+ console.error('Response:', error.response);
328
+
329
+ } else if (error instanceof DidoxNetworkError) {
330
+ // Network/connectivity issues
331
+ console.error('Network error:', error.message);
332
+ console.error('Cause:', error.cause);
333
+ }
334
+ }
335
+ ```
336
+
337
+ ### Error Types
338
+
339
+ | Error Class | When It Occurs | Properties |
340
+ |-------------|----------------|------------|
341
+ | `DidoxValidationError` | Invalid input parameters | `field`, `message` |
342
+ | `DidoxAuthError` | Authentication failures (422) | `statusCode`, `message` |
343
+ | `DidoxApiError` | API errors (4xx, 5xx) | `statusCode`, `response`, `message` |
344
+ | `DidoxNetworkError` | Network/timeout issues | `cause`, `message` |
345
+
346
+ ## TypeScript Support
347
+
348
+ The SDK is built with TypeScript and provides full type definitions:
349
+
350
+ ```typescript
351
+ import type {
352
+ DidoxConfig,
353
+ LegalEntityLoginRequest,
354
+ LegalEntityLoginResponse,
355
+ CompanyLoginRequest,
356
+ CompanyLoginResponse,
357
+ RelatedCompany,
358
+ UserPermissions,
359
+ DidoxLocale,
360
+ AccountProfile,
361
+ UpdateProfileRequest,
362
+ UpdateProfileResponse,
363
+ CompanyProfile,
364
+ ProfileUpdateRequest,
365
+ ProfileUpdateResponse,
366
+ ProfileOperators,
367
+ CompanyBranch,
368
+ GetBranchesByTinRequest
369
+ } from 'didox';
370
+
371
+ // Fully typed request
372
+ const request: LegalEntityLoginRequest = {
373
+ taxId: '123456789',
374
+ password: 'securePassword',
375
+ locale: 'ru'
376
+ };
377
+
378
+ // Fully typed response
379
+ const response: LegalEntityLoginResponse = await didox.auth.loginLegalEntity(request);
380
+ ```
381
+
382
+ ## Requirements
383
+
384
+ - **Node.js**: ≥ 18.0.0
385
+ - **TypeScript**: ≥ 5.0 (for development)
386
+
387
+ ## Versioning
388
+
389
+ This package follows [Semantic Versioning](https://semver.org/):
390
+
391
+ - **1.x.0**: New features, backward compatible
392
+ - **1.x.y**: Bug fixes and patches
393
+ - **No breaking changes** in 1.x releases
394
+
395
+ ## License
396
+
397
+ MIT
398
+
399
+ ## Support
400
+
401
+ For API documentation and support:
402
+ - [Official Didox API Documentation](https://api-docs.didox.uz/ru/home)
403
+ - [GitHub Issues](https://github.com/mirzaevoff/didox/issues)
404
+
405
+ ---
62
406
 
63
- ### v0.0.1
64
- - ***Added*** support for [Account](https://api-docs.didox.uz/ru/integrators-account) controller
65
- - Get account information
66
- - Get account status ( own or by TIN )
67
- - ***Added*** support for [Profile](https://api-docs.didox.uz/ru/integrators-profile) controller
68
- - Get profile information
69
- - ***Added*** support for [Documents](https://api-docs.didox.uz/ru/integrators-documents) controller
70
- - Get documents list
407
+ **Note**: This is an unofficial SDK. For official support, contact Didox directly.