@timeback/case 0.1.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 (40) hide show
  1. package/dist/client.d.ts +42 -0
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/constants.d.ts +29 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/errors.d.ts +1 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/errors.js +1730 -0
  8. package/dist/factory.d.ts +42 -0
  9. package/dist/factory.d.ts.map +1 -0
  10. package/dist/index.d.ts +560 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +16966 -0
  13. package/dist/lib/index.d.ts +7 -0
  14. package/dist/lib/index.d.ts.map +1 -0
  15. package/dist/lib/resolve.d.ts +19 -0
  16. package/dist/lib/resolve.d.ts.map +1 -0
  17. package/dist/lib/transport.d.ts +27 -0
  18. package/dist/lib/transport.d.ts.map +1 -0
  19. package/dist/public-types.d.ts +327 -0
  20. package/dist/public-types.d.ts.map +1 -0
  21. package/dist/public-types.js +0 -0
  22. package/dist/resources/associations.d.ts +21 -0
  23. package/dist/resources/associations.d.ts.map +1 -0
  24. package/dist/resources/documents.d.ts +30 -0
  25. package/dist/resources/documents.d.ts.map +1 -0
  26. package/dist/resources/index.d.ts +8 -0
  27. package/dist/resources/index.d.ts.map +1 -0
  28. package/dist/resources/items.d.ts +30 -0
  29. package/dist/resources/items.d.ts.map +1 -0
  30. package/dist/resources/packages.d.ts +45 -0
  31. package/dist/resources/packages.d.ts.map +1 -0
  32. package/dist/types/client.d.ts +38 -0
  33. package/dist/types/client.d.ts.map +1 -0
  34. package/dist/types/index.d.ts +4 -0
  35. package/dist/types/index.d.ts.map +1 -0
  36. package/dist/types.d.ts +10 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/utils.d.ts +5 -0
  39. package/dist/utils.d.ts.map +1 -0
  40. package/package.json +43 -0
package/dist/errors.js ADDED
@@ -0,0 +1,1730 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, {
5
+ get: all[name],
6
+ enumerable: true,
7
+ configurable: true,
8
+ set: (newValue) => all[name] = () => newValue
9
+ });
10
+ };
11
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
12
+
13
+ // node:util
14
+ var exports_util = {};
15
+ __export(exports_util, {
16
+ types: () => types,
17
+ promisify: () => promisify,
18
+ log: () => log,
19
+ isUndefined: () => isUndefined,
20
+ isSymbol: () => isSymbol,
21
+ isString: () => isString,
22
+ isRegExp: () => isRegExp,
23
+ isPrimitive: () => isPrimitive,
24
+ isObject: () => isObject,
25
+ isNumber: () => isNumber,
26
+ isNullOrUndefined: () => isNullOrUndefined,
27
+ isNull: () => isNull,
28
+ isFunction: () => isFunction,
29
+ isError: () => isError,
30
+ isDate: () => isDate,
31
+ isBuffer: () => isBuffer,
32
+ isBoolean: () => isBoolean,
33
+ isArray: () => isArray,
34
+ inspect: () => inspect,
35
+ inherits: () => inherits,
36
+ format: () => format,
37
+ deprecate: () => deprecate,
38
+ default: () => util_default,
39
+ debuglog: () => debuglog,
40
+ callbackifyOnRejected: () => callbackifyOnRejected,
41
+ callbackify: () => callbackify,
42
+ _extend: () => _extend,
43
+ TextEncoder: () => TextEncoder,
44
+ TextDecoder: () => TextDecoder
45
+ });
46
+ function format(f, ...args) {
47
+ if (!isString(f)) {
48
+ var objects = [f];
49
+ for (var i = 0;i < args.length; i++)
50
+ objects.push(inspect(args[i]));
51
+ return objects.join(" ");
52
+ }
53
+ var i = 0, len = args.length, str = String(f).replace(formatRegExp, function(x2) {
54
+ if (x2 === "%%")
55
+ return "%";
56
+ if (i >= len)
57
+ return x2;
58
+ switch (x2) {
59
+ case "%s":
60
+ return String(args[i++]);
61
+ case "%d":
62
+ return Number(args[i++]);
63
+ case "%j":
64
+ try {
65
+ return JSON.stringify(args[i++]);
66
+ } catch (_) {
67
+ return "[Circular]";
68
+ }
69
+ default:
70
+ return x2;
71
+ }
72
+ });
73
+ for (var x = args[i];i < len; x = args[++i])
74
+ if (isNull(x) || !isObject(x))
75
+ str += " " + x;
76
+ else
77
+ str += " " + inspect(x);
78
+ return str;
79
+ }
80
+ function deprecate(fn, msg) {
81
+ if (typeof process > "u" || process?.noDeprecation === true)
82
+ return fn;
83
+ var warned = false;
84
+ function deprecated(...args) {
85
+ if (!warned) {
86
+ if (process.throwDeprecation)
87
+ throw Error(msg);
88
+ else if (process.traceDeprecation)
89
+ console.trace(msg);
90
+ else
91
+ console.error(msg);
92
+ warned = true;
93
+ }
94
+ return fn.apply(this, ...args);
95
+ }
96
+ return deprecated;
97
+ }
98
+ function stylizeWithColor(str, styleType) {
99
+ var style = inspect.styles[styleType];
100
+ if (style)
101
+ return "\x1B[" + inspect.colors[style][0] + "m" + str + "\x1B[" + inspect.colors[style][1] + "m";
102
+ else
103
+ return str;
104
+ }
105
+ function stylizeNoColor(str, styleType) {
106
+ return str;
107
+ }
108
+ function arrayToHash(array) {
109
+ var hash = {};
110
+ return array.forEach(function(val, idx) {
111
+ hash[val] = true;
112
+ }), hash;
113
+ }
114
+ function formatValue(ctx, value, recurseTimes) {
115
+ if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype === value)) {
116
+ var ret = value.inspect(recurseTimes, ctx);
117
+ if (!isString(ret))
118
+ ret = formatValue(ctx, ret, recurseTimes);
119
+ return ret;
120
+ }
121
+ var primitive = formatPrimitive(ctx, value);
122
+ if (primitive)
123
+ return primitive;
124
+ var keys = Object.keys(value), visibleKeys = arrayToHash(keys);
125
+ if (ctx.showHidden)
126
+ keys = Object.getOwnPropertyNames(value);
127
+ if (isError(value) && (keys.indexOf("message") >= 0 || keys.indexOf("description") >= 0))
128
+ return formatError(value);
129
+ if (keys.length === 0) {
130
+ if (isFunction(value)) {
131
+ var name = value.name ? ": " + value.name : "";
132
+ return ctx.stylize("[Function" + name + "]", "special");
133
+ }
134
+ if (isRegExp(value))
135
+ return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
136
+ if (isDate(value))
137
+ return ctx.stylize(Date.prototype.toString.call(value), "date");
138
+ if (isError(value))
139
+ return formatError(value);
140
+ }
141
+ var base = "", array = false, braces = ["{", "}"];
142
+ if (isArray(value))
143
+ array = true, braces = ["[", "]"];
144
+ if (isFunction(value)) {
145
+ var n = value.name ? ": " + value.name : "";
146
+ base = " [Function" + n + "]";
147
+ }
148
+ if (isRegExp(value))
149
+ base = " " + RegExp.prototype.toString.call(value);
150
+ if (isDate(value))
151
+ base = " " + Date.prototype.toUTCString.call(value);
152
+ if (isError(value))
153
+ base = " " + formatError(value);
154
+ if (keys.length === 0 && (!array || value.length == 0))
155
+ return braces[0] + base + braces[1];
156
+ if (recurseTimes < 0)
157
+ if (isRegExp(value))
158
+ return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
159
+ else
160
+ return ctx.stylize("[Object]", "special");
161
+ ctx.seen.push(value);
162
+ var output;
163
+ if (array)
164
+ output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
165
+ else
166
+ output = keys.map(function(key) {
167
+ return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
168
+ });
169
+ return ctx.seen.pop(), reduceToSingleString(output, base, braces);
170
+ }
171
+ function formatPrimitive(ctx, value) {
172
+ if (isUndefined(value))
173
+ return ctx.stylize("undefined", "undefined");
174
+ if (isString(value)) {
175
+ var simple = "'" + JSON.stringify(value).replace(/^"|"$/g, "").replace(/'/g, "\\'").replace(/\\"/g, '"') + "'";
176
+ return ctx.stylize(simple, "string");
177
+ }
178
+ if (isNumber(value))
179
+ return ctx.stylize("" + value, "number");
180
+ if (isBoolean(value))
181
+ return ctx.stylize("" + value, "boolean");
182
+ if (isNull(value))
183
+ return ctx.stylize("null", "null");
184
+ }
185
+ function formatError(value) {
186
+ return "[" + Error.prototype.toString.call(value) + "]";
187
+ }
188
+ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
189
+ var output = [];
190
+ for (var i = 0, l = value.length;i < l; ++i)
191
+ if (hasOwnProperty(value, String(i)))
192
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
193
+ else
194
+ output.push("");
195
+ return keys.forEach(function(key) {
196
+ if (!key.match(/^\d+$/))
197
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
198
+ }), output;
199
+ }
200
+ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
201
+ var name, str, desc;
202
+ if (desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }, desc.get)
203
+ if (desc.set)
204
+ str = ctx.stylize("[Getter/Setter]", "special");
205
+ else
206
+ str = ctx.stylize("[Getter]", "special");
207
+ else if (desc.set)
208
+ str = ctx.stylize("[Setter]", "special");
209
+ if (!hasOwnProperty(visibleKeys, key))
210
+ name = "[" + key + "]";
211
+ if (!str)
212
+ if (ctx.seen.indexOf(desc.value) < 0) {
213
+ if (isNull(recurseTimes))
214
+ str = formatValue(ctx, desc.value, null);
215
+ else
216
+ str = formatValue(ctx, desc.value, recurseTimes - 1);
217
+ if (str.indexOf(`
218
+ `) > -1)
219
+ if (array)
220
+ str = str.split(`
221
+ `).map(function(line) {
222
+ return " " + line;
223
+ }).join(`
224
+ `).slice(2);
225
+ else
226
+ str = `
227
+ ` + str.split(`
228
+ `).map(function(line) {
229
+ return " " + line;
230
+ }).join(`
231
+ `);
232
+ } else
233
+ str = ctx.stylize("[Circular]", "special");
234
+ if (isUndefined(name)) {
235
+ if (array && key.match(/^\d+$/))
236
+ return str;
237
+ if (name = JSON.stringify("" + key), name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/))
238
+ name = name.slice(1, -1), name = ctx.stylize(name, "name");
239
+ else
240
+ name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"), name = ctx.stylize(name, "string");
241
+ }
242
+ return name + ": " + str;
243
+ }
244
+ function reduceToSingleString(output, base, braces) {
245
+ var numLinesEst = 0, length = output.reduce(function(prev, cur) {
246
+ if (numLinesEst++, cur.indexOf(`
247
+ `) >= 0)
248
+ numLinesEst++;
249
+ return prev + cur.replace(/\u001b\[\d\d?m/g, "").length + 1;
250
+ }, 0);
251
+ if (length > 60)
252
+ return braces[0] + (base === "" ? "" : base + `
253
+ `) + " " + output.join(`,
254
+ `) + " " + braces[1];
255
+ return braces[0] + base + " " + output.join(", ") + " " + braces[1];
256
+ }
257
+ function isArray(ar) {
258
+ return Array.isArray(ar);
259
+ }
260
+ function isBoolean(arg) {
261
+ return typeof arg === "boolean";
262
+ }
263
+ function isNull(arg) {
264
+ return arg === null;
265
+ }
266
+ function isNullOrUndefined(arg) {
267
+ return arg == null;
268
+ }
269
+ function isNumber(arg) {
270
+ return typeof arg === "number";
271
+ }
272
+ function isString(arg) {
273
+ return typeof arg === "string";
274
+ }
275
+ function isSymbol(arg) {
276
+ return typeof arg === "symbol";
277
+ }
278
+ function isUndefined(arg) {
279
+ return arg === undefined;
280
+ }
281
+ function isRegExp(re) {
282
+ return isObject(re) && objectToString(re) === "[object RegExp]";
283
+ }
284
+ function isObject(arg) {
285
+ return typeof arg === "object" && arg !== null;
286
+ }
287
+ function isDate(d) {
288
+ return isObject(d) && objectToString(d) === "[object Date]";
289
+ }
290
+ function isError(e) {
291
+ return isObject(e) && (objectToString(e) === "[object Error]" || e instanceof Error);
292
+ }
293
+ function isFunction(arg) {
294
+ return typeof arg === "function";
295
+ }
296
+ function isPrimitive(arg) {
297
+ return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || typeof arg > "u";
298
+ }
299
+ function isBuffer(arg) {
300
+ return arg instanceof Buffer;
301
+ }
302
+ function objectToString(o) {
303
+ return Object.prototype.toString.call(o);
304
+ }
305
+ function pad(n) {
306
+ return n < 10 ? "0" + n.toString(10) : n.toString(10);
307
+ }
308
+ function timestamp() {
309
+ var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(":");
310
+ return [d.getDate(), months[d.getMonth()], time].join(" ");
311
+ }
312
+ function log(...args) {
313
+ console.log("%s - %s", timestamp(), format.apply(null, args));
314
+ }
315
+ function inherits(ctor, superCtor) {
316
+ if (superCtor)
317
+ ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } });
318
+ }
319
+ function _extend(origin, add) {
320
+ if (!add || !isObject(add))
321
+ return origin;
322
+ var keys = Object.keys(add), i = keys.length;
323
+ while (i--)
324
+ origin[keys[i]] = add[keys[i]];
325
+ return origin;
326
+ }
327
+ function hasOwnProperty(obj, prop) {
328
+ return Object.prototype.hasOwnProperty.call(obj, prop);
329
+ }
330
+ function callbackifyOnRejected(reason, cb) {
331
+ if (!reason) {
332
+ var newReason = Error("Promise was rejected with a falsy value");
333
+ newReason.reason = reason, reason = newReason;
334
+ }
335
+ return cb(reason);
336
+ }
337
+ function callbackify(original) {
338
+ if (typeof original !== "function")
339
+ throw TypeError('The "original" argument must be of type Function');
340
+ function callbackified(...args) {
341
+ var maybeCb = args.pop();
342
+ if (typeof maybeCb !== "function")
343
+ throw TypeError("The last argument must be of type Function");
344
+ var self = this, cb = function(...args2) {
345
+ return maybeCb.apply(self, ...args2);
346
+ };
347
+ original.apply(this, args).then(function(ret) {
348
+ process.nextTick(cb.bind(null, null, ret));
349
+ }, function(rej) {
350
+ process.nextTick(callbackifyOnRejected.bind(null, rej, cb));
351
+ });
352
+ }
353
+ return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, Object.getOwnPropertyDescriptors(original)), callbackified;
354
+ }
355
+ var formatRegExp, debuglog, inspect, types = () => {}, months, promisify, TextEncoder, TextDecoder, util_default;
356
+ var init_util = __esm(() => {
357
+ formatRegExp = /%[sdj%]/g;
358
+ debuglog = ((debugs = {}, debugEnvRegex = {}, debugEnv) => ((debugEnv = typeof process < "u" && false) && (debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/\*/g, ".*").replace(/,/g, "$|^").toUpperCase()), debugEnvRegex = new RegExp("^" + debugEnv + "$", "i"), (set) => {
359
+ if (set = set.toUpperCase(), !debugs[set])
360
+ if (debugEnvRegex.test(set))
361
+ debugs[set] = function(...args) {
362
+ console.error("%s: %s", set, pid, format.apply(null, ...args));
363
+ };
364
+ else
365
+ debugs[set] = function() {};
366
+ return debugs[set];
367
+ }))();
368
+ inspect = ((i) => (i.colors = { bold: [1, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], white: [37, 39], grey: [90, 39], black: [30, 39], blue: [34, 39], cyan: [36, 39], green: [32, 39], magenta: [35, 39], red: [31, 39], yellow: [33, 39] }, i.styles = { special: "cyan", number: "yellow", boolean: "yellow", undefined: "grey", null: "bold", string: "green", date: "magenta", regexp: "red" }, i.custom = Symbol.for("nodejs.util.inspect.custom"), i))(function(obj, opts, ...rest) {
369
+ var ctx = { seen: [], stylize: stylizeNoColor };
370
+ if (rest.length >= 1)
371
+ ctx.depth = rest[0];
372
+ if (rest.length >= 2)
373
+ ctx.colors = rest[1];
374
+ if (isBoolean(opts))
375
+ ctx.showHidden = opts;
376
+ else if (opts)
377
+ _extend(ctx, opts);
378
+ if (isUndefined(ctx.showHidden))
379
+ ctx.showHidden = false;
380
+ if (isUndefined(ctx.depth))
381
+ ctx.depth = 2;
382
+ if (isUndefined(ctx.colors))
383
+ ctx.colors = false;
384
+ if (ctx.colors)
385
+ ctx.stylize = stylizeWithColor;
386
+ return formatValue(ctx, obj, ctx.depth);
387
+ });
388
+ months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
389
+ promisify = ((x) => (x.custom = Symbol.for("nodejs.util.promisify.custom"), x))(function(original) {
390
+ if (typeof original !== "function")
391
+ throw TypeError('The "original" argument must be of type Function');
392
+ if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
393
+ var fn = original[kCustomPromisifiedSymbol];
394
+ if (typeof fn !== "function")
395
+ throw TypeError('The "nodejs.util.promisify.custom" argument must be of type Function');
396
+ return Object.defineProperty(fn, kCustomPromisifiedSymbol, { value: fn, enumerable: false, writable: false, configurable: true }), fn;
397
+ }
398
+ function fn(...args) {
399
+ var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {
400
+ promiseResolve = resolve, promiseReject = reject;
401
+ });
402
+ args.push(function(err, value) {
403
+ if (err)
404
+ promiseReject(err);
405
+ else
406
+ promiseResolve(value);
407
+ });
408
+ try {
409
+ original.apply(this, args);
410
+ } catch (err) {
411
+ promiseReject(err);
412
+ }
413
+ return promise;
414
+ }
415
+ if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)
416
+ Object.defineProperty(fn, kCustomPromisifiedSymbol, { value: fn, enumerable: false, writable: false, configurable: true });
417
+ return Object.defineProperties(fn, Object.getOwnPropertyDescriptors(original));
418
+ });
419
+ ({ TextEncoder, TextDecoder } = globalThis);
420
+ util_default = { TextEncoder, TextDecoder, promisify, log, inherits, _extend, callbackifyOnRejected, callbackify };
421
+ });
422
+
423
+ // ../../internal/constants/src/endpoints.ts
424
+ var DEFAULT_PLATFORM = "BEYOND_AI";
425
+ var BEYONDAI_TOKEN_URLS = {
426
+ staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
427
+ production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
428
+ };
429
+ var BEYONDAI_API_URLS = {
430
+ staging: "https://api.staging.alpha-1edtech.ai",
431
+ production: "https://api.alpha-1edtech.ai"
432
+ };
433
+ var BEYONDAI_CALIPER_URLS = {
434
+ staging: "https://caliper.staging.alpha-1edtech.ai",
435
+ production: "https://caliper.alpha-1edtech.ai"
436
+ };
437
+ var BEYONDAI_QTI_URLS = {
438
+ staging: "https://qti.alpha-1edtech.ai/api",
439
+ production: "https://qti.alpha-1edtech.ai/api"
440
+ };
441
+ var LEARNWITHAI_TOKEN_URLS = {
442
+ staging: "https://platform.dev.timeback.com/auth/1.0/token",
443
+ production: "https://platform.timeback.com/auth/1.0/token"
444
+ };
445
+ var LEARNWITHAI_API_URLS = {
446
+ staging: "https://platform.dev.timeback.com",
447
+ production: "https://platform.timeback.com"
448
+ };
449
+ var LEARNWITHAI_CALIPER_URLS = {
450
+ staging: "https://platform.dev.timeback.com",
451
+ production: "https://platform.timeback.com"
452
+ };
453
+ var LEARNWITHAI_QTI_URLS = {
454
+ staging: "https://platform.dev.timeback.com",
455
+ production: "https://platform.timeback.com"
456
+ };
457
+ var PLATFORM_ENDPOINTS = {
458
+ BEYOND_AI: {
459
+ token: BEYONDAI_TOKEN_URLS,
460
+ api: BEYONDAI_API_URLS,
461
+ caliper: BEYONDAI_CALIPER_URLS,
462
+ qti: BEYONDAI_QTI_URLS
463
+ },
464
+ LEARNWITH_AI: {
465
+ token: LEARNWITHAI_TOKEN_URLS,
466
+ api: LEARNWITHAI_API_URLS,
467
+ caliper: LEARNWITHAI_CALIPER_URLS,
468
+ qti: LEARNWITHAI_QTI_URLS
469
+ }
470
+ };
471
+ // ../../internal/constants/src/typescript.ts
472
+ var TypeScriptPackages = {
473
+ tsc: "tsc",
474
+ nativePreview: "@typescript/native-preview"
475
+ };
476
+ var TYPESCRIPT_RUNNER = {
477
+ package: TypeScriptPackages.nativePreview,
478
+ bin: "tsgo"
479
+ };
480
+ // ../../internal/logger/src/debug.ts
481
+ var patterns = null;
482
+ var debugAll = false;
483
+ var debugEnvSet = false;
484
+ function patternToRegex(pattern) {
485
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
486
+ const regexStr = escaped.replace(/\*/g, ".*");
487
+ return new RegExp(`^${regexStr}$`);
488
+ }
489
+ function parseDebugEnv() {
490
+ if (patterns !== null)
491
+ return;
492
+ patterns = [];
493
+ if (typeof process === "undefined" || !process.env?.DEBUG) {
494
+ debugEnvSet = false;
495
+ return;
496
+ }
497
+ debugEnvSet = true;
498
+ const debugValue = process.env.DEBUG.trim();
499
+ if (debugValue === "1" || debugValue === "true" || debugValue === "*") {
500
+ debugAll = true;
501
+ return;
502
+ }
503
+ const parts = debugValue.split(",").map((p) => p.trim()).filter(Boolean);
504
+ for (const part of parts) {
505
+ if (part.startsWith("-")) {
506
+ patterns.push({
507
+ regex: patternToRegex(part.slice(1)),
508
+ exclude: true
509
+ });
510
+ } else {
511
+ patterns.push({
512
+ regex: patternToRegex(part),
513
+ exclude: false
514
+ });
515
+ }
516
+ }
517
+ const hasInclude = patterns.some((p) => !p.exclude);
518
+ if (!hasInclude && patterns.length > 0) {
519
+ debugAll = true;
520
+ }
521
+ }
522
+ function shouldShowDebug(scope) {
523
+ parseDebugEnv();
524
+ if (!debugEnvSet) {
525
+ return true;
526
+ }
527
+ if (debugAll) {
528
+ if (scope) {
529
+ for (const pattern of patterns) {
530
+ if (pattern.exclude && pattern.regex.test(scope)) {
531
+ return false;
532
+ }
533
+ }
534
+ }
535
+ return true;
536
+ }
537
+ if (!scope) {
538
+ return false;
539
+ }
540
+ for (const pattern of patterns) {
541
+ if (pattern.exclude && pattern.regex.test(scope)) {
542
+ return false;
543
+ }
544
+ }
545
+ for (const pattern of patterns) {
546
+ if (!pattern.exclude && pattern.regex.test(scope)) {
547
+ return true;
548
+ }
549
+ }
550
+ return false;
551
+ }
552
+
553
+ // ../../internal/logger/src/env.ts
554
+ function isBrowser() {
555
+ return typeof globalThis !== "undefined" && "window" in globalThis;
556
+ }
557
+ function detectEnvironment() {
558
+ if (isBrowser()) {
559
+ return "browser";
560
+ }
561
+ if (typeof process !== "undefined" && process.env) {
562
+ if (process.env["NODE_ENV"] === "test" || process.env["BUN_ENV"] === "test") {
563
+ return "test";
564
+ }
565
+ if (false) {}
566
+ if (process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.CIRCLECI || process.env.JENKINS_URL || process.env.BUILDKITE) {
567
+ return "ci";
568
+ }
569
+ }
570
+ return "terminal";
571
+ }
572
+
573
+ // ../../internal/logger/src/formatters/terminal.ts
574
+ var nodeInspect;
575
+ if (!isBrowser()) {
576
+ try {
577
+ const util = await Promise.resolve().then(() => (init_util(), exports_util));
578
+ nodeInspect = util.inspect;
579
+ } catch {}
580
+ }
581
+ var colors = {
582
+ reset: "\x1B[0m",
583
+ bold: "\x1B[1m",
584
+ dim: "\x1B[2m",
585
+ red: "\x1B[31m",
586
+ yellow: "\x1B[33m",
587
+ blue: "\x1B[34m",
588
+ cyan: "\x1B[36m"
589
+ };
590
+ function getLevelColor(level) {
591
+ switch (level) {
592
+ case "debug":
593
+ return colors.blue;
594
+ case "info":
595
+ return colors.cyan;
596
+ case "warn":
597
+ return colors.yellow;
598
+ case "error":
599
+ return colors.red;
600
+ }
601
+ }
602
+ function getConsoleMethod(level) {
603
+ switch (level) {
604
+ case "debug":
605
+ return console.debug;
606
+ case "info":
607
+ return console.info;
608
+ case "warn":
609
+ return console.warn;
610
+ case "error":
611
+ return console.error;
612
+ }
613
+ }
614
+ function formatContext(context) {
615
+ if (nodeInspect) {
616
+ return nodeInspect(context, {
617
+ depth: null,
618
+ colors: true,
619
+ breakLength: 80,
620
+ compact: false
621
+ });
622
+ }
623
+ return JSON.stringify(context, null, 2);
624
+ }
625
+ var terminalFormatter = (entry) => {
626
+ const levelColor = getLevelColor(entry.level);
627
+ const consoleMethod = getConsoleMethod(entry.level);
628
+ const levelUpper = entry.level.toUpperCase().padEnd(5);
629
+ const isoString = entry.timestamp.toISOString().replace(/\.\d{3}Z$/, "");
630
+ const timestamp2 = `${colors.dim}[${isoString}]${colors.reset}`;
631
+ const level = `${levelColor}${levelUpper}${colors.reset}`;
632
+ const scope = entry.scope ? `${colors.bold}[${entry.scope}]${colors.reset} ` : "";
633
+ const prefix = `${timestamp2} ${level} ${scope}${entry.message}`;
634
+ if (entry.context && Object.keys(entry.context).length > 0) {
635
+ consoleMethod(prefix, formatContext(entry.context));
636
+ } else {
637
+ consoleMethod(prefix);
638
+ }
639
+ };
640
+ // ../../internal/logger/src/formatters/ci.ts
641
+ var LEVEL_PREFIX = {
642
+ debug: "[DEBUG]",
643
+ info: "[INFO]",
644
+ warn: "[WARN]",
645
+ error: "[ERROR]"
646
+ };
647
+ function formatContext2(context) {
648
+ return Object.entries(context).map(([key, value]) => `${key}=${formatValue2(value)}`).join(" ");
649
+ }
650
+ function formatValue2(value) {
651
+ if (typeof value === "string")
652
+ return value;
653
+ if (typeof value === "number")
654
+ return String(value);
655
+ if (typeof value === "boolean")
656
+ return String(value);
657
+ if (value === null)
658
+ return "null";
659
+ if (value === undefined)
660
+ return "undefined";
661
+ return JSON.stringify(value);
662
+ }
663
+ var ciFormatter = (entry) => {
664
+ const parts = [];
665
+ parts.push(entry.timestamp.toISOString());
666
+ parts.push(LEVEL_PREFIX[entry.level]);
667
+ if (entry.scope) {
668
+ parts.push(`[${entry.scope}]`);
669
+ }
670
+ parts.push(entry.message);
671
+ if (entry.context && Object.keys(entry.context).length > 0) {
672
+ parts.push(formatContext2(entry.context));
673
+ }
674
+ console.log(parts.join(" "));
675
+ };
676
+ // ../../internal/logger/src/formatters/production.ts
677
+ var productionFormatter = (entry) => {
678
+ const output = {
679
+ timestamp: entry.timestamp.toISOString(),
680
+ level: entry.level,
681
+ ...entry.scope && { scope: entry.scope },
682
+ msg: entry.message
683
+ };
684
+ if (entry.context && Object.keys(entry.context).length > 0) {
685
+ Object.assign(output, entry.context);
686
+ }
687
+ console.log(JSON.stringify(output));
688
+ };
689
+ // ../../internal/logger/src/formatters/browser.ts
690
+ var LEVEL_STYLES = {
691
+ debug: "color: gray",
692
+ info: "color: #0ea5e9",
693
+ warn: "color: #f59e0b",
694
+ error: "color: #ef4444; font-weight: bold"
695
+ };
696
+ var LEVEL_METHODS = {
697
+ debug: "log",
698
+ info: "info",
699
+ warn: "warn",
700
+ error: "error"
701
+ };
702
+ var browserFormatter = (entry) => {
703
+ const method = LEVEL_METHODS[entry.level];
704
+ const style = LEVEL_STYLES[entry.level];
705
+ const prefix = entry.scope ? `[${entry.scope}]` : "";
706
+ const label = `%c${prefix} ${entry.message}`;
707
+ if (entry.context && Object.keys(entry.context).length > 0) {
708
+ console[method](label, style, entry.context);
709
+ } else {
710
+ console[method](label, style);
711
+ }
712
+ };
713
+ // ../../internal/logger/src/logger.ts
714
+ var LOG_LEVELS = ["debug", "info", "warn", "error"];
715
+ function getFormatter(env) {
716
+ switch (env) {
717
+ case "terminal":
718
+ return terminalFormatter;
719
+ case "ci":
720
+ return ciFormatter;
721
+ case "production":
722
+ return productionFormatter;
723
+ case "browser":
724
+ return browserFormatter;
725
+ case "test":
726
+ return () => {};
727
+ }
728
+ }
729
+ function getDefaultMinLevel() {
730
+ if (typeof process !== "undefined" && process.env?.DEBUG) {
731
+ return "debug";
732
+ }
733
+ return "info";
734
+ }
735
+ function shouldLog(level, minLevel) {
736
+ return LOG_LEVELS.indexOf(level) >= LOG_LEVELS.indexOf(minLevel);
737
+ }
738
+
739
+ class Logger {
740
+ scope;
741
+ minLevel;
742
+ environment;
743
+ formatter;
744
+ defaultContext;
745
+ constructor(options = {}) {
746
+ this.scope = options.scope;
747
+ this.minLevel = options.minLevel ?? getDefaultMinLevel();
748
+ this.defaultContext = options.defaultContext ?? {};
749
+ this.environment = options.environment ?? detectEnvironment();
750
+ this.formatter = getFormatter(this.environment);
751
+ }
752
+ child(scope) {
753
+ const childScope = this.scope ? `${this.scope}:${scope}` : scope;
754
+ return new Logger({
755
+ scope: childScope,
756
+ minLevel: this.minLevel,
757
+ environment: this.environment,
758
+ defaultContext: { ...this.defaultContext }
759
+ });
760
+ }
761
+ withContext(context) {
762
+ return new Logger({
763
+ scope: this.scope,
764
+ minLevel: this.minLevel,
765
+ environment: this.environment,
766
+ defaultContext: { ...this.defaultContext, ...context }
767
+ });
768
+ }
769
+ debug(message, context) {
770
+ this.log("debug", message, context);
771
+ }
772
+ info(message, context) {
773
+ this.log("info", message, context);
774
+ }
775
+ warn(message, context) {
776
+ this.log("warn", message, context);
777
+ }
778
+ error(message, context) {
779
+ this.log("error", message, context);
780
+ }
781
+ log(level, message, context) {
782
+ if (level === "debug" && !shouldShowDebug(this.scope)) {
783
+ return;
784
+ }
785
+ if (!shouldLog(level, this.minLevel)) {
786
+ return;
787
+ }
788
+ const entry = {
789
+ level,
790
+ message,
791
+ scope: this.scope,
792
+ context: context || Object.keys(this.defaultContext).length > 0 ? { ...this.defaultContext, ...context } : undefined,
793
+ timestamp: new Date
794
+ };
795
+ this.formatter(entry);
796
+ }
797
+ }
798
+ function createLogger(options = {}) {
799
+ return new Logger(options);
800
+ }
801
+ // ../../internal/client-infra/src/auth/token-manager.ts
802
+ function isDebug() {
803
+ try {
804
+ const debug = typeof process === "undefined" ? undefined : process.env["DEBUG"];
805
+ return debug === "1" || debug === "true";
806
+ } catch {
807
+ return false;
808
+ }
809
+ }
810
+ var log2 = createLogger({ scope: "auth", minLevel: isDebug() ? "debug" : "warn" });
811
+
812
+ class TokenManager {
813
+ config;
814
+ accessToken = null;
815
+ tokenExpiry = 0;
816
+ pendingRequest = null;
817
+ fetchFn;
818
+ constructor(config) {
819
+ this.config = config;
820
+ this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
821
+ }
822
+ async getToken() {
823
+ if (this.accessToken && Date.now() < this.tokenExpiry) {
824
+ log2.debug("Using cached token");
825
+ return this.accessToken;
826
+ }
827
+ if (this.pendingRequest) {
828
+ log2.debug("Waiting for in-flight token request");
829
+ return this.pendingRequest;
830
+ }
831
+ this.pendingRequest = this.fetchToken();
832
+ try {
833
+ return await this.pendingRequest;
834
+ } finally {
835
+ this.pendingRequest = null;
836
+ }
837
+ }
838
+ async fetchToken() {
839
+ log2.debug("Fetching new access token...");
840
+ const { clientId, clientSecret } = this.config.credentials;
841
+ const credentials = btoa(`${clientId}:${clientSecret}`);
842
+ const start = performance.now();
843
+ const response = await this.fetchFn(this.config.tokenUrl, {
844
+ method: "POST",
845
+ headers: {
846
+ Authorization: `Basic ${credentials}`,
847
+ "Content-Type": "application/x-www-form-urlencoded"
848
+ },
849
+ body: "grant_type=client_credentials"
850
+ });
851
+ const duration = Math.round(performance.now() - start);
852
+ if (!response.ok) {
853
+ log2.error(`Token request failed: ${response.status} ${response.statusText}`);
854
+ throw new Error(`Failed to obtain access token: ${response.status} ${response.statusText}`);
855
+ }
856
+ const data = await response.json();
857
+ this.accessToken = data.access_token;
858
+ this.tokenExpiry = Date.now() + (data.expires_in - 60) * 1000;
859
+ log2.debug(`Token acquired (${duration}ms, expires in ${data.expires_in}s)`);
860
+ return this.accessToken;
861
+ }
862
+ invalidate() {
863
+ log2.debug("Token invalidated");
864
+ this.accessToken = null;
865
+ this.tokenExpiry = 0;
866
+ }
867
+ }
868
+ // ../../internal/client-infra/src/config/paths.ts
869
+ var BEYONDAI_PATHS = {
870
+ caliper: {
871
+ send: "/caliper/event",
872
+ validate: "/caliper/event/validate",
873
+ list: "/caliper/events",
874
+ get: "/caliper/events/{id}",
875
+ jobStatus: "/jobs/{id}/status"
876
+ },
877
+ oneroster: {
878
+ rostering: "/ims/oneroster/rostering/v1p2",
879
+ gradebook: "/ims/oneroster/gradebook/v1p2",
880
+ resources: "/ims/oneroster/resources/v1p2"
881
+ },
882
+ edubridge: {
883
+ base: "/edubridge"
884
+ },
885
+ powerpath: {
886
+ base: "/powerpath"
887
+ },
888
+ clr: {
889
+ credentials: "/ims/clr/v2p0/credentials",
890
+ discovery: "/ims/clr/v2p0/discovery"
891
+ },
892
+ case: {
893
+ base: "/ims/case/v1p1"
894
+ }
895
+ };
896
+ var LEARNWITHAI_PATHS = {
897
+ caliper: {
898
+ send: "/events/1.0/",
899
+ validate: null,
900
+ list: null,
901
+ get: null,
902
+ jobStatus: null
903
+ },
904
+ oneroster: {
905
+ rostering: "/rostering/1.0",
906
+ gradebook: "/gradebook/1.0",
907
+ resources: "/resources/1.0"
908
+ },
909
+ edubridge: null,
910
+ powerpath: null,
911
+ clr: null,
912
+ case: null
913
+ };
914
+ var PLATFORM_PATHS = {
915
+ BEYOND_AI: BEYONDAI_PATHS,
916
+ LEARNWITH_AI: LEARNWITHAI_PATHS
917
+ };
918
+
919
+ // ../../internal/client-infra/src/config/provider.ts
920
+ function isEnvConfig(config) {
921
+ return "env" in config && !("baseUrl" in config) && !("services" in config);
922
+ }
923
+ function isExplicitConfig(config) {
924
+ return "baseUrl" in config && !("services" in config);
925
+ }
926
+ function isServicesConfig(config) {
927
+ return "services" in config;
928
+ }
929
+ function resolvePathProfiles(pathProfile, customPaths) {
930
+ const basePaths = pathProfile ? PLATFORM_PATHS[pathProfile] ?? BEYONDAI_PATHS : BEYONDAI_PATHS;
931
+ return {
932
+ caliper: customPaths?.caliper ?? basePaths.caliper,
933
+ oneroster: customPaths?.oneroster ?? basePaths.oneroster,
934
+ edubridge: customPaths?.edubridge ?? basePaths.edubridge,
935
+ powerpath: customPaths?.powerpath ?? basePaths.powerpath,
936
+ clr: customPaths?.clr ?? basePaths.clr,
937
+ case: customPaths?.case ?? basePaths.case
938
+ };
939
+ }
940
+
941
+ class TimebackProvider {
942
+ platform;
943
+ env;
944
+ auth;
945
+ timeout;
946
+ endpoints;
947
+ authUrl;
948
+ pathProfiles;
949
+ tokenManagers = new Map;
950
+ constructor(config) {
951
+ this.timeout = config.timeout ?? 30000;
952
+ if (isEnvConfig(config)) {
953
+ this.auth = config.auth;
954
+ const platform = config.platform ?? DEFAULT_PLATFORM;
955
+ const env = config.env;
956
+ this.platform = platform;
957
+ this.env = env;
958
+ const platformEndpoints = PLATFORM_ENDPOINTS[platform];
959
+ if (!platformEndpoints) {
960
+ throw new Error(`Unknown platform: ${platform}`);
961
+ }
962
+ this.authUrl = platformEndpoints.token[env];
963
+ this.pathProfiles = PLATFORM_PATHS[platform] ?? BEYONDAI_PATHS;
964
+ this.endpoints = {
965
+ oneroster: {
966
+ baseUrl: platformEndpoints.api[env],
967
+ authUrl: this.authUrl
968
+ },
969
+ edubridge: {
970
+ baseUrl: platformEndpoints.api[env],
971
+ authUrl: this.authUrl
972
+ },
973
+ powerpath: {
974
+ baseUrl: platformEndpoints.api[env],
975
+ authUrl: this.authUrl
976
+ },
977
+ clr: {
978
+ baseUrl: platformEndpoints.api[env],
979
+ authUrl: this.authUrl
980
+ },
981
+ case: {
982
+ baseUrl: platformEndpoints.api[env],
983
+ authUrl: this.authUrl
984
+ },
985
+ caliper: {
986
+ baseUrl: platformEndpoints.caliper[env],
987
+ authUrl: this.authUrl
988
+ },
989
+ qti: {
990
+ baseUrl: platformEndpoints.qti[env],
991
+ authUrl: this.authUrl
992
+ }
993
+ };
994
+ } else if (isExplicitConfig(config)) {
995
+ this.auth = config.auth;
996
+ this.authUrl = config.authUrl;
997
+ this.pathProfiles = resolvePathProfiles(config.pathProfile, config.paths);
998
+ this.endpoints = {
999
+ oneroster: { baseUrl: config.baseUrl, authUrl: this.authUrl },
1000
+ edubridge: { baseUrl: config.baseUrl, authUrl: this.authUrl },
1001
+ powerpath: { baseUrl: config.baseUrl, authUrl: this.authUrl },
1002
+ clr: { baseUrl: config.baseUrl, authUrl: this.authUrl },
1003
+ case: { baseUrl: config.baseUrl, authUrl: this.authUrl },
1004
+ caliper: { baseUrl: config.baseUrl, authUrl: this.authUrl },
1005
+ qti: { baseUrl: config.baseUrl, authUrl: this.authUrl }
1006
+ };
1007
+ } else if (isServicesConfig(config)) {
1008
+ this.auth = config.auth;
1009
+ this.authUrl = config.authUrl;
1010
+ this.pathProfiles = resolvePathProfiles(config.pathProfile, config.paths);
1011
+ this.endpoints = {};
1012
+ for (const [service, baseUrl] of Object.entries(config.services)) {
1013
+ if (baseUrl) {
1014
+ this.endpoints[service] = {
1015
+ baseUrl,
1016
+ authUrl: this.authUrl
1017
+ };
1018
+ }
1019
+ }
1020
+ } else {
1021
+ throw new Error("Invalid provider configuration");
1022
+ }
1023
+ }
1024
+ getEndpoint(service) {
1025
+ const endpoint = this.endpoints[service];
1026
+ if (!endpoint) {
1027
+ throw new Error(`Service "${service}" is not configured in this provider`);
1028
+ }
1029
+ return endpoint;
1030
+ }
1031
+ hasService(service) {
1032
+ return service in this.endpoints;
1033
+ }
1034
+ getAvailableServices() {
1035
+ return Object.keys(this.endpoints);
1036
+ }
1037
+ getTokenUrl() {
1038
+ return this.authUrl;
1039
+ }
1040
+ getEndpointWithPaths(service) {
1041
+ const endpoint = this.getEndpoint(service);
1042
+ const paths = this.getServicePaths(service);
1043
+ return { ...endpoint, paths };
1044
+ }
1045
+ getPaths() {
1046
+ return this.pathProfiles;
1047
+ }
1048
+ getServicePaths(service) {
1049
+ const paths = this.pathProfiles[service];
1050
+ if (!paths) {
1051
+ throw new Error(`Service "${service}" is not supported on ${this.platform ?? "this"} platform.`);
1052
+ }
1053
+ return paths;
1054
+ }
1055
+ hasServiceSupport(service) {
1056
+ return this.pathProfiles[service] !== null;
1057
+ }
1058
+ getTokenProvider(service) {
1059
+ const endpoint = this.getEndpoint(service);
1060
+ const { authUrl } = endpoint;
1061
+ if (!authUrl) {
1062
+ return;
1063
+ }
1064
+ if (!this.auth) {
1065
+ throw new Error(`Service "${service}" requires authentication but no credentials were provided`);
1066
+ }
1067
+ let manager = this.tokenManagers.get(authUrl);
1068
+ if (!manager) {
1069
+ manager = new TokenManager({
1070
+ tokenUrl: authUrl,
1071
+ credentials: {
1072
+ clientId: this.auth.clientId,
1073
+ clientSecret: this.auth.clientSecret
1074
+ }
1075
+ });
1076
+ this.tokenManagers.set(authUrl, manager);
1077
+ }
1078
+ return manager;
1079
+ }
1080
+ async checkAuth() {
1081
+ if (!this.authUrl || !this.auth) {
1082
+ throw new Error("No auth configured on this provider");
1083
+ }
1084
+ const startTime = Date.now();
1085
+ let manager = this.tokenManagers.get(this.authUrl);
1086
+ if (!manager) {
1087
+ manager = new TokenManager({
1088
+ tokenUrl: this.authUrl,
1089
+ credentials: {
1090
+ clientId: this.auth.clientId,
1091
+ clientSecret: this.auth.clientSecret
1092
+ }
1093
+ });
1094
+ this.tokenManagers.set(this.authUrl, manager);
1095
+ }
1096
+ try {
1097
+ await manager.getToken();
1098
+ return {
1099
+ ok: true,
1100
+ latencyMs: Date.now() - startTime,
1101
+ checks: { tokenAcquisition: true }
1102
+ };
1103
+ } catch (error) {
1104
+ return {
1105
+ ok: false,
1106
+ latencyMs: Date.now() - startTime,
1107
+ error: error instanceof Error ? error.message : String(error),
1108
+ checks: { tokenAcquisition: false }
1109
+ };
1110
+ }
1111
+ }
1112
+ invalidateTokens() {
1113
+ for (const manager of this.tokenManagers.values()) {
1114
+ manager.invalidate?.();
1115
+ }
1116
+ this.tokenManagers.clear();
1117
+ }
1118
+ }
1119
+ // ../../internal/client-infra/src/utils/utils.ts
1120
+ function getEnv(key) {
1121
+ try {
1122
+ if (typeof process === "undefined")
1123
+ return;
1124
+ if (typeof key === "string") {
1125
+ return process.env[key];
1126
+ }
1127
+ for (const k of key) {
1128
+ const value = process.env[k];
1129
+ if (value !== undefined)
1130
+ return value;
1131
+ }
1132
+ return;
1133
+ } catch {
1134
+ return;
1135
+ }
1136
+ }
1137
+ function isDebug2() {
1138
+ const debug = getEnv("DEBUG");
1139
+ return debug === "1" || debug === "true";
1140
+ }
1141
+ function generateRequestId() {
1142
+ return Math.random().toString(16).slice(2, 10);
1143
+ }
1144
+ function createScopedLogger(scope) {
1145
+ return createLogger({
1146
+ scope,
1147
+ minLevel: isDebug2() ? "debug" : "warn"
1148
+ });
1149
+ }
1150
+ // ../../internal/client-infra/src/config/registry.ts
1151
+ var DEFAULT_PROVIDER_REGISTRY = {
1152
+ defaultPlatform: DEFAULT_PLATFORM,
1153
+ templates: {
1154
+ BEYOND_AI: {
1155
+ staging: { platform: "BEYOND_AI", env: "staging" },
1156
+ production: { platform: "BEYOND_AI", env: "production" }
1157
+ },
1158
+ LEARNWITH_AI: {
1159
+ staging: { platform: "LEARNWITH_AI", env: "staging" },
1160
+ production: { platform: "LEARNWITH_AI", env: "production" }
1161
+ }
1162
+ }
1163
+ };
1164
+
1165
+ // ../../internal/client-infra/src/config/resolve.ts
1166
+ function primaryEnvVar(key) {
1167
+ if (typeof key === "string") {
1168
+ return key;
1169
+ }
1170
+ if (key.length === 0) {
1171
+ throw new Error(`Missing env var key: ${key}`);
1172
+ }
1173
+ return key[0];
1174
+ }
1175
+ function formatEnvVarKey(key) {
1176
+ return primaryEnvVar(key);
1177
+ }
1178
+ function validateEnv(env) {
1179
+ if (env !== "staging" && env !== "production") {
1180
+ throw new Error(`Invalid env "${env}": must be "staging" or "production"`);
1181
+ }
1182
+ return env;
1183
+ }
1184
+ function validateAuth(auth, envVars) {
1185
+ const clientId = auth?.clientId ?? getEnv(envVars.clientId);
1186
+ const clientSecret = auth?.clientSecret ?? getEnv(envVars.clientSecret);
1187
+ if (!clientId) {
1188
+ throw new Error(`Missing clientId: provide in config or set ${formatEnvVarKey(envVars.clientId)}`);
1189
+ }
1190
+ if (!clientSecret) {
1191
+ throw new Error(`Missing clientSecret: provide in config or set ${formatEnvVarKey(envVars.clientSecret)}`);
1192
+ }
1193
+ return { clientId, clientSecret };
1194
+ }
1195
+ function validateAuthOptional(auth, envVars, requireAuth) {
1196
+ if (!requireAuth) {
1197
+ return;
1198
+ }
1199
+ return validateAuth(auth, envVars);
1200
+ }
1201
+ function buildMissingEnvError(envVars) {
1202
+ const baseUrl = getEnv(envVars.baseUrl);
1203
+ const authUrl = getEnv(envVars.authUrl);
1204
+ const clientId = getEnv(envVars.clientId);
1205
+ const clientSecret = getEnv(envVars.clientSecret);
1206
+ if (baseUrl === undefined && clientId === undefined) {
1207
+ const hint = formatEnvVarKey(envVars.env ?? envVars.baseUrl);
1208
+ return `Missing env: provide in config or set ${hint}`;
1209
+ }
1210
+ const missing = [];
1211
+ if (baseUrl === undefined) {
1212
+ missing.push(formatEnvVarKey(envVars.env ?? envVars.baseUrl));
1213
+ }
1214
+ if (baseUrl !== undefined && authUrl === undefined) {
1215
+ missing.push(formatEnvVarKey(envVars.authUrl));
1216
+ }
1217
+ if (clientId === undefined) {
1218
+ missing.push(formatEnvVarKey(envVars.clientId));
1219
+ }
1220
+ if (clientSecret === undefined) {
1221
+ missing.push(formatEnvVarKey(envVars.clientSecret));
1222
+ }
1223
+ return `Missing environment variables: ${missing.join(", ")}`;
1224
+ }
1225
+ var MODE_TRANSPORT = {
1226
+ name: "transport",
1227
+ matches(config) {
1228
+ return "transport" in config && !!config.transport;
1229
+ },
1230
+ resolve(config) {
1231
+ const c = config;
1232
+ return { mode: "transport", transport: c.transport };
1233
+ }
1234
+ };
1235
+ var MODE_PROVIDER = {
1236
+ name: "provider",
1237
+ matches(config) {
1238
+ return "provider" in config && !!config.provider;
1239
+ },
1240
+ resolve(config) {
1241
+ const c = config;
1242
+ return { mode: "provider", provider: c.provider };
1243
+ }
1244
+ };
1245
+ var MODE_ENV_CONFIG = {
1246
+ name: "env-config",
1247
+ matches(config) {
1248
+ return "env" in config;
1249
+ },
1250
+ resolve(config, envVars, registry) {
1251
+ const c = config;
1252
+ const env = validateEnv(c.env);
1253
+ const auth = validateAuth(c.auth, envVars);
1254
+ const platform = c.platform ?? registry.defaultPlatform;
1255
+ const platformTemplates = registry.templates[platform];
1256
+ if (!platformTemplates) {
1257
+ const available = Object.keys(registry.templates).join(", ");
1258
+ throw new Error(`Unknown platform "${platform}": available platforms are ${available}`);
1259
+ }
1260
+ const template = platformTemplates[env];
1261
+ if (!template) {
1262
+ const available = Object.keys(platformTemplates).join(", ");
1263
+ throw new Error(`Unknown env "${env}" for platform "${platform}": available environments are ${available}`);
1264
+ }
1265
+ return {
1266
+ mode: "provider",
1267
+ provider: new TimebackProvider({
1268
+ platform: template.platform,
1269
+ env: template.env,
1270
+ auth,
1271
+ timeout: c.timeout
1272
+ })
1273
+ };
1274
+ }
1275
+ };
1276
+ var MODE_EXPLICIT_CONFIG = {
1277
+ name: "explicit-config",
1278
+ matches(config) {
1279
+ return "baseUrl" in config;
1280
+ },
1281
+ resolve(config, envVars) {
1282
+ const c = config;
1283
+ const authUrl = c.authUrl ?? c.auth?.authUrl;
1284
+ const requireAuth = !!authUrl;
1285
+ const auth = validateAuthOptional(c.auth, envVars, requireAuth);
1286
+ return {
1287
+ mode: "provider",
1288
+ provider: new TimebackProvider({
1289
+ baseUrl: c.baseUrl,
1290
+ authUrl,
1291
+ auth,
1292
+ timeout: c.timeout,
1293
+ pathProfile: c.pathProfile,
1294
+ paths: c.paths
1295
+ })
1296
+ };
1297
+ }
1298
+ };
1299
+ var MODE_ENV_FALLBACK_PLATFORM = {
1300
+ name: "env-fallback-platform",
1301
+ matches(config, envVars) {
1302
+ if (Object.keys(config).length > 0)
1303
+ return false;
1304
+ const env = envVars.env ? getEnv(envVars.env) : undefined;
1305
+ const clientId = getEnv(envVars.clientId);
1306
+ const clientSecret = getEnv(envVars.clientSecret);
1307
+ return env !== undefined && clientId !== undefined && clientSecret !== undefined;
1308
+ },
1309
+ resolve(_config, envVars, registry) {
1310
+ const env = validateEnv(getEnv(envVars.env));
1311
+ const clientId = getEnv(envVars.clientId);
1312
+ const clientSecret = getEnv(envVars.clientSecret);
1313
+ const platform = registry.defaultPlatform;
1314
+ const template = registry.templates[platform]?.[env];
1315
+ if (!template) {
1316
+ throw new Error(`Unknown env "${env}" for platform "${platform}"`);
1317
+ }
1318
+ return {
1319
+ mode: "provider",
1320
+ provider: new TimebackProvider({
1321
+ platform: template.platform,
1322
+ env: template.env,
1323
+ auth: { clientId, clientSecret }
1324
+ })
1325
+ };
1326
+ }
1327
+ };
1328
+ var MODE_ENV_FALLBACK_EXPLICIT = {
1329
+ name: "env-fallback-explicit",
1330
+ matches(config, envVars) {
1331
+ if (Object.keys(config).length > 0)
1332
+ return false;
1333
+ const baseUrl = getEnv(envVars.baseUrl);
1334
+ const authUrl = getEnv(envVars.authUrl);
1335
+ const clientId = getEnv(envVars.clientId);
1336
+ const clientSecret = getEnv(envVars.clientSecret);
1337
+ return baseUrl !== undefined && authUrl !== undefined && clientId !== undefined && clientSecret !== undefined;
1338
+ },
1339
+ resolve(_config, envVars) {
1340
+ const baseUrl = getEnv(envVars.baseUrl);
1341
+ const authUrl = getEnv(envVars.authUrl);
1342
+ const clientId = getEnv(envVars.clientId);
1343
+ const clientSecret = getEnv(envVars.clientSecret);
1344
+ return {
1345
+ mode: "provider",
1346
+ provider: new TimebackProvider({
1347
+ baseUrl,
1348
+ authUrl,
1349
+ auth: { clientId, clientSecret }
1350
+ })
1351
+ };
1352
+ }
1353
+ };
1354
+ var MODE_TOKEN_PROVIDER = {
1355
+ name: "token-provider",
1356
+ matches(config) {
1357
+ return "tokenProvider" in config;
1358
+ },
1359
+ resolve() {
1360
+ throw new Error("TokenProvider mode is not supported with provider pattern. " + "Use { provider: TimebackProvider } or { env, auth } instead.");
1361
+ }
1362
+ };
1363
+ var MODES = [
1364
+ MODE_TRANSPORT,
1365
+ MODE_PROVIDER,
1366
+ MODE_ENV_CONFIG,
1367
+ MODE_TOKEN_PROVIDER,
1368
+ MODE_EXPLICIT_CONFIG,
1369
+ MODE_ENV_FALLBACK_PLATFORM,
1370
+ MODE_ENV_FALLBACK_EXPLICIT
1371
+ ];
1372
+ function resolveToProvider(config, envVars, registry = DEFAULT_PROVIDER_REGISTRY) {
1373
+ for (const mode of MODES) {
1374
+ if (mode.matches(config, envVars)) {
1375
+ return mode.resolve(config, envVars, registry);
1376
+ }
1377
+ }
1378
+ throw new Error(buildMissingEnvError(envVars));
1379
+ }
1380
+ // ../../internal/client-infra/src/errors/errors.ts
1381
+ class ApiError extends Error {
1382
+ statusCode;
1383
+ response;
1384
+ name = "ApiError";
1385
+ constructor(message, statusCode, response) {
1386
+ super(message);
1387
+ this.statusCode = statusCode;
1388
+ this.response = response;
1389
+ }
1390
+ get minorCodes() {
1391
+ const ims = this.response;
1392
+ if (!ims?.imsx_CodeMinor?.imsx_codeMinorField) {
1393
+ return [];
1394
+ }
1395
+ return ims.imsx_CodeMinor.imsx_codeMinorField.map((field) => ({
1396
+ field: field.imsx_codeMinorFieldName,
1397
+ value: field.imsx_codeMinorFieldValue
1398
+ }));
1399
+ }
1400
+ get details() {
1401
+ const ims = this.response;
1402
+ return ims?.imsx_error_details ?? [];
1403
+ }
1404
+ }
1405
+
1406
+ class UnauthorizedError extends ApiError {
1407
+ name = "UnauthorizedError";
1408
+ constructor(message = "Unauthorized", response) {
1409
+ super(message, 401, response);
1410
+ }
1411
+ }
1412
+
1413
+ class ForbiddenError extends ApiError {
1414
+ name = "ForbiddenError";
1415
+ constructor(message = "Forbidden", response) {
1416
+ super(message, 403, response);
1417
+ }
1418
+ }
1419
+
1420
+ class NotFoundError extends ApiError {
1421
+ name = "NotFoundError";
1422
+ constructor(message = "Not Found", response) {
1423
+ super(message, 404, response);
1424
+ }
1425
+ }
1426
+
1427
+ class ValidationError extends ApiError {
1428
+ name = "ValidationError";
1429
+ constructor(message = "Validation Error", response) {
1430
+ super(message, 422, response);
1431
+ }
1432
+ }
1433
+
1434
+ class InputValidationError extends ApiError {
1435
+ name = "InputValidationError";
1436
+ issues;
1437
+ constructor(message, issues) {
1438
+ const response = {
1439
+ imsx_codeMajor: "failure",
1440
+ imsx_severity: "error",
1441
+ imsx_description: message,
1442
+ imsx_error_details: issues.map((issue) => ({
1443
+ path: issue.path,
1444
+ message: issue.message
1445
+ }))
1446
+ };
1447
+ super(message, 400, response);
1448
+ this.issues = issues;
1449
+ }
1450
+ }
1451
+ function createInputValidationError(message, issues) {
1452
+ return new InputValidationError(message, issues);
1453
+ }
1454
+ // ../../internal/client-infra/src/transport/constants.ts
1455
+ var MAX_RETRIES = 3;
1456
+ var RETRY_STATUS_CODES = [429, 503];
1457
+ var INITIAL_RETRY_DELAY_MS = 1000;
1458
+
1459
+ // ../../internal/client-infra/src/transport/transport.ts
1460
+ class BaseTransport {
1461
+ config;
1462
+ log;
1463
+ constructor(options) {
1464
+ const { config, logger } = options;
1465
+ const fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
1466
+ let tokenProvider;
1467
+ if ("tokenProvider" in config && config.tokenProvider) {
1468
+ tokenProvider = config.tokenProvider;
1469
+ } else if ("auth" in config && config.auth) {
1470
+ tokenProvider = new TokenManager({
1471
+ tokenUrl: config.auth.authUrl,
1472
+ credentials: {
1473
+ clientId: config.auth.clientId,
1474
+ clientSecret: config.auth.clientSecret
1475
+ },
1476
+ fetch: fetchFn
1477
+ });
1478
+ }
1479
+ const normalizedBaseUrl = config.baseUrl.endsWith("/") ? config.baseUrl : `${config.baseUrl}/`;
1480
+ this.config = {
1481
+ baseUrl: normalizedBaseUrl,
1482
+ timeout: config.timeout ?? 30000,
1483
+ fetch: fetchFn,
1484
+ tokenProvider
1485
+ };
1486
+ this.log = logger.child("http");
1487
+ }
1488
+ get baseUrl() {
1489
+ return this.config.baseUrl;
1490
+ }
1491
+ async request(path, options = {}) {
1492
+ const response = await this.requestRaw(path, options);
1493
+ return this.handleResponse(response);
1494
+ }
1495
+ async requestRaw(path, options = {}) {
1496
+ const { method = "GET", params, body, headers = {} } = options;
1497
+ const url = this.buildUrl(path, params);
1498
+ const requestId = options.requestId ?? generateRequestId();
1499
+ const operationStart = Date.now();
1500
+ const operationDeadline = operationStart + this.config.timeout;
1501
+ for (let attempt = 0;attempt < MAX_RETRIES; attempt++) {
1502
+ const remainingTime = operationDeadline - Date.now();
1503
+ if (remainingTime <= 0) {
1504
+ this.log.error("Request timeout before attempt", isDebug2() ? { requestId, path } : { path });
1505
+ throw new ApiError("Request timeout", 408);
1506
+ }
1507
+ const token = await this.getAccessToken();
1508
+ const isLastAttempt = attempt === MAX_RETRIES - 1;
1509
+ const start = performance.now();
1510
+ this.log.debug(`→ ${method} ${url}`, {
1511
+ requestId,
1512
+ attempt: attempt > 0 ? attempt + 1 : undefined
1513
+ });
1514
+ const requestHeaders = {
1515
+ "Content-Type": "application/json",
1516
+ Accept: "application/json",
1517
+ "X-Request-ID": requestId,
1518
+ ...headers
1519
+ };
1520
+ if (token) {
1521
+ requestHeaders.Authorization = `Bearer ${token}`;
1522
+ }
1523
+ const response = await this.config.fetch(url, {
1524
+ method,
1525
+ headers: requestHeaders,
1526
+ body: body ? JSON.stringify(body) : undefined,
1527
+ signal: AbortSignal.timeout(Math.min(remainingTime, this.config.timeout))
1528
+ });
1529
+ const duration = Math.round(performance.now() - start);
1530
+ this.log.debug(`← ${response.status} ${response.statusText} (${duration}ms)`, {
1531
+ requestId
1532
+ });
1533
+ const shouldRetry = RETRY_STATUS_CODES.includes(response.status) && !isLastAttempt;
1534
+ if (shouldRetry) {
1535
+ const retryAfter = response.headers.get("Retry-After");
1536
+ const delayMs = this.parseRetryAfter(retryAfter, attempt);
1537
+ const timeRemaining = operationDeadline - Date.now();
1538
+ if (delayMs >= timeRemaining) {
1539
+ this.log.error("Request timeout during retry backoff", isDebug2() ? { requestId, path } : { path });
1540
+ throw new ApiError("Request timeout", 408);
1541
+ }
1542
+ this.log.warn(`Retrying in ${delayMs}ms (attempt ${attempt + 1}/${MAX_RETRIES})`, {
1543
+ ...isDebug2() && { requestId },
1544
+ status: response.status
1545
+ });
1546
+ await this.sleep(delayMs);
1547
+ continue;
1548
+ }
1549
+ if (!response.ok) {
1550
+ return this.handleErrorResponse(response, requestId);
1551
+ }
1552
+ return response;
1553
+ }
1554
+ this.log.error("Max retries exceeded", isDebug2() ? { requestId, path } : { path });
1555
+ throw new ApiError("Max retries exceeded");
1556
+ }
1557
+ getAccessToken() {
1558
+ if (!this.config.tokenProvider) {
1559
+ return Promise.resolve(undefined);
1560
+ }
1561
+ return this.config.tokenProvider.getToken();
1562
+ }
1563
+ buildUrl(path, params) {
1564
+ if (/^[a-z][a-z0-9+.-]*:/i.test(path)) {
1565
+ throw new Error(`Absolute URLs are not allowed in path: ${path}. Use relative paths only.`);
1566
+ }
1567
+ const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
1568
+ const url = new URL(normalizedPath, this.config.baseUrl);
1569
+ if (params) {
1570
+ for (const [key, value] of Object.entries(params)) {
1571
+ if (value !== undefined) {
1572
+ url.searchParams.set(key, String(value));
1573
+ }
1574
+ }
1575
+ }
1576
+ return url.toString();
1577
+ }
1578
+ async handleResponse(response) {
1579
+ if (!response.ok) {
1580
+ await this.handleErrorResponse(response);
1581
+ }
1582
+ if (response.status === 204) {
1583
+ return;
1584
+ }
1585
+ const contentLength = response.headers.get("content-length");
1586
+ if (contentLength === "0") {
1587
+ return;
1588
+ }
1589
+ return this.parseJsonResponse(response);
1590
+ }
1591
+ async parseJsonResponse(response) {
1592
+ const text = await response.text();
1593
+ if (!text || text.trim() === "") {
1594
+ return;
1595
+ }
1596
+ try {
1597
+ return JSON.parse(text);
1598
+ } catch (error) {
1599
+ const preview = text.length > 200 ? text.slice(0, 200) + "..." : text;
1600
+ const parseError = error instanceof Error ? error.message : String(error);
1601
+ const url = response.url || "unknown";
1602
+ this.log.error("Failed to parse JSON response", {
1603
+ url,
1604
+ status: response.status,
1605
+ contentType: response.headers.get("content-type"),
1606
+ bodyPreview: preview,
1607
+ error: parseError
1608
+ });
1609
+ throw new ApiError(`Invalid JSON response from ${url}`, response.status, {
1610
+ parseError,
1611
+ body: preview
1612
+ });
1613
+ }
1614
+ }
1615
+ async handleErrorResponse(response, requestId) {
1616
+ let errorBody;
1617
+ const text = await response.text().catch(() => "");
1618
+ if (text) {
1619
+ try {
1620
+ errorBody = JSON.parse(text);
1621
+ } catch (parseError) {
1622
+ const parseWarning = parseError instanceof Error ? parseError.message : "Unknown parse error";
1623
+ errorBody = { rawBody: text.slice(0, 500), parseError: parseWarning };
1624
+ this.log.warn("Failed to parse error response as JSON", {
1625
+ ...isDebug2() && { requestId },
1626
+ url: response.url,
1627
+ status: response.status,
1628
+ parseError: parseWarning,
1629
+ bodyPreview: text.slice(0, 200)
1630
+ });
1631
+ }
1632
+ }
1633
+ const message = this.extractErrorMessage(errorBody, response.statusText);
1634
+ if (response.status !== 404) {
1635
+ this.log.error(`Request failed: ${response.status} ${message}`, isDebug2() ? { requestId } : undefined);
1636
+ }
1637
+ switch (response.status) {
1638
+ case 401:
1639
+ this.config.tokenProvider?.invalidate?.();
1640
+ throw new UnauthorizedError(message, errorBody);
1641
+ case 403:
1642
+ throw new ForbiddenError(message, errorBody);
1643
+ case 404:
1644
+ throw new NotFoundError(message, errorBody);
1645
+ case 422:
1646
+ throw new ValidationError(message, errorBody);
1647
+ default:
1648
+ throw new ApiError(message, response.status, errorBody);
1649
+ }
1650
+ }
1651
+ extractErrorMessage(body, fallback) {
1652
+ if (typeof body === "object" && body !== null) {
1653
+ const obj = body;
1654
+ if (typeof obj.message === "string")
1655
+ return obj.message;
1656
+ if (typeof obj.error === "string")
1657
+ return obj.error;
1658
+ if (typeof obj.imsx_description === "string")
1659
+ return obj.imsx_description;
1660
+ }
1661
+ return fallback;
1662
+ }
1663
+ sleep(ms) {
1664
+ return new Promise((resolve) => {
1665
+ setTimeout(resolve, ms);
1666
+ });
1667
+ }
1668
+ parseRetryAfter(retryAfter, attempt) {
1669
+ if (!retryAfter) {
1670
+ return INITIAL_RETRY_DELAY_MS * Math.pow(2, attempt);
1671
+ }
1672
+ const seconds = parseInt(retryAfter, 10);
1673
+ if (!isNaN(seconds)) {
1674
+ return seconds * 1000;
1675
+ }
1676
+ const date = Date.parse(retryAfter);
1677
+ if (!isNaN(date)) {
1678
+ const delayMs = date - Date.now();
1679
+ return Math.max(0, delayMs);
1680
+ }
1681
+ return INITIAL_RETRY_DELAY_MS * Math.pow(2, attempt);
1682
+ }
1683
+ }
1684
+ // ../../internal/client-infra/src/pagination/strategies.ts
1685
+ function hasNextLink(linkHeader) {
1686
+ if (!linkHeader)
1687
+ return false;
1688
+ return /rel=["']?next["']?(?:\s|;|,|$)/i.test(linkHeader);
1689
+ }
1690
+ function parseHeaderPagination(response, data) {
1691
+ const linkHeader = response.headers.get("Link");
1692
+ const totalHeader = response.headers.get("X-Total-Count");
1693
+ const parsedTotal = totalHeader ? parseInt(totalHeader, 10) : undefined;
1694
+ const total = parsedTotal !== undefined && !Number.isNaN(parsedTotal) ? parsedTotal : undefined;
1695
+ return {
1696
+ data,
1697
+ hasMore: hasNextLink(linkHeader),
1698
+ total
1699
+ };
1700
+ }
1701
+ // ../../internal/client-infra/src/validation/index.ts
1702
+ function issue(path, message) {
1703
+ return { path, message };
1704
+ }
1705
+ function validateWithSchema(schema, data, context) {
1706
+ const result = schema.safeParse(data);
1707
+ if (result.success) {
1708
+ return;
1709
+ }
1710
+ const issues = result.error.issues.map((errorIssue) => ({
1711
+ path: errorIssue.path.join(".") || "(root)",
1712
+ message: errorIssue.message
1713
+ }));
1714
+ throw createInputValidationError(`Invalid ${context} data`, issues);
1715
+ }
1716
+ function validateNonEmptyString(value, name) {
1717
+ if (typeof value !== "string" || value.trim() === "") {
1718
+ throw createInputValidationError(`Invalid ${name}`, [
1719
+ issue(name, "Must be a non-empty string")
1720
+ ]);
1721
+ }
1722
+ }
1723
+ export {
1724
+ ValidationError,
1725
+ UnauthorizedError,
1726
+ NotFoundError,
1727
+ InputValidationError,
1728
+ ForbiddenError,
1729
+ ApiError as CaseError
1730
+ };