@coderule/clients 1.2.0 → 1.5.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,17 +82,25 @@ 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
92
  private timeout;
56
93
  private apiBase;
57
- constructor(uri?: string, timeout?: number);
58
- checkSnapshotStatus(snapshotHash: string, jwt: string): Promise<SnapshotStatus$1>;
59
- createSnapshot(snapshotHash: string, files: FileInfo[], jwt: string): Promise<SnapshotStatus$1>;
94
+ private readonly jwtProvider;
95
+ constructor({ baseUrl, timeout, jwtProvider, }: SyncClientConfig);
96
+ updateBaseUrl(baseUrl: string): void;
97
+ private configureBase;
98
+ checkSnapshotStatus(snapshotHash: string): Promise<SnapshotStatus$1>;
99
+ createSnapshot(snapshotHash: string, files: FileInfo[]): Promise<SnapshotStatus$1>;
60
100
  uploadFileContent(filesContent: Map<string, {
61
101
  path: string;
62
102
  content: Buffer | string;
63
- }>, jwt: string): Promise<UploadResult>;
103
+ }>): Promise<UploadResult>;
64
104
  static calculateFileHash(filePath: string, content: Buffer | string): string;
65
105
  static calculateSnapshotHash(fileHashes: string[]): string;
66
106
  health(): Promise<HealthResponse$1>;
@@ -101,17 +141,25 @@ interface CacheStats {
101
141
  ttl: number;
102
142
  snapshots: string[];
103
143
  }
144
+ interface RetrievalClientConfig {
145
+ baseUrl?: string;
146
+ timeout?: number;
147
+ jwtProvider: JWTProvider;
148
+ }
104
149
  declare class RetrievalHttpClient {
105
150
  private baseUrl;
106
151
  private timeout;
107
152
  private apiBase;
108
- constructor(uri?: string, timeout?: number);
153
+ private readonly jwtProvider;
154
+ constructor({ baseUrl, timeout, jwtProvider, }: RetrievalClientConfig);
155
+ updateBaseUrl(baseUrl: string): void;
156
+ private configureBase;
109
157
  healthCheck(): Promise<HealthResponse>;
110
- query(snapshotHash: string, queryText: string, budgetTokens: number | undefined, jwt: string, options?: RetrievalOptions): Promise<RetrievalResult>;
111
- checkSnapshotStatus(snapshotHash: string, jwt: string): Promise<SnapshotStatus>;
112
- clearCache(jwt: string): Promise<boolean>;
113
- getCacheStats(jwt: string): Promise<CacheStats>;
114
- 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>;
115
163
  close(): void;
116
164
  }
117
165
 
@@ -127,22 +175,61 @@ interface HealthStatus {
127
175
  frontends_loaded: number;
128
176
  info: Record<string, string>;
129
177
  }
178
+ interface ASTClientConfig {
179
+ baseUrl?: string;
180
+ timeout?: number;
181
+ jwtProvider: JWTProvider;
182
+ }
130
183
  declare class ASTHttpClient {
131
184
  private baseUrl;
132
185
  private timeout;
133
186
  private apiBase;
134
- constructor(uri?: string, timeout?: number);
135
- getVisitorRulesV2(jwt: string): Promise<VisitorRulesV2>;
187
+ private readonly jwtProvider;
188
+ constructor({ baseUrl, timeout, jwtProvider, }: ASTClientConfig);
189
+ updateBaseUrl(baseUrl: string): void;
190
+ private configureBase;
191
+ getVisitorRulesV2(): Promise<VisitorRulesV2>;
136
192
  health(): Promise<HealthStatus>;
137
193
  static compileRulesV2(rules: VisitorRulesV2): {
138
194
  exts: Set<string>;
139
195
  names: Set<string>;
140
196
  dirRe: RegExp;
197
+ dirs: Set<string>;
141
198
  };
142
199
  static buildIgnoredPredicate(compiled: ReturnType<typeof ASTHttpClient.compileRulesV2>): (path: string, stats?: any) => boolean;
143
200
  close(): void;
144
201
  }
145
202
 
203
+ type ServiceKey = 'auth' | 'ast' | 'retrieval' | 'sync';
204
+ interface ServiceConfig {
205
+ baseUrl?: string;
206
+ timeout?: number;
207
+ }
208
+ interface CoderuleClientOptions {
209
+ token: string;
210
+ baseUrl?: string;
211
+ auth?: ServiceConfig;
212
+ ast?: ServiceConfig;
213
+ retrieval?: ServiceConfig;
214
+ sync?: ServiceConfig;
215
+ jwtFactory?: JWTFactoryOptions;
216
+ }
217
+ declare class CoderuleClients {
218
+ readonly auth: AuthHttpClient;
219
+ readonly ast: ASTHttpClient;
220
+ readonly retrieval: RetrievalHttpClient;
221
+ readonly sync: SyncHttpClient;
222
+ readonly jwtFactory: JWTFactory;
223
+ private readonly serviceBaseLocked;
224
+ private lastServerUrl?;
225
+ constructor(options: CoderuleClientOptions);
226
+ get jwt(): JWTProvider;
227
+ getJWT(forceRefresh?: boolean): Promise<string>;
228
+ setToken(token: string): void;
229
+ close(): void;
230
+ private applyServerUrl;
231
+ }
232
+
146
233
  declare const fetch: typeof globalThis.fetch;
147
234
 
148
- export { ASTHttpClient, AuthHttpClient, type HealthStatus, RetrievalHttpClient, SyncHttpClient, type VisitorRulesV2, decodeJWT, fetch };
235
+ 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 };