@coderule/clients 1.4.0 → 1.6.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 +50 -2
- package/dist/index.cjs +95 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -6
- package/dist/index.d.ts +27 -6
- package/dist/index.js +94 -47
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,11 +29,12 @@ npm run build
|
|
|
29
29
|
### Unified client access
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
|
-
import { CoderuleClients } from '@coderule/clients';
|
|
32
|
+
import { CoderuleClients, consoleLogger } from '@coderule/clients';
|
|
33
33
|
|
|
34
34
|
const clients = new CoderuleClients({
|
|
35
35
|
token: process.env.CODERULE_TOKEN!,
|
|
36
36
|
auth: { baseUrl: 'https://r.coderule.ai:16803' }, // optional, defaults to this host
|
|
37
|
+
logger: consoleLogger, // optional, defaults to nullLogger (silent)
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
const snapshotStatus = await clients.sync.checkSnapshotStatus(snapshotHash);
|
|
@@ -257,13 +258,60 @@ const retrievalClient = new RetrievalHttpClient({
|
|
|
257
258
|
baseUrl: 'http://localhost:8004',
|
|
258
259
|
timeout: 30_000,
|
|
259
260
|
jwtProvider: jwtFactory,
|
|
261
|
+
logger: consoleLogger, // optional
|
|
260
262
|
});
|
|
261
263
|
```
|
|
262
264
|
`CoderuleClients` also accepts per-service overrides via the `auth`, `ast`, `retrieval`,
|
|
263
265
|
and `sync` options. `JWTFactory` exposes an `onTokenRefreshed` callback if you need to
|
|
264
266
|
observe token rotations (for example, to log the current `server_url`).
|
|
265
267
|
|
|
266
|
-
|
|
268
|
+
### Logging
|
|
269
|
+
|
|
270
|
+
The SDK includes a flexible logging interface that allows you to integrate with any logging library:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { Logger, nullLogger, consoleLogger } from '@coderule/clients';
|
|
274
|
+
|
|
275
|
+
// Use the built-in silent logger (default)
|
|
276
|
+
const silentClients = new CoderuleClients({
|
|
277
|
+
token,
|
|
278
|
+
logger: nullLogger, // or omit for default
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Use the built-in console logger for debugging
|
|
282
|
+
const debugClients = new CoderuleClients({
|
|
283
|
+
token,
|
|
284
|
+
logger: consoleLogger,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Implement your own logger
|
|
288
|
+
const customLogger: Logger = {
|
|
289
|
+
error: (message, ...meta) => myLogger.error(message, meta),
|
|
290
|
+
warn: (message, ...meta) => myLogger.warn(message, meta),
|
|
291
|
+
info: (message, ...meta) => myLogger.info(message, meta),
|
|
292
|
+
debug: (message, ...meta) => myLogger.debug(message, meta),
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const clients = new CoderuleClients({
|
|
296
|
+
token,
|
|
297
|
+
logger: customLogger,
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
All individual clients also accept an optional logger parameter:
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
const authClient = new AuthHttpClient('http://localhost:8001', 30000, consoleLogger);
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Breaking Changes
|
|
308
|
+
|
|
309
|
+
### v1.6.0
|
|
310
|
+
- **Logger interface added**: All clients now accept an optional `logger` parameter
|
|
311
|
+
- **Default behavior is silent**: By default, clients use `nullLogger` which produces no output
|
|
312
|
+
- **Backward compatible**: The logger parameter is optional, existing code continues to work
|
|
313
|
+
|
|
314
|
+
### v1.4.0
|
|
267
315
|
|
|
268
316
|
- **Clients now require a JWT provider**: `SyncHttpClient`, `RetrievalHttpClient`, and
|
|
269
317
|
`ASTHttpClient` no longer accept JWT strings per method. Inject a `JWTFactory` or any
|
package/dist/index.cjs
CHANGED
|
@@ -141,16 +141,37 @@ var FormData2 = fetchModule.FormData;
|
|
|
141
141
|
var AbortController2 = fetchModule.AbortController;
|
|
142
142
|
var fetch_wrapper_default = fetch2;
|
|
143
143
|
|
|
144
|
+
// src/utils/logger.ts
|
|
145
|
+
init_cjs_shims();
|
|
146
|
+
var nullLogger = {
|
|
147
|
+
error: () => {
|
|
148
|
+
},
|
|
149
|
+
warn: () => {
|
|
150
|
+
},
|
|
151
|
+
info: () => {
|
|
152
|
+
},
|
|
153
|
+
debug: () => {
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var consoleLogger = {
|
|
157
|
+
error: (message, ...meta) => console.error(message, ...meta),
|
|
158
|
+
warn: (message, ...meta) => console.warn(message, ...meta),
|
|
159
|
+
info: (message, ...meta) => console.info(message, ...meta),
|
|
160
|
+
debug: (message, ...meta) => console.debug(message, ...meta)
|
|
161
|
+
};
|
|
162
|
+
|
|
144
163
|
// src/clients/auth-client.ts
|
|
145
164
|
var AuthHttpClient = class {
|
|
146
165
|
/**
|
|
147
166
|
* Initialize the Auth HTTP client
|
|
148
167
|
* @param baseUrl - Base URL of the Auth service (e.g., "http://localhost:8001")
|
|
149
168
|
* @param timeout - Request timeout in milliseconds (default: 30000)
|
|
169
|
+
* @param logger - Optional logger instance (defaults to nullLogger)
|
|
150
170
|
*/
|
|
151
|
-
constructor(baseUrl, timeout = 3e4) {
|
|
171
|
+
constructor(baseUrl, timeout = 3e4, logger) {
|
|
152
172
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
153
173
|
this.timeout = timeout;
|
|
174
|
+
this.logger = logger ?? nullLogger;
|
|
154
175
|
}
|
|
155
176
|
/**
|
|
156
177
|
* Authenticate a token and receive a JWT
|
|
@@ -179,7 +200,7 @@ var AuthHttpClient = class {
|
|
|
179
200
|
);
|
|
180
201
|
}
|
|
181
202
|
const data = await response.json();
|
|
182
|
-
|
|
203
|
+
this.logger.debug(
|
|
183
204
|
`Authentication successful, JWT expires at ${data.expires_at}`
|
|
184
205
|
);
|
|
185
206
|
return data;
|
|
@@ -187,7 +208,7 @@ var AuthHttpClient = class {
|
|
|
187
208
|
if (error.name === "AbortError") {
|
|
188
209
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
189
210
|
}
|
|
190
|
-
|
|
211
|
+
this.logger.error(`Authentication request failed: ${error.message}`);
|
|
191
212
|
throw error;
|
|
192
213
|
}
|
|
193
214
|
}
|
|
@@ -213,13 +234,13 @@ var AuthHttpClient = class {
|
|
|
213
234
|
);
|
|
214
235
|
}
|
|
215
236
|
const data = await response.json();
|
|
216
|
-
|
|
237
|
+
this.logger.debug(`Health check: ${data.status}`);
|
|
217
238
|
return data;
|
|
218
239
|
} catch (error) {
|
|
219
240
|
if (error.name === "AbortError") {
|
|
220
241
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
221
242
|
}
|
|
222
|
-
|
|
243
|
+
this.logger.error(`Health check request failed: ${error.message}`);
|
|
223
244
|
throw error;
|
|
224
245
|
}
|
|
225
246
|
}
|
|
@@ -229,7 +250,7 @@ var AuthHttpClient = class {
|
|
|
229
250
|
close() {
|
|
230
251
|
}
|
|
231
252
|
};
|
|
232
|
-
function decodeJWT(jwtToken) {
|
|
253
|
+
function decodeJWT(jwtToken, logger) {
|
|
233
254
|
try {
|
|
234
255
|
const parts = jwtToken.split(".");
|
|
235
256
|
if (parts.length !== 3) {
|
|
@@ -243,13 +264,13 @@ function decodeJWT(jwtToken) {
|
|
|
243
264
|
if (payloadObj.exp) {
|
|
244
265
|
const now = Math.floor(Date.now() / 1e3);
|
|
245
266
|
if (payloadObj.exp < now) {
|
|
246
|
-
|
|
267
|
+
if (logger) logger.debug("JWT token is expired");
|
|
247
268
|
return null;
|
|
248
269
|
}
|
|
249
270
|
}
|
|
250
271
|
return payloadObj;
|
|
251
272
|
} catch (error) {
|
|
252
|
-
|
|
273
|
+
if (logger) logger.error("Failed to decode JWT:", error);
|
|
253
274
|
return null;
|
|
254
275
|
}
|
|
255
276
|
}
|
|
@@ -262,17 +283,20 @@ var SyncHttpClient = class {
|
|
|
262
283
|
* @param config.baseUrl - URI/URL for connecting to the HTTP server (e.g., "http://localhost:8002")
|
|
263
284
|
* @param config.timeout - Request timeout in milliseconds (default: 60000)
|
|
264
285
|
* @param config.jwtProvider - Provider for obtaining JWT tokens
|
|
286
|
+
* @param config.logger - Optional logger instance (defaults to nullLogger)
|
|
265
287
|
*/
|
|
266
288
|
constructor({
|
|
267
289
|
baseUrl = "http://localhost:8002",
|
|
268
290
|
timeout = 6e4,
|
|
269
|
-
jwtProvider
|
|
291
|
+
jwtProvider,
|
|
292
|
+
logger
|
|
270
293
|
}) {
|
|
271
294
|
if (!jwtProvider) {
|
|
272
295
|
throw new Error("SyncHttpClient requires a JWT provider");
|
|
273
296
|
}
|
|
274
297
|
this.timeout = timeout;
|
|
275
298
|
this.jwtProvider = jwtProvider;
|
|
299
|
+
this.logger = logger ?? nullLogger;
|
|
276
300
|
this.configureBase(baseUrl);
|
|
277
301
|
}
|
|
278
302
|
updateBaseUrl(baseUrl) {
|
|
@@ -335,7 +359,7 @@ var SyncHttpClient = class {
|
|
|
335
359
|
if (error.name === "AbortError") {
|
|
336
360
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
337
361
|
}
|
|
338
|
-
|
|
362
|
+
this.logger.error(`Request failed: ${error.message}`);
|
|
339
363
|
throw error;
|
|
340
364
|
}
|
|
341
365
|
}
|
|
@@ -370,7 +394,7 @@ var SyncHttpClient = class {
|
|
|
370
394
|
clearTimeout(timeoutId);
|
|
371
395
|
if (response.status === 422) {
|
|
372
396
|
const data2 = await response.json();
|
|
373
|
-
|
|
397
|
+
this.logger.info(
|
|
374
398
|
`Snapshot ${snapshotHash.substring(0, 8)}... missing ${data2.missing_files?.length || 0} files`
|
|
375
399
|
);
|
|
376
400
|
return data2;
|
|
@@ -382,7 +406,7 @@ var SyncHttpClient = class {
|
|
|
382
406
|
);
|
|
383
407
|
}
|
|
384
408
|
const data = await response.json();
|
|
385
|
-
|
|
409
|
+
this.logger.info(
|
|
386
410
|
`Snapshot ${snapshotHash.substring(0, 8)}... status: ${data.status}`
|
|
387
411
|
);
|
|
388
412
|
return data;
|
|
@@ -390,7 +414,7 @@ var SyncHttpClient = class {
|
|
|
390
414
|
if (error.name === "AbortError") {
|
|
391
415
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
392
416
|
}
|
|
393
|
-
|
|
417
|
+
this.logger.error(`Request failed: ${error.message}`);
|
|
394
418
|
throw error;
|
|
395
419
|
}
|
|
396
420
|
}
|
|
@@ -429,7 +453,7 @@ var SyncHttpClient = class {
|
|
|
429
453
|
);
|
|
430
454
|
}
|
|
431
455
|
const data = await response.json();
|
|
432
|
-
|
|
456
|
+
this.logger.info(
|
|
433
457
|
`Uploaded ${data.uploaded_count || 0} files, ${data.failed_count || 0} failed`
|
|
434
458
|
);
|
|
435
459
|
return data;
|
|
@@ -437,7 +461,7 @@ var SyncHttpClient = class {
|
|
|
437
461
|
if (error.name === "AbortError") {
|
|
438
462
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
439
463
|
}
|
|
440
|
-
|
|
464
|
+
this.logger.error(`Request failed: ${error.message}`);
|
|
441
465
|
throw error;
|
|
442
466
|
}
|
|
443
467
|
}
|
|
@@ -493,7 +517,7 @@ var SyncHttpClient = class {
|
|
|
493
517
|
if (error.name === "AbortError") {
|
|
494
518
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
495
519
|
}
|
|
496
|
-
|
|
520
|
+
this.logger.error(`Request failed: ${error.message}`);
|
|
497
521
|
throw error;
|
|
498
522
|
}
|
|
499
523
|
}
|
|
@@ -512,20 +536,23 @@ var RetrievalHttpClient = class {
|
|
|
512
536
|
* @param config.baseUrl - URI/URL for connecting to the HTTP server (e.g., "http://localhost:8004")
|
|
513
537
|
* @param config.timeout - Request timeout in milliseconds (default: 60000)
|
|
514
538
|
* @param config.jwtProvider - Provider for obtaining JWT tokens
|
|
539
|
+
* @param config.logger - Optional logger instance (defaults to nullLogger)
|
|
515
540
|
*/
|
|
516
541
|
constructor({
|
|
517
542
|
baseUrl = "http://localhost:8004",
|
|
518
543
|
timeout = 6e4,
|
|
519
|
-
jwtProvider
|
|
544
|
+
jwtProvider,
|
|
545
|
+
logger
|
|
520
546
|
}) {
|
|
521
547
|
if (!jwtProvider) {
|
|
522
548
|
throw new Error("RetrievalHttpClient requires a JWT provider");
|
|
523
549
|
}
|
|
524
550
|
this.timeout = timeout;
|
|
525
551
|
this.jwtProvider = jwtProvider;
|
|
552
|
+
this.logger = logger ?? nullLogger;
|
|
526
553
|
this.configureBase(baseUrl);
|
|
527
|
-
|
|
528
|
-
|
|
554
|
+
this.logger.debug(`Initialized HTTP client for ${this.baseUrl}`);
|
|
555
|
+
this.logger.debug(`API base: ${this.apiBase}`);
|
|
529
556
|
}
|
|
530
557
|
updateBaseUrl(baseUrl) {
|
|
531
558
|
this.configureBase(baseUrl);
|
|
@@ -554,7 +581,7 @@ var RetrievalHttpClient = class {
|
|
|
554
581
|
*/
|
|
555
582
|
async healthCheck() {
|
|
556
583
|
const healthEndpoint = `${this.apiBase}health`;
|
|
557
|
-
|
|
584
|
+
this.logger.debug(`Checking server health: ${healthEndpoint}`);
|
|
558
585
|
try {
|
|
559
586
|
const controller = new AbortController2();
|
|
560
587
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
@@ -570,7 +597,7 @@ var RetrievalHttpClient = class {
|
|
|
570
597
|
);
|
|
571
598
|
}
|
|
572
599
|
const healthInfo = await response.json();
|
|
573
|
-
|
|
600
|
+
this.logger.debug(`HTTP retrieval server status:`, healthInfo);
|
|
574
601
|
return {
|
|
575
602
|
status: healthInfo.status || "UNKNOWN",
|
|
576
603
|
database: healthInfo.database || "UNKNOWN",
|
|
@@ -583,7 +610,7 @@ var RetrievalHttpClient = class {
|
|
|
583
610
|
if (error.name === "AbortError") {
|
|
584
611
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
585
612
|
}
|
|
586
|
-
|
|
613
|
+
this.logger.error(`Error checking HTTP server health: ${error.message}`);
|
|
587
614
|
throw new Error(
|
|
588
615
|
`Unable to connect to HTTP server ${this.baseUrl}: ${error.message}`
|
|
589
616
|
);
|
|
@@ -647,7 +674,7 @@ var RetrievalHttpClient = class {
|
|
|
647
674
|
const result = await response.json();
|
|
648
675
|
const elapsedTime = (Date.now() - startTime) / 1e3;
|
|
649
676
|
const formatter = options?.formatter || "standard";
|
|
650
|
-
|
|
677
|
+
this.logger.debug(
|
|
651
678
|
`Retrieval query completed for snapshot ${snapshotHash.substring(0, 8)}... Formatter: ${formatter}. Total time: ${elapsedTime.toFixed(2)}s`
|
|
652
679
|
);
|
|
653
680
|
return result;
|
|
@@ -655,7 +682,7 @@ var RetrievalHttpClient = class {
|
|
|
655
682
|
if (error.name === "AbortError") {
|
|
656
683
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
657
684
|
}
|
|
658
|
-
|
|
685
|
+
this.logger.error(`Error executing retrieval query: ${error.message}`);
|
|
659
686
|
throw new Error(`Failed to execute retrieval query: ${error.message}`);
|
|
660
687
|
}
|
|
661
688
|
}
|
|
@@ -697,7 +724,7 @@ var RetrievalHttpClient = class {
|
|
|
697
724
|
);
|
|
698
725
|
}
|
|
699
726
|
const statusInfo = await response.json();
|
|
700
|
-
|
|
727
|
+
this.logger.debug(
|
|
701
728
|
`Snapshot ${snapshotHash.substring(0, 8)}... status: ${statusInfo.status}`
|
|
702
729
|
);
|
|
703
730
|
return statusInfo;
|
|
@@ -705,7 +732,7 @@ var RetrievalHttpClient = class {
|
|
|
705
732
|
if (error.name === "AbortError") {
|
|
706
733
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
707
734
|
}
|
|
708
|
-
|
|
735
|
+
this.logger.error(`Error checking snapshot status: ${error.message}`);
|
|
709
736
|
throw new Error(`Failed to check snapshot status: ${error.message}`);
|
|
710
737
|
}
|
|
711
738
|
}
|
|
@@ -735,13 +762,13 @@ var RetrievalHttpClient = class {
|
|
|
735
762
|
`Cache clear failed with status ${response.status}: ${errorText}`
|
|
736
763
|
);
|
|
737
764
|
}
|
|
738
|
-
|
|
765
|
+
this.logger.info("Graph cache cleared successfully");
|
|
739
766
|
return true;
|
|
740
767
|
} catch (error) {
|
|
741
768
|
if (error.name === "AbortError") {
|
|
742
769
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
743
770
|
}
|
|
744
|
-
|
|
771
|
+
this.logger.error(`Error clearing cache: ${error.message}`);
|
|
745
772
|
throw new Error(`Failed to clear cache: ${error.message}`);
|
|
746
773
|
}
|
|
747
774
|
}
|
|
@@ -772,7 +799,7 @@ var RetrievalHttpClient = class {
|
|
|
772
799
|
);
|
|
773
800
|
}
|
|
774
801
|
const stats = await response.json();
|
|
775
|
-
|
|
802
|
+
this.logger.debug(
|
|
776
803
|
`Cache stats: ${stats.cached_snapshots || 0} snapshots cached`
|
|
777
804
|
);
|
|
778
805
|
return stats;
|
|
@@ -780,7 +807,7 @@ var RetrievalHttpClient = class {
|
|
|
780
807
|
if (error.name === "AbortError") {
|
|
781
808
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
782
809
|
}
|
|
783
|
-
|
|
810
|
+
this.logger.error(`Error getting cache stats: ${error.message}`);
|
|
784
811
|
throw new Error(`Failed to get cache stats: ${error.message}`);
|
|
785
812
|
}
|
|
786
813
|
}
|
|
@@ -824,17 +851,20 @@ var ASTHttpClient = class {
|
|
|
824
851
|
* @param config.baseUrl - URI/URL for connecting to the HTTP server (e.g., "http://localhost:8003")
|
|
825
852
|
* @param config.timeout - Request timeout in milliseconds (default: 60000)
|
|
826
853
|
* @param config.jwtProvider - Provider for obtaining JWT tokens
|
|
854
|
+
* @param config.logger - Optional logger instance (defaults to nullLogger)
|
|
827
855
|
*/
|
|
828
856
|
constructor({
|
|
829
857
|
baseUrl = "http://localhost:8003",
|
|
830
858
|
timeout = 6e4,
|
|
831
|
-
jwtProvider
|
|
859
|
+
jwtProvider,
|
|
860
|
+
logger
|
|
832
861
|
}) {
|
|
833
862
|
if (!jwtProvider) {
|
|
834
863
|
throw new Error("ASTHttpClient requires a JWT provider");
|
|
835
864
|
}
|
|
836
865
|
this.timeout = timeout;
|
|
837
866
|
this.jwtProvider = jwtProvider;
|
|
867
|
+
this.logger = logger ?? nullLogger;
|
|
838
868
|
this.configureBase(baseUrl);
|
|
839
869
|
}
|
|
840
870
|
updateBaseUrl(baseUrl) {
|
|
@@ -891,7 +921,7 @@ var ASTHttpClient = class {
|
|
|
891
921
|
if (error.name === "AbortError") {
|
|
892
922
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
893
923
|
}
|
|
894
|
-
|
|
924
|
+
this.logger.error(`Failed to get visitor rules v2: ${error.message}`);
|
|
895
925
|
throw error;
|
|
896
926
|
}
|
|
897
927
|
}
|
|
@@ -923,7 +953,7 @@ var ASTHttpClient = class {
|
|
|
923
953
|
if (error.name === "AbortError") {
|
|
924
954
|
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
925
955
|
}
|
|
926
|
-
|
|
956
|
+
this.logger.error(`Health check failed: ${error.message}`);
|
|
927
957
|
throw error;
|
|
928
958
|
}
|
|
929
959
|
}
|
|
@@ -946,7 +976,7 @@ var ASTHttpClient = class {
|
|
|
946
976
|
`(?:^|[\\/])(?:${[...dirs].map(escapeRe).join("|")})(?:[\\/]|$)`,
|
|
947
977
|
"i"
|
|
948
978
|
);
|
|
949
|
-
return { exts, names, dirRe };
|
|
979
|
+
return { exts, names, dirRe, dirs };
|
|
950
980
|
}
|
|
951
981
|
/**
|
|
952
982
|
* Build Chokidar v4 `ignored` predicate from compiled rules
|
|
@@ -956,8 +986,19 @@ var ASTHttpClient = class {
|
|
|
956
986
|
static buildIgnoredPredicate(compiled) {
|
|
957
987
|
return (p, stats) => {
|
|
958
988
|
const posix = p.replace(/\\/g, "/");
|
|
959
|
-
|
|
960
|
-
|
|
989
|
+
const parts = posix.split("/").map((segment) => segment.toLowerCase());
|
|
990
|
+
const isDirectory = stats?.isDirectory?.() ?? false;
|
|
991
|
+
if (isDirectory) {
|
|
992
|
+
const current = parts[parts.length - 1];
|
|
993
|
+
if (compiled.dirs.has(current)) {
|
|
994
|
+
return true;
|
|
995
|
+
}
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
const parentDirs = parts.slice(0, -1);
|
|
999
|
+
if (parentDirs.some((segment) => compiled.dirs.has(segment))) {
|
|
1000
|
+
return true;
|
|
1001
|
+
}
|
|
961
1002
|
const base = posix.split("/").pop()?.toLowerCase() || "";
|
|
962
1003
|
if (compiled.names.has(base)) return false;
|
|
963
1004
|
const extIndex = base.lastIndexOf(".");
|
|
@@ -985,6 +1026,7 @@ var JWTFactory = class {
|
|
|
985
1026
|
}
|
|
986
1027
|
this.minTtlMs = options.minTtlMs ?? DEFAULT_MIN_TTL_MS;
|
|
987
1028
|
this.onTokenRefreshed = options.onTokenRefreshed;
|
|
1029
|
+
this.logger = options.logger ?? nullLogger;
|
|
988
1030
|
}
|
|
989
1031
|
setSourceToken(token) {
|
|
990
1032
|
if (!token) {
|
|
@@ -1023,7 +1065,7 @@ var JWTFactory = class {
|
|
|
1023
1065
|
return await this.refreshPromise;
|
|
1024
1066
|
} catch (error) {
|
|
1025
1067
|
if (!forceRefresh && this.cache && now < this.cache.expiresAt) {
|
|
1026
|
-
|
|
1068
|
+
this.logger.warn(
|
|
1027
1069
|
"Failed to refresh JWT, using cached token until expiry. Reason:",
|
|
1028
1070
|
error
|
|
1029
1071
|
);
|
|
@@ -1066,7 +1108,7 @@ var JWTFactory = class {
|
|
|
1066
1108
|
return parsed;
|
|
1067
1109
|
}
|
|
1068
1110
|
}
|
|
1069
|
-
const decoded = decodeJWT(jwt);
|
|
1111
|
+
const decoded = decodeJWT(jwt, this.logger);
|
|
1070
1112
|
if (decoded?.exp) {
|
|
1071
1113
|
const expMs = decoded.exp * 1e3;
|
|
1072
1114
|
if (expMs > referenceTime + this.minTtlMs) {
|
|
@@ -1087,7 +1129,7 @@ var JWTFactory = class {
|
|
|
1087
1129
|
try {
|
|
1088
1130
|
this.onTokenRefreshed(info);
|
|
1089
1131
|
} catch (error) {
|
|
1090
|
-
|
|
1132
|
+
this.logger.warn("JWTFactory onTokenRefreshed callback failed:", error);
|
|
1091
1133
|
}
|
|
1092
1134
|
}
|
|
1093
1135
|
}
|
|
@@ -1122,14 +1164,16 @@ var CoderuleClients = class {
|
|
|
1122
1164
|
if (!options?.token) {
|
|
1123
1165
|
throw new Error("CoderuleClients requires a non-empty token");
|
|
1124
1166
|
}
|
|
1167
|
+
this.logger = options.logger ?? nullLogger;
|
|
1125
1168
|
const overrides = resolveOverrides(options);
|
|
1126
1169
|
const baseUrl = options.baseUrl;
|
|
1127
1170
|
const authBase = overrides.auth?.baseUrl ?? baseUrl ?? DEFAULT_AUTH_BASE_URL;
|
|
1128
1171
|
const authTimeout = resolveTimeout("auth", overrides);
|
|
1129
|
-
this.auth = new AuthHttpClient(authBase, authTimeout);
|
|
1172
|
+
this.auth = new AuthHttpClient(authBase, authTimeout, this.logger);
|
|
1130
1173
|
const userTokenCallback = options.jwtFactory?.onTokenRefreshed;
|
|
1131
1174
|
const jwtOptions = {
|
|
1132
1175
|
...options.jwtFactory,
|
|
1176
|
+
logger: this.logger,
|
|
1133
1177
|
onTokenRefreshed: (info) => {
|
|
1134
1178
|
userTokenCallback?.(info);
|
|
1135
1179
|
if (info.serverUrl) {
|
|
@@ -1147,17 +1191,20 @@ var CoderuleClients = class {
|
|
|
1147
1191
|
this.ast = new ASTHttpClient({
|
|
1148
1192
|
baseUrl: overrides.ast?.baseUrl ?? defaultServiceBase,
|
|
1149
1193
|
timeout: resolveTimeout("ast", overrides),
|
|
1150
|
-
jwtProvider: this.jwtFactory
|
|
1194
|
+
jwtProvider: this.jwtFactory,
|
|
1195
|
+
logger: this.logger
|
|
1151
1196
|
});
|
|
1152
1197
|
this.retrieval = new RetrievalHttpClient({
|
|
1153
1198
|
baseUrl: overrides.retrieval?.baseUrl ?? defaultServiceBase,
|
|
1154
1199
|
timeout: resolveTimeout("retrieval", overrides),
|
|
1155
|
-
jwtProvider: this.jwtFactory
|
|
1200
|
+
jwtProvider: this.jwtFactory,
|
|
1201
|
+
logger: this.logger
|
|
1156
1202
|
});
|
|
1157
1203
|
this.sync = new SyncHttpClient({
|
|
1158
1204
|
baseUrl: overrides.sync?.baseUrl ?? defaultServiceBase,
|
|
1159
1205
|
timeout: resolveTimeout("sync", overrides),
|
|
1160
|
-
jwtProvider: this.jwtFactory
|
|
1206
|
+
jwtProvider: this.jwtFactory,
|
|
1207
|
+
logger: this.logger
|
|
1161
1208
|
});
|
|
1162
1209
|
const initialServerUrl = this.jwtFactory.getServerUrl();
|
|
1163
1210
|
if (initialServerUrl) {
|
|
@@ -1190,21 +1237,21 @@ var CoderuleClients = class {
|
|
|
1190
1237
|
this.ast.updateBaseUrl(trimmed);
|
|
1191
1238
|
}
|
|
1192
1239
|
} catch (error) {
|
|
1193
|
-
|
|
1240
|
+
this.logger.warn("Failed to update AST client base URL:", error);
|
|
1194
1241
|
}
|
|
1195
1242
|
try {
|
|
1196
1243
|
if (!this.serviceBaseLocked.retrieval) {
|
|
1197
1244
|
this.retrieval.updateBaseUrl(trimmed);
|
|
1198
1245
|
}
|
|
1199
1246
|
} catch (error) {
|
|
1200
|
-
|
|
1247
|
+
this.logger.warn("Failed to update Retrieval client base URL:", error);
|
|
1201
1248
|
}
|
|
1202
1249
|
try {
|
|
1203
1250
|
if (!this.serviceBaseLocked.sync) {
|
|
1204
1251
|
this.sync.updateBaseUrl(trimmed);
|
|
1205
1252
|
}
|
|
1206
1253
|
} catch (error) {
|
|
1207
|
-
|
|
1254
|
+
this.logger.warn("Failed to update Sync client base URL:", error);
|
|
1208
1255
|
}
|
|
1209
1256
|
}
|
|
1210
1257
|
};
|
|
@@ -1215,7 +1262,9 @@ exports.CoderuleClients = CoderuleClients;
|
|
|
1215
1262
|
exports.JWTFactory = JWTFactory;
|
|
1216
1263
|
exports.RetrievalHttpClient = RetrievalHttpClient;
|
|
1217
1264
|
exports.SyncHttpClient = SyncHttpClient;
|
|
1265
|
+
exports.consoleLogger = consoleLogger;
|
|
1218
1266
|
exports.decodeJWT = decodeJWT;
|
|
1219
1267
|
exports.fetch = fetch_wrapper_default;
|
|
1268
|
+
exports.nullLogger = nullLogger;
|
|
1220
1269
|
//# sourceMappingURL=index.cjs.map
|
|
1221
1270
|
//# sourceMappingURL=index.cjs.map
|