promidas 2.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.
Files changed (295) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -0
  3. package/dist/builder.d.ts +158 -0
  4. package/dist/builder.d.ts.map +1 -0
  5. package/dist/builder.js +255 -0
  6. package/dist/builder.js.map +1 -0
  7. package/dist/factory.d.ts +154 -0
  8. package/dist/factory.d.ts.map +1 -0
  9. package/dist/factory.js +243 -0
  10. package/dist/factory.js.map +1 -0
  11. package/dist/fetcher/client/config.d.ts +140 -0
  12. package/dist/fetcher/client/config.d.ts.map +1 -0
  13. package/dist/fetcher/client/config.js +2 -0
  14. package/dist/fetcher/client/config.js.map +1 -0
  15. package/dist/fetcher/client/fetch-with-progress.d.ts +156 -0
  16. package/dist/fetcher/client/fetch-with-progress.d.ts.map +1 -0
  17. package/dist/fetcher/client/fetch-with-progress.js +313 -0
  18. package/dist/fetcher/client/fetch-with-progress.js.map +1 -0
  19. package/dist/fetcher/client/fetch-with-timeout.d.ts +6 -0
  20. package/dist/fetcher/client/fetch-with-timeout.d.ts.map +1 -0
  21. package/dist/fetcher/client/fetch-with-timeout.js +48 -0
  22. package/dist/fetcher/client/fetch-with-timeout.js.map +1 -0
  23. package/dist/fetcher/client/protopedia-api-custom-client.d.ts +141 -0
  24. package/dist/fetcher/client/protopedia-api-custom-client.d.ts.map +1 -0
  25. package/dist/fetcher/client/protopedia-api-custom-client.js +268 -0
  26. package/dist/fetcher/client/protopedia-api-custom-client.js.map +1 -0
  27. package/dist/fetcher/client/select-custom-fetch.d.ts +58 -0
  28. package/dist/fetcher/client/select-custom-fetch.d.ts.map +1 -0
  29. package/dist/fetcher/client/select-custom-fetch.js +58 -0
  30. package/dist/fetcher/client/select-custom-fetch.js.map +1 -0
  31. package/dist/fetcher/errors/fetcher-error.d.ts +10 -0
  32. package/dist/fetcher/errors/fetcher-error.d.ts.map +1 -0
  33. package/dist/fetcher/errors/fetcher-error.js +15 -0
  34. package/dist/fetcher/errors/fetcher-error.js.map +1 -0
  35. package/dist/fetcher/index.d.ts +73 -0
  36. package/dist/fetcher/index.d.ts.map +1 -0
  37. package/dist/fetcher/index.js +70 -0
  38. package/dist/fetcher/index.js.map +1 -0
  39. package/dist/fetcher/types/index.d.ts +9 -0
  40. package/dist/fetcher/types/index.d.ts.map +1 -0
  41. package/dist/fetcher/types/index.js +7 -0
  42. package/dist/fetcher/types/index.js.map +1 -0
  43. package/dist/fetcher/types/progress-event.types.d.ts +221 -0
  44. package/dist/fetcher/types/progress-event.types.d.ts.map +1 -0
  45. package/dist/fetcher/types/progress-event.types.js +10 -0
  46. package/dist/fetcher/types/progress-event.types.js.map +1 -0
  47. package/dist/fetcher/types/prototype-api.types.d.ts +106 -0
  48. package/dist/fetcher/types/prototype-api.types.d.ts.map +1 -0
  49. package/dist/fetcher/types/prototype-api.types.js +2 -0
  50. package/dist/fetcher/types/prototype-api.types.js.map +1 -0
  51. package/dist/fetcher/types/result.types.d.ts +75 -0
  52. package/dist/fetcher/types/result.types.d.ts.map +1 -0
  53. package/dist/fetcher/types/result.types.js +2 -0
  54. package/dist/fetcher/types/result.types.js.map +1 -0
  55. package/dist/fetcher/utils/create-client-fetch.d.ts +63 -0
  56. package/dist/fetcher/utils/create-client-fetch.d.ts.map +1 -0
  57. package/dist/fetcher/utils/create-client-fetch.js +89 -0
  58. package/dist/fetcher/utils/create-client-fetch.js.map +1 -0
  59. package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts +6 -0
  60. package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts.map +1 -0
  61. package/dist/fetcher/utils/create-fetch-with-stripped-headers.js +40 -0
  62. package/dist/fetcher/utils/create-fetch-with-stripped-headers.js.map +1 -0
  63. package/dist/fetcher/utils/errors/handler.d.ts +58 -0
  64. package/dist/fetcher/utils/errors/handler.d.ts.map +1 -0
  65. package/dist/fetcher/utils/errors/handler.js +243 -0
  66. package/dist/fetcher/utils/errors/handler.js.map +1 -0
  67. package/dist/fetcher/utils/errors/messages.d.ts +75 -0
  68. package/dist/fetcher/utils/errors/messages.d.ts.map +1 -0
  69. package/dist/fetcher/utils/errors/messages.js +88 -0
  70. package/dist/fetcher/utils/errors/messages.js.map +1 -0
  71. package/dist/fetcher/utils/index.d.ts +13 -0
  72. package/dist/fetcher/utils/index.d.ts.map +1 -0
  73. package/dist/fetcher/utils/index.js +12 -0
  74. package/dist/fetcher/utils/index.js.map +1 -0
  75. package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts +10 -0
  76. package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts.map +1 -0
  77. package/dist/fetcher/utils/log-timestamp-normalization-warnings.js +32 -0
  78. package/dist/fetcher/utils/log-timestamp-normalization-warnings.js.map +1 -0
  79. package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts +59 -0
  80. package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts.map +1 -0
  81. package/dist/fetcher/utils/normalize-protopedia-timestamp.js +81 -0
  82. package/dist/fetcher/utils/normalize-protopedia-timestamp.js.map +1 -0
  83. package/dist/fetcher/utils/normalize-prototype.d.ts +56 -0
  84. package/dist/fetcher/utils/normalize-prototype.d.ts.map +1 -0
  85. package/dist/fetcher/utils/normalize-prototype.js +113 -0
  86. package/dist/fetcher/utils/normalize-prototype.js.map +1 -0
  87. package/dist/fetcher/utils/sanitize-options.d.ts +14 -0
  88. package/dist/fetcher/utils/sanitize-options.d.ts.map +1 -0
  89. package/dist/fetcher/utils/sanitize-options.js +16 -0
  90. package/dist/fetcher/utils/sanitize-options.js.map +1 -0
  91. package/dist/fetcher/utils/string-parsers.d.ts +45 -0
  92. package/dist/fetcher/utils/string-parsers.d.ts.map +1 -0
  93. package/dist/fetcher/utils/string-parsers.js +53 -0
  94. package/dist/fetcher/utils/string-parsers.js.map +1 -0
  95. package/dist/index.d.ts +66 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +70 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/logger/console-logger.d.ts +74 -0
  100. package/dist/logger/console-logger.d.ts.map +1 -0
  101. package/dist/logger/console-logger.js +113 -0
  102. package/dist/logger/console-logger.js.map +1 -0
  103. package/dist/logger/factory.d.ts +88 -0
  104. package/dist/logger/factory.d.ts.map +1 -0
  105. package/dist/logger/factory.js +94 -0
  106. package/dist/logger/factory.js.map +1 -0
  107. package/dist/logger/index.d.ts +42 -0
  108. package/dist/logger/index.d.ts.map +1 -0
  109. package/dist/logger/index.js +41 -0
  110. package/dist/logger/index.js.map +1 -0
  111. package/dist/logger/logger.types.d.ts +49 -0
  112. package/dist/logger/logger.types.d.ts.map +1 -0
  113. package/dist/logger/logger.types.js +2 -0
  114. package/dist/logger/logger.types.js.map +1 -0
  115. package/dist/repository/errors/validation-error.d.ts +24 -0
  116. package/dist/repository/errors/validation-error.d.ts.map +1 -0
  117. package/dist/repository/errors/validation-error.js +26 -0
  118. package/dist/repository/errors/validation-error.js.map +1 -0
  119. package/dist/repository/index.d.ts +122 -0
  120. package/dist/repository/index.d.ts.map +1 -0
  121. package/dist/repository/index.js +44 -0
  122. package/dist/repository/index.js.map +1 -0
  123. package/dist/repository/protopedia-in-memory-repository.d.ts +560 -0
  124. package/dist/repository/protopedia-in-memory-repository.d.ts.map +1 -0
  125. package/dist/repository/protopedia-in-memory-repository.js +929 -0
  126. package/dist/repository/protopedia-in-memory-repository.js.map +1 -0
  127. package/dist/repository/schemas/index.d.ts +9 -0
  128. package/dist/repository/schemas/index.d.ts.map +1 -0
  129. package/dist/repository/schemas/index.js +11 -0
  130. package/dist/repository/schemas/index.js.map +1 -0
  131. package/dist/repository/schemas/params.d.ts +44 -0
  132. package/dist/repository/schemas/params.d.ts.map +1 -0
  133. package/dist/repository/schemas/params.js +44 -0
  134. package/dist/repository/schemas/params.js.map +1 -0
  135. package/dist/repository/schemas/serializable-snapshot.d.ts +33 -0
  136. package/dist/repository/schemas/serializable-snapshot.d.ts.map +1 -0
  137. package/dist/repository/schemas/serializable-snapshot.js +45 -0
  138. package/dist/repository/schemas/serializable-snapshot.js.map +1 -0
  139. package/dist/repository/types/analysis.types.d.ts +89 -0
  140. package/dist/repository/types/analysis.types.d.ts.map +1 -0
  141. package/dist/repository/types/analysis.types.js +2 -0
  142. package/dist/repository/types/analysis.types.js.map +1 -0
  143. package/dist/repository/types/index.d.ts +12 -0
  144. package/dist/repository/types/index.d.ts.map +1 -0
  145. package/dist/repository/types/index.js +7 -0
  146. package/dist/repository/types/index.js.map +1 -0
  147. package/dist/repository/types/repository-events.types.d.ts +110 -0
  148. package/dist/repository/types/repository-events.types.d.ts.map +1 -0
  149. package/dist/repository/types/repository-events.types.js +2 -0
  150. package/dist/repository/types/repository-events.types.js.map +1 -0
  151. package/dist/repository/types/repository.types.d.ts +330 -0
  152. package/dist/repository/types/repository.types.d.ts.map +1 -0
  153. package/dist/repository/types/repository.types.js +2 -0
  154. package/dist/repository/types/repository.types.js.map +1 -0
  155. package/dist/repository/types/result.types.d.ts +55 -0
  156. package/dist/repository/types/result.types.d.ts.map +1 -0
  157. package/dist/repository/types/result.types.js +2 -0
  158. package/dist/repository/types/result.types.js.map +1 -0
  159. package/dist/repository/types/serialization.types.d.ts +61 -0
  160. package/dist/repository/types/serialization.types.d.ts.map +1 -0
  161. package/dist/repository/types/serialization.types.js +2 -0
  162. package/dist/repository/types/serialization.types.js.map +1 -0
  163. package/dist/repository/types/snapshot-operation.types.d.ts +140 -0
  164. package/dist/repository/types/snapshot-operation.types.d.ts.map +1 -0
  165. package/dist/repository/types/snapshot-operation.types.js +2 -0
  166. package/dist/repository/types/snapshot-operation.types.js.map +1 -0
  167. package/dist/repository/utils/convert-fetch-result.d.ts +46 -0
  168. package/dist/repository/utils/convert-fetch-result.d.ts.map +1 -0
  169. package/dist/repository/utils/convert-fetch-result.js +59 -0
  170. package/dist/repository/utils/convert-fetch-result.js.map +1 -0
  171. package/dist/repository/utils/convert-store-result.d.ts +36 -0
  172. package/dist/repository/utils/convert-store-result.d.ts.map +1 -0
  173. package/dist/repository/utils/convert-store-result.js +36 -0
  174. package/dist/repository/utils/convert-store-result.js.map +1 -0
  175. package/dist/repository/utils/emit-repository-event-safely.d.ts +5 -0
  176. package/dist/repository/utils/emit-repository-event-safely.d.ts.map +1 -0
  177. package/dist/repository/utils/emit-repository-event-safely.js +17 -0
  178. package/dist/repository/utils/emit-repository-event-safely.js.map +1 -0
  179. package/dist/repository/utils/index.d.ts +3 -0
  180. package/dist/repository/utils/index.d.ts.map +1 -0
  181. package/dist/repository/utils/index.js +3 -0
  182. package/dist/repository/utils/index.js.map +1 -0
  183. package/dist/repository/validation/index.d.ts +9 -0
  184. package/dist/repository/validation/index.d.ts.map +1 -0
  185. package/dist/repository/validation/index.js +10 -0
  186. package/dist/repository/validation/index.js.map +1 -0
  187. package/dist/repository/validation/params-validators.d.ts +46 -0
  188. package/dist/repository/validation/params-validators.d.ts.map +1 -0
  189. package/dist/repository/validation/params-validators.js +68 -0
  190. package/dist/repository/validation/params-validators.js.map +1 -0
  191. package/dist/repository/validation/serializable-snapshot.d.ts +47 -0
  192. package/dist/repository/validation/serializable-snapshot.d.ts.map +1 -0
  193. package/dist/repository/validation/serializable-snapshot.js +104 -0
  194. package/dist/repository/validation/serializable-snapshot.js.map +1 -0
  195. package/dist/schemas/index.d.ts +8 -0
  196. package/dist/schemas/index.d.ts.map +1 -0
  197. package/dist/schemas/index.js +8 -0
  198. package/dist/schemas/index.js.map +1 -0
  199. package/dist/schemas/normalized-prototype.d.ts +56 -0
  200. package/dist/schemas/normalized-prototype.d.ts.map +1 -0
  201. package/dist/schemas/normalized-prototype.js +123 -0
  202. package/dist/schemas/normalized-prototype.js.map +1 -0
  203. package/dist/store/errors/store-error.d.ts +148 -0
  204. package/dist/store/errors/store-error.d.ts.map +1 -0
  205. package/dist/store/errors/store-error.js +156 -0
  206. package/dist/store/errors/store-error.js.map +1 -0
  207. package/dist/store/index.d.ts +84 -0
  208. package/dist/store/index.d.ts.map +1 -0
  209. package/dist/store/index.js +83 -0
  210. package/dist/store/index.js.map +1 -0
  211. package/dist/store/store.d.ts +295 -0
  212. package/dist/store/store.d.ts.map +1 -0
  213. package/dist/store/store.js +411 -0
  214. package/dist/store/store.js.map +1 -0
  215. package/dist/store/types/index.d.ts +2 -0
  216. package/dist/store/types/index.d.ts.map +1 -0
  217. package/dist/store/types/index.js +2 -0
  218. package/dist/store/types/index.js.map +1 -0
  219. package/dist/store/types/result.types.d.ts +67 -0
  220. package/dist/store/types/result.types.d.ts.map +1 -0
  221. package/dist/store/types/result.types.js +2 -0
  222. package/dist/store/types/result.types.js.map +1 -0
  223. package/dist/types/codes.d.ts +44 -0
  224. package/dist/types/codes.d.ts.map +1 -0
  225. package/dist/types/codes.js +9 -0
  226. package/dist/types/codes.js.map +1 -0
  227. package/dist/types/index.d.ts +61 -0
  228. package/dist/types/index.d.ts.map +1 -0
  229. package/dist/types/index.js +60 -0
  230. package/dist/types/index.js.map +1 -0
  231. package/dist/types/normalized-prototype.d.ts +95 -0
  232. package/dist/types/normalized-prototype.d.ts.map +1 -0
  233. package/dist/types/normalized-prototype.js +2 -0
  234. package/dist/types/normalized-prototype.js.map +1 -0
  235. package/dist/utils/converters/index.d.ts +15 -0
  236. package/dist/utils/converters/index.d.ts.map +1 -0
  237. package/dist/utils/converters/index.js +15 -0
  238. package/dist/utils/converters/index.js.map +1 -0
  239. package/dist/utils/converters/license-type.d.ts +23 -0
  240. package/dist/utils/converters/license-type.d.ts.map +1 -0
  241. package/dist/utils/converters/license-type.js +38 -0
  242. package/dist/utils/converters/license-type.js.map +1 -0
  243. package/dist/utils/converters/release-flag.d.ts +24 -0
  244. package/dist/utils/converters/release-flag.d.ts.map +1 -0
  245. package/dist/utils/converters/release-flag.js +40 -0
  246. package/dist/utils/converters/release-flag.js.map +1 -0
  247. package/dist/utils/converters/status.d.ts +23 -0
  248. package/dist/utils/converters/status.d.ts.map +1 -0
  249. package/dist/utils/converters/status.js +40 -0
  250. package/dist/utils/converters/status.js.map +1 -0
  251. package/dist/utils/converters/thanks-flag.d.ts +25 -0
  252. package/dist/utils/converters/thanks-flag.d.ts.map +1 -0
  253. package/dist/utils/converters/thanks-flag.js +41 -0
  254. package/dist/utils/converters/thanks-flag.js.map +1 -0
  255. package/dist/utils/deep-merge.d.ts +38 -0
  256. package/dist/utils/deep-merge.d.ts.map +1 -0
  257. package/dist/utils/deep-merge.js +85 -0
  258. package/dist/utils/deep-merge.js.map +1 -0
  259. package/dist/utils/index.d.ts +80 -0
  260. package/dist/utils/index.d.ts.map +1 -0
  261. package/dist/utils/index.js +85 -0
  262. package/dist/utils/index.js.map +1 -0
  263. package/dist/utils/logger-utils.d.ts +100 -0
  264. package/dist/utils/logger-utils.d.ts.map +1 -0
  265. package/dist/utils/logger-utils.js +265 -0
  266. package/dist/utils/logger-utils.js.map +1 -0
  267. package/dist/utils/time/constants.d.ts +14 -0
  268. package/dist/utils/time/constants.d.ts.map +1 -0
  269. package/dist/utils/time/constants.js +14 -0
  270. package/dist/utils/time/constants.js.map +1 -0
  271. package/dist/utils/time/index.d.ts +28 -0
  272. package/dist/utils/time/index.d.ts.map +1 -0
  273. package/dist/utils/time/index.js +28 -0
  274. package/dist/utils/time/index.js.map +1 -0
  275. package/dist/utils/time/parser.d.ts +91 -0
  276. package/dist/utils/time/parser.d.ts.map +1 -0
  277. package/dist/utils/time/parser.js +143 -0
  278. package/dist/utils/time/parser.js.map +1 -0
  279. package/dist/utils/validation/index.d.ts +8 -0
  280. package/dist/utils/validation/index.d.ts.map +1 -0
  281. package/dist/utils/validation/index.js +7 -0
  282. package/dist/utils/validation/index.js.map +1 -0
  283. package/dist/utils/validation/normalized-prototype.d.ts +64 -0
  284. package/dist/utils/validation/normalized-prototype.d.ts.map +1 -0
  285. package/dist/utils/validation/normalized-prototype.js +97 -0
  286. package/dist/utils/validation/normalized-prototype.js.map +1 -0
  287. package/dist/utils/validation/types.d.ts +62 -0
  288. package/dist/utils/validation/types.d.ts.map +1 -0
  289. package/dist/utils/validation/types.js +8 -0
  290. package/dist/utils/validation/types.js.map +1 -0
  291. package/dist/version.d.ts +6 -0
  292. package/dist/version.d.ts.map +1 -0
  293. package/dist/version.js +6 -0
  294. package/dist/version.js.map +1 -0
  295. package/package.json +138 -0
@@ -0,0 +1,141 @@
1
+ /**
2
+ * ProtopediaApiCustomClient class implementation.
3
+ *
4
+ * This module provides a class-based wrapper around the official
5
+ * protopedia-api-v2-client with integrated logger management,
6
+ * event-driven progress tracking, and high-level helper methods.
7
+ *
8
+ * Features:
9
+ * - Fastify-style logger configuration (logger + logLevel)
10
+ * - Event-driven progress tracking with type-safe discriminated unions
11
+ * - Automatic data normalization and validation
12
+ * - Result type for type-safe error handling
13
+ *
14
+ * @module
15
+ */
16
+ import { type ListPrototypesParams } from 'protopedia-api-v2-client';
17
+ import type { FetchPrototypesResult } from '../types/result.types.js';
18
+ import type { ProtopediaApiCustomClientConfig } from './config.js';
19
+ /**
20
+ * Custom API client that wraps protopedia-api-v2-client with enhanced features.
21
+ *
22
+ * This class manages:
23
+ * - Logger configuration (Fastify-style with logger + logLevel)
24
+ * - Integration with protopedia-api-v2-client
25
+ * - Event-driven progress tracking for download operations
26
+ * - High-level fetchPrototypes helper with normalization and error handling
27
+ *
28
+ * @example Basic usage
29
+ * ```typescript
30
+ * const client = new ProtopediaApiCustomClient({
31
+ * protoPediaApiClientOptions: {
32
+ * token: process.env.PROTOPEDIA_API_TOKEN,
33
+ * },
34
+ * logLevel: 'debug',
35
+ * });
36
+ *
37
+ * const result = await client.fetchPrototypes({ limit: 10 });
38
+ * if (result.ok) {
39
+ * console.log(result.data);
40
+ * }
41
+ * ```
42
+ *
43
+ * @example With progress tracking
44
+ * ```typescript
45
+ * const client = new ProtopediaApiCustomClient({
46
+ * protoPediaApiClientOptions: {
47
+ * token: process.env.PROTOPEDIA_API_TOKEN,
48
+ * },
49
+ * progressCallback: (event) => {
50
+ * switch (event.type) {
51
+ * case 'request-start':
52
+ * console.log('Starting request...');
53
+ * break;
54
+ * case 'download-progress':
55
+ * console.log(`Progress: ${event.percentage.toFixed(1)}%`);
56
+ * break;
57
+ * case 'complete':
58
+ * console.log(`Complete in ${event.totalTimeMs}ms`);
59
+ * break;
60
+ * }
61
+ * },
62
+ * });
63
+ * ```
64
+ */
65
+ export declare class ProtopediaApiCustomClient {
66
+ #private;
67
+ /**
68
+ * Create a new ProtopediaApiCustomClient instance.
69
+ *
70
+ * @param config - Configuration options for the client
71
+ * @param config.protoPediaApiClientOptions - Options for protopedia-api-v2-client
72
+ * @param config.protoPediaApiClientOptions.timeoutMs - Optional request timeout in milliseconds
73
+ * @param config.protoPediaApiClientOptions.fetch - Optional custom fetch implementation
74
+ * @param config.logger - Custom logger instance
75
+ * @param config.logLevel - Log level for default logger or to update existing logger
76
+ * @param config.progressLog - Enable download progress logging (default: true)
77
+ * @param config.progressCallback - Event handler for download progress lifecycle events
78
+ *
79
+ * @throws {unknown} If the underlying protopedia-api-v2-client initialization fails
80
+ *
81
+ * @example Basic usage with progress logging
82
+ * ```typescript
83
+ * const client = new ProtopediaApiCustomClient({
84
+ * protoPediaApiClientOptions: { token: process.env.TOKEN },
85
+ * logLevel: 'info', // Shows progress logs
86
+ * });
87
+ * ```
88
+ *
89
+ * @example With custom event handler
90
+ * ```typescript
91
+ * const client = new ProtopediaApiCustomClient({
92
+ * protoPediaApiClientOptions: { token: process.env.TOKEN },
93
+ * progressLog: false, // Disable automatic logging
94
+ * progressCallback: (event) => {
95
+ * if (event.type === 'download-progress') {
96
+ * updateProgressBar(event.percentage);
97
+ * }
98
+ * },
99
+ * });
100
+ * ```
101
+ */
102
+ constructor(config?: ProtopediaApiCustomClientConfig | null);
103
+ /**
104
+ * Fetch prototypes using the configured client, normalize them,
105
+ * and return a structured result.
106
+ *
107
+ * This high-level helper combines API fetching, normalization, and
108
+ * error handling into a single call. It uses the logger configured
109
+ * during construction for error diagnostics.
110
+ *
111
+ * @param params - Query parameters for listing prototypes
112
+ * @returns A {@link FetchPrototypesResult} with normalized data or error details
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const result = await client.fetchPrototypes({ offset: 0, limit: 100 });
117
+ * if (result.ok) {
118
+ * console.log(`Fetched ${result.data.length} prototypes`);
119
+ * } else {
120
+ * console.error(result.error, result.status);
121
+ * }
122
+ * ```
123
+ */
124
+ fetchPrototypes(params: ListPrototypesParams): Promise<FetchPrototypesResult>;
125
+ /**
126
+ * Direct access to the underlying protopedia-api-v2-client's listPrototypes method.
127
+ *
128
+ * Use this when you need the raw API response without normalization.
129
+ *
130
+ * @param params - Query parameters for listing prototypes
131
+ * @returns Raw API response from protopedia-api-v2-client
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const rawResult = await client.listPrototypes({ limit: 10 });
136
+ * console.log(rawResult.results);
137
+ * ```
138
+ */
139
+ listPrototypes(params: ListPrototypesParams): Promise<import("protopedia-api-v2-client").ListPrototypesApiResponse>;
140
+ }
141
+ //# sourceMappingURL=protopedia-api-custom-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protopedia-api-custom-client.d.ts","sourceRoot":"","sources":["../../../lib/fetcher/client/protopedia-api-custom-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,0BAA0B,CAAC;AAclC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAMtE,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,yBAAyB;;IAgBpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;gBACS,MAAM,CAAC,EAAE,+BAA+B,GAAG,IAAI;IA6I3D;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,eAAe,CACnB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,qBAAqB,CAAC;IAIjC;;;;;;;;;;;;;OAaG;IACG,cAAc,CAAC,MAAM,EAAE,oBAAoB;CAGlD"}
@@ -0,0 +1,268 @@
1
+ /**
2
+ * ProtopediaApiCustomClient class implementation.
3
+ *
4
+ * This module provides a class-based wrapper around the official
5
+ * protopedia-api-v2-client with integrated logger management,
6
+ * event-driven progress tracking, and high-level helper methods.
7
+ *
8
+ * Features:
9
+ * - Fastify-style logger configuration (logger + logLevel)
10
+ * - Event-driven progress tracking with type-safe discriminated unions
11
+ * - Automatic data normalization and validation
12
+ * - Result type for type-safe error handling
13
+ *
14
+ * @module
15
+ */
16
+ import { createProtoPediaClient, } from 'protopedia-api-v2-client';
17
+ import { ConsoleLogger, } from '../../logger/index.js';
18
+ import { sanitizeDataForLogging } from '../../utils/index.js';
19
+ import { VERSION } from '../../version.js';
20
+ import { createClientFetch } from '../utils/create-client-fetch.js';
21
+ import { handleApiError } from '../utils/errors/handler.js';
22
+ import { logTimestampNormalizationWarnings } from '../utils/log-timestamp-normalization-warnings.js';
23
+ import { normalizePrototype } from '../utils/normalize-prototype.js';
24
+ /**
25
+ * Custom API client that wraps protopedia-api-v2-client with enhanced features.
26
+ *
27
+ * This class manages:
28
+ * - Logger configuration (Fastify-style with logger + logLevel)
29
+ * - Integration with protopedia-api-v2-client
30
+ * - Event-driven progress tracking for download operations
31
+ * - High-level fetchPrototypes helper with normalization and error handling
32
+ *
33
+ * @example Basic usage
34
+ * ```typescript
35
+ * const client = new ProtopediaApiCustomClient({
36
+ * protoPediaApiClientOptions: {
37
+ * token: process.env.PROTOPEDIA_API_TOKEN,
38
+ * },
39
+ * logLevel: 'debug',
40
+ * });
41
+ *
42
+ * const result = await client.fetchPrototypes({ limit: 10 });
43
+ * if (result.ok) {
44
+ * console.log(result.data);
45
+ * }
46
+ * ```
47
+ *
48
+ * @example With progress tracking
49
+ * ```typescript
50
+ * const client = new ProtopediaApiCustomClient({
51
+ * protoPediaApiClientOptions: {
52
+ * token: process.env.PROTOPEDIA_API_TOKEN,
53
+ * },
54
+ * progressCallback: (event) => {
55
+ * switch (event.type) {
56
+ * case 'request-start':
57
+ * console.log('Starting request...');
58
+ * break;
59
+ * case 'download-progress':
60
+ * console.log(`Progress: ${event.percentage.toFixed(1)}%`);
61
+ * break;
62
+ * case 'complete':
63
+ * console.log(`Complete in ${event.totalTimeMs}ms`);
64
+ * break;
65
+ * }
66
+ * },
67
+ * });
68
+ * ```
69
+ */
70
+ export class ProtopediaApiCustomClient {
71
+ /**
72
+ * Underlying protopedia-api-v2-client instance.
73
+ */
74
+ #client;
75
+ /**
76
+ * Logger instance for this client.
77
+ */
78
+ #logger;
79
+ /**
80
+ * Log level for this client.
81
+ */
82
+ #logLevel;
83
+ /**
84
+ * Create a new ProtopediaApiCustomClient instance.
85
+ *
86
+ * @param config - Configuration options for the client
87
+ * @param config.protoPediaApiClientOptions - Options for protopedia-api-v2-client
88
+ * @param config.protoPediaApiClientOptions.timeoutMs - Optional request timeout in milliseconds
89
+ * @param config.protoPediaApiClientOptions.fetch - Optional custom fetch implementation
90
+ * @param config.logger - Custom logger instance
91
+ * @param config.logLevel - Log level for default logger or to update existing logger
92
+ * @param config.progressLog - Enable download progress logging (default: true)
93
+ * @param config.progressCallback - Event handler for download progress lifecycle events
94
+ *
95
+ * @throws {unknown} If the underlying protopedia-api-v2-client initialization fails
96
+ *
97
+ * @example Basic usage with progress logging
98
+ * ```typescript
99
+ * const client = new ProtopediaApiCustomClient({
100
+ * protoPediaApiClientOptions: { token: process.env.TOKEN },
101
+ * logLevel: 'info', // Shows progress logs
102
+ * });
103
+ * ```
104
+ *
105
+ * @example With custom event handler
106
+ * ```typescript
107
+ * const client = new ProtopediaApiCustomClient({
108
+ * protoPediaApiClientOptions: { token: process.env.TOKEN },
109
+ * progressLog: false, // Disable automatic logging
110
+ * progressCallback: (event) => {
111
+ * if (event.type === 'download-progress') {
112
+ * updateProgressBar(event.percentage);
113
+ * }
114
+ * },
115
+ * });
116
+ * ```
117
+ */
118
+ constructor(config) {
119
+ const { protoPediaApiClientOptions = {}, logger, logLevel, progressLog = true, progressCallback, } = config ?? {};
120
+ const { timeoutMs, fetch: providedFetch, ...sdkOptions } = protoPediaApiClientOptions;
121
+ // Fastify-style logger configuration
122
+ if (logger) {
123
+ this.#logger = logger;
124
+ this.#logLevel = logLevel ?? 'info';
125
+ // If logLevel is specified, update logger's level property (if mutable)
126
+ if (logLevel !== undefined && 'level' in logger) {
127
+ logger.level = logLevel;
128
+ }
129
+ }
130
+ else {
131
+ const resolvedLogLevel = logLevel ?? 'info';
132
+ this.#logger = new ConsoleLogger(resolvedLogLevel);
133
+ this.#logLevel = resolvedLogLevel;
134
+ }
135
+ this.#logger.info('ProtopediaApiCustomClient constructor called', sanitizeDataForLogging(config));
136
+ const hasWindow = typeof globalThis.window !== 'undefined';
137
+ const hasDocument = typeof globalThis.document !== 'undefined';
138
+ const isBrowserRuntime = hasWindow && hasDocument;
139
+ // Determine User-Agent header
140
+ const userAgent = sdkOptions.userAgent ?? `ProtopediaApiCustomClient/${VERSION} (promidas)`;
141
+ // Issue #55 (browser CORS): `protopedia-api-v2-client` adds
142
+ // `x-client-user-agent` by design. In browsers, custom request headers
143
+ // trigger a CORS preflight and the request may be blocked because the
144
+ // server may not allow that header.
145
+ //
146
+ // Mitigation (promidas-side): In browser runtimes, strip
147
+ // `x-client-user-agent` from the outgoing request in our fetch wrapper.
148
+ // Server-side Node.js execution is not affected.
149
+ // Determine headers to strip based on runtime environment
150
+ const stripHeaders = isBrowserRuntime ? ['x-client-user-agent'] : undefined;
151
+ const customFetch = createClientFetch({
152
+ logger: this.#logger,
153
+ enableProgressLog: progressLog,
154
+ progressCallback,
155
+ timeoutMs,
156
+ providedFetch: providedFetch,
157
+ stripHeaders,
158
+ });
159
+ // Create underlying protopedia-api-v2-client
160
+ // Note: SDK client logging is controlled via protoPediaApiClientOptions
161
+ this.#client = createProtoPediaClient({
162
+ ...sdkOptions,
163
+ userAgent,
164
+ ...(customFetch !== undefined && { fetch: customFetch }),
165
+ });
166
+ }
167
+ /**
168
+ * Fetch and normalize ProtoPedia prototypes.
169
+ *
170
+ * This helper calls the underlying client's listPrototypes method,
171
+ * normalizes each item into a {@link NormalizedPrototype}, and wraps
172
+ * the result in a {@link FetchPrototypesResult} discriminated union.
173
+ *
174
+ * This method never throws; all errors are caught and converted into
175
+ * failure results by {@link handleApiError}.
176
+ *
177
+ * @param params - Query parameters for the upstream listPrototypes call
178
+ * @returns A {@link FetchPrototypesResult} with normalized data or error details
179
+ *
180
+ * @private
181
+ */
182
+ async #fetchAndNormalizePrototypes(params) {
183
+ try {
184
+ const upstream = await this.#client.listPrototypes(params);
185
+ let data = [];
186
+ if (!Array.isArray(upstream.results)) {
187
+ this.#logger.warn('Upstream API response "results" is not an array. Returning empty data.', {
188
+ upstreamResults: upstream.results,
189
+ params,
190
+ });
191
+ // data remains empty array as initialized
192
+ }
193
+ else {
194
+ data = upstream.results.map((value, index) => {
195
+ const original = value;
196
+ const normalized = normalizePrototype(original);
197
+ logTimestampNormalizationWarnings({
198
+ logger: this.#logger,
199
+ original,
200
+ normalized,
201
+ index,
202
+ });
203
+ return normalized;
204
+ });
205
+ }
206
+ this.#logger.debug(`Successfully fetched ${data.length} prototypes.`, {
207
+ params,
208
+ });
209
+ return { ok: true, data };
210
+ }
211
+ catch (error) {
212
+ const errorResult = handleApiError(error);
213
+ // Log based on the errorResult (always an error result from handleApiError)
214
+ if (!errorResult.ok) {
215
+ const sanitizedError = sanitizeDataForLogging(errorResult);
216
+ if (errorResult.status === undefined || errorResult.status >= 500) {
217
+ this.#logger.error(errorResult.error, sanitizedError);
218
+ }
219
+ else {
220
+ this.#logger.warn(errorResult.error, sanitizedError);
221
+ }
222
+ }
223
+ return errorResult;
224
+ }
225
+ }
226
+ /**
227
+ * Fetch prototypes using the configured client, normalize them,
228
+ * and return a structured result.
229
+ *
230
+ * This high-level helper combines API fetching, normalization, and
231
+ * error handling into a single call. It uses the logger configured
232
+ * during construction for error diagnostics.
233
+ *
234
+ * @param params - Query parameters for listing prototypes
235
+ * @returns A {@link FetchPrototypesResult} with normalized data or error details
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * const result = await client.fetchPrototypes({ offset: 0, limit: 100 });
240
+ * if (result.ok) {
241
+ * console.log(`Fetched ${result.data.length} prototypes`);
242
+ * } else {
243
+ * console.error(result.error, result.status);
244
+ * }
245
+ * ```
246
+ */
247
+ async fetchPrototypes(params) {
248
+ return this.#fetchAndNormalizePrototypes(params);
249
+ }
250
+ /**
251
+ * Direct access to the underlying protopedia-api-v2-client's listPrototypes method.
252
+ *
253
+ * Use this when you need the raw API response without normalization.
254
+ *
255
+ * @param params - Query parameters for listing prototypes
256
+ * @returns Raw API response from protopedia-api-v2-client
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const rawResult = await client.listPrototypes({ limit: 10 });
261
+ * console.log(rawResult.results);
262
+ * ```
263
+ */
264
+ async listPrototypes(params) {
265
+ return this.#client.listPrototypes(params);
266
+ }
267
+ }
268
+ //# sourceMappingURL=protopedia-api-custom-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protopedia-api-custom-client.js","sourceRoot":"","sources":["../../../lib/fetcher/client/protopedia-api-custom-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EACL,sBAAsB,GAGvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,GAGd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAM3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,iCAAiC,EAAE,MAAM,kDAAkD,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAA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OAaG;IACH,KAAK,CAAC,cAAc,CAAC,MAA4B;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Custom fetch selector function.
3
+ *
4
+ * This module provides a function to select the appropriate custom fetch
5
+ * implementation based on configuration. It evaluates various feature flags
6
+ * and returns the corresponding custom fetch function, or undefined to use
7
+ * the default fetch implementation.
8
+ *
9
+ * @module
10
+ */
11
+ import type { Logger } from '../../logger/index.js';
12
+ import type { FetchProgressEvent } from '../types/progress-event.types.js';
13
+ /**
14
+ * Configuration for custom fetch selection.
15
+ */
16
+ export interface CustomFetchConfig {
17
+ /**
18
+ * Logger instance for custom fetch implementations.
19
+ */
20
+ logger: Logger;
21
+ /**
22
+ * Whether to enable progress logging.
23
+ */
24
+ enableProgressLog: boolean;
25
+ /**
26
+ * Base fetch function to wrap with progress tracking.
27
+ * If not provided, uses global fetch.
28
+ */
29
+ baseFetch?: typeof fetch;
30
+ /**
31
+ * Optional callback for progress events.
32
+ */
33
+ onProgressEvent?: (event: FetchProgressEvent) => void;
34
+ }
35
+ /**
36
+ * Select appropriate custom fetch function based on configuration.
37
+ *
38
+ * This function evaluates the provided configuration and returns the appropriate
39
+ * custom fetch function. If no custom features are needed, it returns undefined
40
+ * to allow the default fetch implementation to be used.
41
+ *
42
+ * @param config - Configuration for custom fetch selection
43
+ * @returns Custom fetch function or undefined for default behavior
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const customFetch = selectCustomFetch({
48
+ * logger: myLogger,
49
+ * enableProgressLog: true,
50
+ * });
51
+ *
52
+ * const client = createProtoPediaClient({
53
+ * fetch: customFetch, // undefined uses default fetch
54
+ * });
55
+ * ```
56
+ */
57
+ export declare function selectCustomFetch(config: CustomFetchConfig): typeof fetch | undefined;
58
+ //# sourceMappingURL=select-custom-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-custom-fetch.d.ts","sourceRoot":"","sources":["../../../lib/fetcher/client/select-custom-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAI3E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IAEzB;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,iBAAiB,GACxB,OAAO,KAAK,GAAG,SAAS,CA4B1B"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Custom fetch selector function.
3
+ *
4
+ * This module provides a function to select the appropriate custom fetch
5
+ * implementation based on configuration. It evaluates various feature flags
6
+ * and returns the corresponding custom fetch function, or undefined to use
7
+ * the default fetch implementation.
8
+ *
9
+ * @module
10
+ */
11
+ import { createFetchWithProgress } from './fetch-with-progress.js';
12
+ /**
13
+ * Select appropriate custom fetch function based on configuration.
14
+ *
15
+ * This function evaluates the provided configuration and returns the appropriate
16
+ * custom fetch function. If no custom features are needed, it returns undefined
17
+ * to allow the default fetch implementation to be used.
18
+ *
19
+ * @param config - Configuration for custom fetch selection
20
+ * @returns Custom fetch function or undefined for default behavior
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const customFetch = selectCustomFetch({
25
+ * logger: myLogger,
26
+ * enableProgressLog: true,
27
+ * });
28
+ *
29
+ * const client = createProtoPediaClient({
30
+ * fetch: customFetch, // undefined uses default fetch
31
+ * });
32
+ * ```
33
+ */
34
+ export function selectCustomFetch(config) {
35
+ const { logger, enableProgressLog, baseFetch, onProgressEvent } = config;
36
+ // Check if progress tracking is needed
37
+ const needsProgressTracking = enableProgressLog || onProgressEvent !== undefined;
38
+ if (needsProgressTracking) {
39
+ return createFetchWithProgress({
40
+ logger,
41
+ enableProgressLog,
42
+ ...(baseFetch !== undefined && { baseFetch }),
43
+ ...(onProgressEvent !== undefined && { onProgressEvent }),
44
+ });
45
+ }
46
+ // Future: Add other custom fetch implementations here
47
+ // Example:
48
+ // if (config.retryEnabled) {
49
+ // return createFetchWithRetry({ baseFetch, ... });
50
+ // }
51
+ //
52
+ // if (config.cacheEnabled) {
53
+ // return createFetchWithCache({ baseFetch, ... });
54
+ // }
55
+ // If no custom features needed, return the base fetch or undefined
56
+ return baseFetch;
57
+ }
58
+ //# sourceMappingURL=select-custom-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-custom-fetch.js","sourceRoot":"","sources":["../../../lib/fetcher/client/select-custom-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AA4BnE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAyB;IAEzB,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAEzE,uCAAuC;IACvC,MAAM,qBAAqB,GACzB,iBAAiB,IAAI,eAAe,KAAK,SAAS,CAAC;IAErD,IAAI,qBAAqB,EAAE,CAAC;QAC1B,OAAO,uBAAuB,CAAC;YAC7B,MAAM;YACN,iBAAiB;YACjB,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;YAC7C,GAAG,CAAC,eAAe,KAAK,SAAS,IAAI,EAAE,eAAe,EAAE,CAAC;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,sDAAsD;IACtD,WAAW;IACX,6BAA6B;IAC7B,qDAAqD;IACrD,IAAI;IACJ,EAAE;IACF,6BAA6B;IAC7B,qDAAqD;IACrD,IAAI;IAEJ,mEAAmE;IACnE,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Error classes for fetcher operations.
3
+ *
4
+ * @module
5
+ */
6
+ export declare class PromidasTimeoutError extends Error {
7
+ readonly timeoutMs: number;
8
+ constructor(timeoutMs: number, message?: string);
9
+ }
10
+ //# sourceMappingURL=fetcher-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher-error.d.ts","sourceRoot":"","sources":["../../../lib/fetcher/errors/fetcher-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAMhD"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Error classes for fetcher operations.
3
+ *
4
+ * @module
5
+ */
6
+ export class PromidasTimeoutError extends Error {
7
+ timeoutMs;
8
+ constructor(timeoutMs, message) {
9
+ super(message ?? `Upstream request timed out after ${timeoutMs}ms`);
10
+ Object.setPrototypeOf(this, new.target.prototype);
11
+ this.name = 'PromidasTimeoutError';
12
+ this.timeoutMs = timeoutMs;
13
+ }
14
+ }
15
+ //# sourceMappingURL=fetcher-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher-error.js","sourceRoot":"","sources":["../../../lib/fetcher/errors/fetcher-error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,SAAS,CAAS;IAE3B,YAAY,SAAiB,EAAE,OAAgB;QAC7C,KAAK,CAAC,OAAO,IAAI,oCAAoC,SAAS,IAAI,CAAC,CAAC;QACpE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * ProtoPedia API Client and Data Fetching Utilities.
3
+ *
4
+ * This module provides a complete fetcher layer for interacting with the
5
+ * ProtoPedia API, including client creation, data fetching, normalization,
6
+ * and error handling. It can be used as a standalone module for custom
7
+ * data pipelines or integrated with the repository layer.
8
+ *
9
+ * ## Core Components
10
+ *
11
+ * - {@link ProtopediaApiCustomClient} — Class-based client with managed logger and high-level methods.
12
+ * - {@link ProtopediaApiCustomClientConfig} — Configuration options including logger and SDK client settings.
13
+ *
14
+ * ### Dependencies
15
+ *
16
+ * Types from `protopedia-api-v2-client` should be imported directly from the package:
17
+ * - `ProtoPediaApiClientOptions` — SDK client options.
18
+ * - `ListPrototypesParams` — Query parameters for listing prototypes.
19
+ *
20
+ * ### Data Fetching & Normalization
21
+ *
22
+ * - {@link FetchPrototypesResult} — Discriminated union result type for fetch operations.
23
+ * - {@link normalizePrototype} — Transform raw API data to {@link NormalizedPrototype}.
24
+ * - {@link UpstreamPrototype} — Raw API response type from protopedia-api-v2-client.
25
+ * - {@link NormalizedPrototype} — Standardized, type-safe prototype data model.
26
+ *
27
+ * ### Logging
28
+ *
29
+ * - {@link Logger} — Logger interface compatible with protopedia-api-v2-client.
30
+ * - {@link LogLevel} — Log level type for controlling logger verbosity.
31
+ *
32
+ * ## Standalone Usage
33
+ *
34
+ * This module is designed to work independently, allowing you to:
35
+ * - Create custom API clients with specific configurations
36
+ * - Build custom data processing pipelines
37
+ * - Integrate with different runtime environments (Node.js, Next.js, etc.)
38
+ *
39
+ * ## API Client Version Compatibility
40
+ *
41
+ * This library supports `protopedia-api-v2-client` v3.0.0 and later.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { ProtopediaApiCustomClient } from 'promidas/fetcher';
46
+ *
47
+ * const client = new ProtopediaApiCustomClient({
48
+ * protoPediaApiClientOptions: {
49
+ * token: process.env.PROTOPEDIA_API_TOKEN,
50
+ * },
51
+ * logLevel: 'debug',
52
+ * });
53
+ *
54
+ * const result = await client.fetchPrototypes({ limit: 10 });
55
+ *
56
+ * if (result.ok) {
57
+ * console.log(`Fetched ${result.data.length} prototypes`);
58
+ * }
59
+ * ```
60
+ *
61
+ * @module
62
+ * @see {@link ../repository/index.js} for high-level repository integration
63
+ */
64
+ export type { NormalizedPrototype } from '../types/index.js';
65
+ export type { Logger, LogLevel } from '../logger/index.js';
66
+ export { ProtopediaApiCustomClient } from './client/protopedia-api-custom-client.js';
67
+ export type { ProtopediaApiCustomClientConfig } from './client/config.js';
68
+ export type { FetchProgressEvent } from './types/progress-event.types.js';
69
+ export { PromidasTimeoutError } from './errors/fetcher-error.js';
70
+ export type { FetchPrototypesResult, FetchFailureKind, FetcherErrorCode, } from './types/result.types.js';
71
+ export type { UpstreamPrototype } from './types/prototype-api.types.js';
72
+ export { normalizePrototype } from './utils/normalize-prototype.js';
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAGH,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,YAAY,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAG1E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAG1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,YAAY,EACV,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}