@adpal/shared-lib 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/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @adpal/shared-lib
2
+
3
+ Общие утилиты для проектов AdPal / Shared utilities for AdPal projects.
4
+
5
+ ## Установка / Installation
6
+
7
+ ```bash
8
+ npm install @adpal/shared-lib
9
+ ```
10
+
11
+ Для доступа к GitHub Packages:
12
+ ```bash
13
+ npm login --registry=https://npm.pkg.github.com --scope=@adpal
14
+ ```
15
+
16
+ ## Модули / Modules
17
+
18
+ ### Errors (Ошибки)
19
+
20
+ ```typescript
21
+ import { AppError, VoyageApiError, isAppError, wrapError } from '@adpal/shared-lib';
22
+
23
+ // Кастомная ошибка
24
+ throw new VoyageApiError('Rate limited', 429, { tokens: 1500 });
25
+
26
+ // Проверка типа
27
+ if (isAppError(error) && error.retryable) {
28
+ // Можно повторить
29
+ }
30
+ ```
31
+
32
+ ### Logger (Логирование)
33
+
34
+ ```typescript
35
+ import { Logger, createTimer } from '@adpal/shared-lib';
36
+
37
+ const log = new Logger('my-module');
38
+ const timer = createTimer();
39
+
40
+ log.info('Операция начата');
41
+ await doSomething();
42
+ log.info('Операция завершена', { durationMs: timer() });
43
+ ```
44
+
45
+ ### Retry
46
+
47
+ ```typescript
48
+ import { withRetry, retryApiCall } from '@adpal/shared-lib';
49
+
50
+ // С полным контролем
51
+ const result = await withRetry(
52
+ () => fetch('https://api.example.com'),
53
+ { maxAttempts: 3, baseDelayMs: 1000 }
54
+ );
55
+
56
+ // Для API вызовов
57
+ const data = await retryApiCall(() => fetchFromVoyage());
58
+ ```
59
+
60
+ ### Schemas (Zod валидация)
61
+
62
+ ```typescript
63
+ import {
64
+ VoyageEmbeddingResponseSchema,
65
+ safeParse
66
+ } from '@adpal/shared-lib';
67
+
68
+ const data = await response.json();
69
+ const parsed = safeParse(VoyageEmbeddingResponseSchema, data);
70
+ if (!parsed) throw new Error('Invalid response');
71
+ ```
72
+
73
+ ## Разработка / Development
74
+
75
+ ```bash
76
+ npm install
77
+ npm run build
78
+ npm test
79
+ ```
80
+
81
+ ## Безопасность / Security
82
+
83
+ Этот пакет **не содержит секретов**. Все API ключи передаются через `process.env` в runtime.