@coderule/clients 1.1.0 → 1.4.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/dist/index.d.ts CHANGED
@@ -23,6 +23,38 @@ interface JWTPayload {
23
23
  }
24
24
  declare function decodeJWT(jwtToken: string): JWTPayload | null;
25
25
 
26
+ interface JWTProvider {
27
+ getJWT(forceRefresh?: boolean): Promise<string>;
28
+ }
29
+ interface TokenRefreshInfo {
30
+ token: string;
31
+ expiresAt: number;
32
+ serverUrl?: string;
33
+ }
34
+ interface JWTFactoryOptions {
35
+ minTtlMs?: number;
36
+ onTokenRefreshed?: (info: TokenRefreshInfo) => void;
37
+ }
38
+ declare class JWTFactory implements JWTProvider {
39
+ private readonly authClient;
40
+ private sourceToken;
41
+ private cache?;
42
+ private refreshPromise?;
43
+ private readonly minTtlMs;
44
+ private readonly onTokenRefreshed?;
45
+ private currentServerUrl?;
46
+ constructor(authClient: AuthHttpClient, sourceToken: string, options?: JWTFactoryOptions);
47
+ setSourceToken(token: string): void;
48
+ invalidate(): void;
49
+ getJWT(forceRefresh?: boolean): Promise<string>;
50
+ private refresh;
51
+ private fetchNewToken;
52
+ private resolveExpiryMs;
53
+ private extractServerUrl;
54
+ private emitTokenRefreshed;
55
+ getServerUrl(): string | undefined;
56
+ }
57
+
26
58
  interface SnapshotStatus$1 {
27
59
  status: 'NOT_FOUND' | 'READY' | 'INDEXING' | 'PENDING' | 'FAILED' | 'MISSING_CONTENT';
28
60
  snapshot_hash?: string;
@@ -50,12 +82,19 @@ interface HealthResponse$1 {
50
82
  version?: string;
51
83
  [key: string]: any;
52
84
  }
85
+ interface SyncClientConfig {
86
+ baseUrl?: string;
87
+ timeout?: number;
88
+ jwtProvider: JWTProvider;
89
+ }
53
90
  declare class SyncHttpClient {
54
91
  private baseUrl;
55
- private jwtToken;
56
92
  private timeout;
57
- private headers;
58
- constructor(baseUrl: string, jwtToken: string, timeout?: number);
93
+ private apiBase;
94
+ private readonly jwtProvider;
95
+ constructor({ baseUrl, timeout, jwtProvider, }: SyncClientConfig);
96
+ updateBaseUrl(baseUrl: string): void;
97
+ private configureBase;
59
98
  checkSnapshotStatus(snapshotHash: string): Promise<SnapshotStatus$1>;
60
99
  createSnapshot(snapshotHash: string, files: FileInfo[]): Promise<SnapshotStatus$1>;
61
100
  uploadFileContent(filesContent: Map<string, {
@@ -102,20 +141,94 @@ interface CacheStats {
102
141
  ttl: number;
103
142
  snapshots: string[];
104
143
  }
144
+ interface RetrievalClientConfig {
145
+ baseUrl?: string;
146
+ timeout?: number;
147
+ jwtProvider: JWTProvider;
148
+ }
105
149
  declare class RetrievalHttpClient {
106
150
  private baseUrl;
107
151
  private timeout;
108
152
  private apiBase;
109
- constructor(uri?: string, timeout?: number);
153
+ private readonly jwtProvider;
154
+ constructor({ baseUrl, timeout, jwtProvider, }: RetrievalClientConfig);
155
+ updateBaseUrl(baseUrl: string): void;
156
+ private configureBase;
110
157
  healthCheck(): Promise<HealthResponse>;
111
- query(snapshotHash: string, queryText: string, budgetTokens: number | undefined, jwt: string, options?: RetrievalOptions): Promise<RetrievalResult>;
112
- checkSnapshotStatus(snapshotHash: string, jwt: string): Promise<SnapshotStatus>;
113
- clearCache(jwt: string): Promise<boolean>;
114
- getCacheStats(jwt: string): Promise<CacheStats>;
115
- queryWithOptions(snapshotHash: string, queryText: string, jwt: string, budgetTokens?: number, flowStrength?: number, blendAlpha?: number, hopDepth?: number, maxIterations?: number, split?: number, formatter?: 'standard' | 'compact'): Promise<RetrievalResult>;
158
+ query(snapshotHash: string, queryText: string, budgetTokens?: number, options?: RetrievalOptions): Promise<RetrievalResult>;
159
+ checkSnapshotStatus(snapshotHash: string): Promise<SnapshotStatus>;
160
+ clearCache(): Promise<boolean>;
161
+ getCacheStats(): Promise<CacheStats>;
162
+ queryWithOptions(snapshotHash: string, queryText: string, budgetTokens?: number, flowStrength?: number, blendAlpha?: number, hopDepth?: number, maxIterations?: number, split?: number, formatter?: 'standard' | 'compact'): Promise<RetrievalResult>;
163
+ close(): void;
164
+ }
165
+
166
+ interface VisitorRulesV2 {
167
+ format: 'segments+exts@v2';
168
+ include_extensions: string[];
169
+ include_filenames: string[];
170
+ exclude_dirnames: string[];
171
+ }
172
+ interface HealthStatus {
173
+ status: 'OK' | 'NOT_READY';
174
+ message: string;
175
+ frontends_loaded: number;
176
+ info: Record<string, string>;
177
+ }
178
+ interface ASTClientConfig {
179
+ baseUrl?: string;
180
+ timeout?: number;
181
+ jwtProvider: JWTProvider;
182
+ }
183
+ declare class ASTHttpClient {
184
+ private baseUrl;
185
+ private timeout;
186
+ private apiBase;
187
+ private readonly jwtProvider;
188
+ constructor({ baseUrl, timeout, jwtProvider, }: ASTClientConfig);
189
+ updateBaseUrl(baseUrl: string): void;
190
+ private configureBase;
191
+ getVisitorRulesV2(): Promise<VisitorRulesV2>;
192
+ health(): Promise<HealthStatus>;
193
+ static compileRulesV2(rules: VisitorRulesV2): {
194
+ exts: Set<string>;
195
+ names: Set<string>;
196
+ dirRe: RegExp;
197
+ };
198
+ static buildIgnoredPredicate(compiled: ReturnType<typeof ASTHttpClient.compileRulesV2>): (path: string, stats?: any) => boolean;
199
+ close(): void;
200
+ }
201
+
202
+ type ServiceKey = 'auth' | 'ast' | 'retrieval' | 'sync';
203
+ interface ServiceConfig {
204
+ baseUrl?: string;
205
+ timeout?: number;
206
+ }
207
+ interface CoderuleClientOptions {
208
+ token: string;
209
+ baseUrl?: string;
210
+ auth?: ServiceConfig;
211
+ ast?: ServiceConfig;
212
+ retrieval?: ServiceConfig;
213
+ sync?: ServiceConfig;
214
+ jwtFactory?: JWTFactoryOptions;
215
+ }
216
+ declare class CoderuleClients {
217
+ readonly auth: AuthHttpClient;
218
+ readonly ast: ASTHttpClient;
219
+ readonly retrieval: RetrievalHttpClient;
220
+ readonly sync: SyncHttpClient;
221
+ readonly jwtFactory: JWTFactory;
222
+ private readonly serviceBaseLocked;
223
+ private lastServerUrl?;
224
+ constructor(options: CoderuleClientOptions);
225
+ get jwt(): JWTProvider;
226
+ getJWT(forceRefresh?: boolean): Promise<string>;
227
+ setToken(token: string): void;
116
228
  close(): void;
229
+ private applyServerUrl;
117
230
  }
118
231
 
119
232
  declare const fetch: typeof globalThis.fetch;
120
233
 
121
- export { AuthHttpClient, RetrievalHttpClient, SyncHttpClient, decodeJWT, fetch };
234
+ export { type ASTClientConfig, ASTHttpClient, AuthHttpClient, type CoderuleClientOptions, CoderuleClients, type HealthStatus, JWTFactory, type JWTFactoryOptions, type JWTProvider, type RetrievalClientConfig, RetrievalHttpClient, type ServiceConfig, type ServiceKey, type SyncClientConfig, SyncHttpClient, type TokenRefreshInfo, type VisitorRulesV2, decodeJWT, fetch };