@timeback/core 0.2.4-beta.20260401002024 → 0.2.4-beta.20260403024308

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.
@@ -8,7 +8,7 @@ import {
8
8
  validateNonEmptyString,
9
9
  validateUuid,
10
10
  validateWithSchema
11
- } from "./chunk-bjb7ngh9.js";
11
+ } from "./chunk-9yh4rvkr.js";
12
12
 
13
13
  // ../edubridge/src/utils.ts
14
14
  var log = createScopedLogger("edubridge");
@@ -224,6 +224,13 @@ var StringTimebackGrade = z.string().transform((value, ctx) => {
224
224
  return z.NEVER;
225
225
  }
226
226
  const stripped = raw.replace(/\bgrade\b/g, "").replace(/(\d+)(st|nd|rd|th)\b/g, "$1").trim();
227
+ if (stripped === "") {
228
+ ctx.addIssue({
229
+ code: "custom",
230
+ message: "must be a valid Timeback grade"
231
+ });
232
+ return z.NEVER;
233
+ }
227
234
  if (stripped === "pre-k" || stripped === "pk") {
228
235
  return -1;
229
236
  }
@@ -68,6 +68,17 @@ var TYPESCRIPT_RUNNER = {
68
68
  var patterns = null;
69
69
  var debugAll = false;
70
70
  var debugEnvSet = false;
71
+ function hasDebugOptIn() {
72
+ try {
73
+ const debugValue = process.env.DEBUG?.trim();
74
+ if (!debugValue) {
75
+ return false;
76
+ }
77
+ return debugValue.split(",").some((part) => part.trim().length > 0);
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
71
82
  function patternToRegex(pattern) {
72
83
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
73
84
  const regexStr = escaped.replace(/\*/g, ".*");
@@ -77,7 +88,7 @@ function parseDebugEnv() {
77
88
  if (patterns !== null)
78
89
  return;
79
90
  patterns = [];
80
- if (typeof process === "undefined" || !process.env?.DEBUG) {
91
+ if (!hasDebugOptIn()) {
81
92
  debugEnvSet = false;
82
93
  return;
83
94
  }
@@ -299,6 +310,19 @@ var browserFormatter = (entry) => {
299
310
  };
300
311
  // ../../internal/logger/src/logger.ts
301
312
  var LOG_LEVELS = ["debug", "info", "warn", "error"];
313
+ var GLOBAL_LOGGING_CONFIG_KEY = Symbol.for("@timeback/internal-logger/config");
314
+ function shouldUseSilentFormatter() {
315
+ try {
316
+ return process.env["TIMEBACK_INTERNAL_LOGGER"] === "silent";
317
+ } catch {
318
+ return false;
319
+ }
320
+ }
321
+ function getGlobalLoggingConfig() {
322
+ const globalState = globalThis;
323
+ globalState[GLOBAL_LOGGING_CONFIG_KEY] ??= {};
324
+ return globalState[GLOBAL_LOGGING_CONFIG_KEY];
325
+ }
302
326
  function getFormatter(env) {
303
327
  switch (env) {
304
328
  case "terminal":
@@ -314,11 +338,14 @@ function getFormatter(env) {
314
338
  }
315
339
  }
316
340
  function getDefaultMinLevel() {
317
- if (typeof process !== "undefined" && process.env?.DEBUG) {
341
+ if (hasDebugOptIn()) {
318
342
  return "debug";
319
343
  }
320
344
  return "info";
321
345
  }
346
+ function getConfiguredFormatter(env, formatter) {
347
+ return formatter ?? getGlobalLoggingConfig().formatter ?? (shouldUseSilentFormatter() ? () => {} : getFormatter(env));
348
+ }
322
349
  function shouldLog(level, minLevel) {
323
350
  return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(minLevel);
324
351
  }
@@ -327,14 +354,14 @@ class Logger {
327
354
  scope;
328
355
  minLevel;
329
356
  environment;
330
- formatter;
357
+ explicitFormatter;
331
358
  defaultContext;
332
359
  constructor(options = {}) {
333
360
  this.scope = options.scope;
334
361
  this.minLevel = options.minLevel ?? getDefaultMinLevel();
335
362
  this.defaultContext = options.defaultContext ?? {};
336
363
  this.environment = options.environment ?? detectEnvironment();
337
- this.formatter = getFormatter(this.environment);
364
+ this.explicitFormatter = options.formatter;
338
365
  }
339
366
  child(scope) {
340
367
  const childScope = this.scope ? `${this.scope}:${scope}` : scope;
@@ -342,7 +369,8 @@ class Logger {
342
369
  scope: childScope,
343
370
  minLevel: this.minLevel,
344
371
  environment: this.environment,
345
- defaultContext: { ...this.defaultContext }
372
+ defaultContext: { ...this.defaultContext },
373
+ formatter: this.explicitFormatter
346
374
  });
347
375
  }
348
376
  withContext(context) {
@@ -350,7 +378,8 @@ class Logger {
350
378
  scope: this.scope,
351
379
  minLevel: this.minLevel,
352
380
  environment: this.environment,
353
- defaultContext: { ...this.defaultContext, ...context }
381
+ defaultContext: { ...this.defaultContext, ...context },
382
+ formatter: this.explicitFormatter
354
383
  });
355
384
  }
356
385
  debug(message, context) {
@@ -379,7 +408,7 @@ class Logger {
379
408
  context: context || Object.keys(this.defaultContext).length > 0 ? { ...this.defaultContext, ...context } : undefined,
380
409
  timestamp: new Date
381
410
  };
382
- this.formatter(entry);
411
+ getConfiguredFormatter(this.environment, this.explicitFormatter)(entry);
383
412
  }
384
413
  }
385
414
  function createLogger(options = {}) {
@@ -394,7 +423,6 @@ function isDebug() {
394
423
  return false;
395
424
  }
396
425
  }
397
- var log = createLogger({ scope: "auth", minLevel: isDebug() ? "debug" : "warn" });
398
426
 
399
427
  class TokenManager {
400
428
  config;
@@ -402,17 +430,22 @@ class TokenManager {
402
430
  tokenExpiry = 0;
403
431
  pendingRequest = null;
404
432
  fetchFn;
433
+ log;
405
434
  constructor(config) {
406
435
  this.config = config;
407
436
  this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
437
+ this.log = config.logger ?? createLogger({
438
+ scope: "auth",
439
+ minLevel: isDebug() ? "debug" : "warn"
440
+ });
408
441
  }
409
442
  async getToken() {
410
443
  if (this.accessToken && Date.now() < this.tokenExpiry) {
411
- log.debug("Using cached token");
444
+ this.log.debug("Using cached token");
412
445
  return this.accessToken;
413
446
  }
414
447
  if (this.pendingRequest) {
415
- log.debug("Waiting for in-flight token request");
448
+ this.log.debug("Waiting for in-flight token request");
416
449
  return this.pendingRequest;
417
450
  }
418
451
  this.pendingRequest = this.fetchToken();
@@ -423,7 +456,7 @@ class TokenManager {
423
456
  }
424
457
  }
425
458
  async fetchToken() {
426
- log.debug("Fetching new access token...");
459
+ this.log.debug("Fetching new access token...");
427
460
  const { clientId, clientSecret } = this.config.credentials;
428
461
  const credentials = btoa(`${clientId}:${clientSecret}`);
429
462
  const start = performance.now();
@@ -437,17 +470,17 @@ class TokenManager {
437
470
  });
438
471
  const duration = Math.round(performance.now() - start);
439
472
  if (!response.ok) {
440
- log.error(`Token request failed: ${response.status} ${response.statusText}`);
473
+ this.log.error(`Token request failed: ${response.status} ${response.statusText}`);
441
474
  throw new Error(`Failed to obtain access token: ${response.status} ${response.statusText}`);
442
475
  }
443
476
  const data = await response.json();
444
477
  this.accessToken = data.access_token;
445
478
  this.tokenExpiry = Date.now() + (data.expires_in - 60) * 1000;
446
- log.debug(`Token acquired (${duration}ms, expires in ${data.expires_in}s)`);
479
+ this.log.debug(`Token acquired (${duration}ms, expires in ${data.expires_in}s)`);
447
480
  return this.accessToken;
448
481
  }
449
482
  invalidate() {
450
- log.debug("Token invalidated");
483
+ this.log.debug("Token invalidated");
451
484
  this.accessToken = null;
452
485
  this.tokenExpiry = 0;
453
486
  }
package/dist/errors.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  NotFoundError,
5
5
  UnauthorizedError,
6
6
  ValidationError
7
- } from "./chunk-bjb7ngh9.js";
7
+ } from "./chunk-9yh4rvkr.js";
8
8
  import"./chunk-3j7jywnx.js";
9
9
  export {
10
10
  ValidationError,
package/dist/index.js CHANGED
@@ -85,7 +85,7 @@ import {
85
85
  WebhookFilterCreateInput,
86
86
  WebhookFilterUpdateInput,
87
87
  WebhookUpdateInput
88
- } from "./chunk-jqy7m30q.js";
88
+ } from "./chunk-988xrzn7.js";
89
89
  import {
90
90
  ApiError,
91
91
  BaseTransport,
@@ -112,7 +112,7 @@ import {
112
112
  validateUuid,
113
113
  validateWithSchema,
114
114
  whereToFilter
115
- } from "./chunk-bjb7ngh9.js";
115
+ } from "./chunk-9yh4rvkr.js";
116
116
  import {
117
117
  CALIPER_DATA_VERSION,
118
118
  CALIPER_ENV_VARS,
package/dist/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  aggregateActivityMetrics
3
- } from "./chunk-jqy7m30q.js";
4
- import"./chunk-bjb7ngh9.js";
3
+ } from "./chunk-988xrzn7.js";
4
+ import"./chunk-9yh4rvkr.js";
5
5
  import"./chunk-3j7jywnx.js";
6
6
  export {
7
7
  aggregateActivityMetrics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timeback/core",
3
- "version": "0.2.4-beta.20260401002024",
3
+ "version": "0.2.4-beta.20260403024308",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {