@timeback/core 0.1.7-beta.20260303225507 → 0.1.7-beta.20260305053803
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors.js +2 -1
- package/dist/index.js +147 -12
- package/dist/utils.js +2 -1
- package/package.json +1 -1
package/dist/errors.js
CHANGED
|
@@ -421,7 +421,8 @@ var init_util = __esm(() => {
|
|
|
421
421
|
});
|
|
422
422
|
|
|
423
423
|
// ../../internal/constants/src/endpoints.ts
|
|
424
|
-
var
|
|
424
|
+
var PLATFORM_BEYOND_AI = "BEYOND_AI";
|
|
425
|
+
var DEFAULT_PLATFORM = PLATFORM_BEYOND_AI;
|
|
425
426
|
var BEYONDAI_TOKEN_URLS = {
|
|
426
427
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
427
428
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
package/dist/index.js
CHANGED
|
@@ -848,7 +848,9 @@ var init_util = __esm2(() => {
|
|
|
848
848
|
({ TextEncoder, TextDecoder } = globalThis);
|
|
849
849
|
util_default = { TextEncoder, TextDecoder, promisify, log, inherits, _extend, callbackifyOnRejected, callbackify };
|
|
850
850
|
});
|
|
851
|
-
var
|
|
851
|
+
var PLATFORM_BEYOND_AI = "BEYOND_AI";
|
|
852
|
+
var PLATFORM_LEARNWITH_AI = "LEARNWITH_AI";
|
|
853
|
+
var DEFAULT_PLATFORM = PLATFORM_BEYOND_AI;
|
|
852
854
|
var BEYONDAI_TOKEN_URLS = {
|
|
853
855
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
854
856
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -2383,6 +2385,124 @@ var CALIPER_DATA_VERSION = "http://purl.imsglobal.org/ctx/caliper/v1p2";
|
|
|
2383
2385
|
function resolveToProvider2(config, registry = DEFAULT_PROVIDER_REGISTRY) {
|
|
2384
2386
|
return resolveToProvider(config, CALIPER_ENV_VARS, registry);
|
|
2385
2387
|
}
|
|
2388
|
+
var CALIPER_CONTEXT = "http://purl.imsglobal.org/ctx/caliper/v1p2";
|
|
2389
|
+
var CALIPER_TYPE = {
|
|
2390
|
+
PERSON: "Person",
|
|
2391
|
+
ASSIGNABLE_DIGITAL_RESOURCE: "AssignableDigitalResource",
|
|
2392
|
+
ACTIVITY_METRIC: "ActivityMetric",
|
|
2393
|
+
TIME_SPENT_METRIC: "TimeSpentMetric",
|
|
2394
|
+
ACTIVITY_METRICS_COLLECTION: "ActivityMetricsCollection",
|
|
2395
|
+
TIME_SPENT_METRICS_COLLECTION: "TimeSpentMetricsCollection",
|
|
2396
|
+
COURSE_OFFERING: "CourseOffering",
|
|
2397
|
+
SOFTWARE_APPLICATION: "SoftwareApplication"
|
|
2398
|
+
};
|
|
2399
|
+
var LEARNING_ACTIVITY_EVENT_TYPES = new Set([
|
|
2400
|
+
"ActivityEvent",
|
|
2401
|
+
"TimeSpentEvent",
|
|
2402
|
+
"AssignableEvent",
|
|
2403
|
+
"ViewEvent"
|
|
2404
|
+
]);
|
|
2405
|
+
|
|
2406
|
+
class LwaiEventTransformer {
|
|
2407
|
+
transformEnvelope(envelope) {
|
|
2408
|
+
const { data } = envelope;
|
|
2409
|
+
if (!Array.isArray(data))
|
|
2410
|
+
return envelope;
|
|
2411
|
+
const transformedData = data.map((event) => isDict(event) ? transformEvent(event) : event);
|
|
2412
|
+
return { ...envelope, data: transformedData };
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
function transformEvent(event) {
|
|
2416
|
+
const transformed = { ...event };
|
|
2417
|
+
if (!("@context" in transformed)) {
|
|
2418
|
+
transformed["@context"] = CALIPER_CONTEXT;
|
|
2419
|
+
}
|
|
2420
|
+
if (transformed.profile === "TimebackProfile") {
|
|
2421
|
+
transformed.profile = "AggregationProfile";
|
|
2422
|
+
}
|
|
2423
|
+
if (isDict(transformed.actor)) {
|
|
2424
|
+
transformed.actor = transformActor(transformed.actor);
|
|
2425
|
+
}
|
|
2426
|
+
if (isDict(transformed.object)) {
|
|
2427
|
+
transformed.object = transformObject(transformed.object, transformed.type);
|
|
2428
|
+
}
|
|
2429
|
+
if (isDict(transformed.generated)) {
|
|
2430
|
+
const eventType = transformed.type;
|
|
2431
|
+
if (eventType === "ActivityEvent") {
|
|
2432
|
+
transformed.generated = transformActivityMetrics(transformed.generated);
|
|
2433
|
+
} else if (eventType === "TimeSpentEvent") {
|
|
2434
|
+
transformed.generated = transformTimeSpentMetrics(transformed.generated);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
return transformed;
|
|
2438
|
+
}
|
|
2439
|
+
function transformActor(actor) {
|
|
2440
|
+
return { type: CALIPER_TYPE.PERSON, id: actor.id };
|
|
2441
|
+
}
|
|
2442
|
+
function transformObject(obj, eventType) {
|
|
2443
|
+
const shouldTransform = obj.type === "TimebackActivityContext" && eventType !== undefined && LEARNING_ACTIVITY_EVENT_TYPES.has(eventType);
|
|
2444
|
+
if (!shouldTransform)
|
|
2445
|
+
return { ...obj };
|
|
2446
|
+
const transformed = {
|
|
2447
|
+
type: CALIPER_TYPE.ASSIGNABLE_DIGITAL_RESOURCE,
|
|
2448
|
+
id: obj.id
|
|
2449
|
+
};
|
|
2450
|
+
if (obj.name) {
|
|
2451
|
+
transformed.name = obj.name;
|
|
2452
|
+
}
|
|
2453
|
+
if (isDict(obj.course)) {
|
|
2454
|
+
const isPartOf = { type: CALIPER_TYPE.COURSE_OFFERING, id: obj.course.id };
|
|
2455
|
+
if (obj.course.name) {
|
|
2456
|
+
isPartOf.name = obj.course.name;
|
|
2457
|
+
}
|
|
2458
|
+
transformed.isPartOf = isPartOf;
|
|
2459
|
+
}
|
|
2460
|
+
if (isDict(obj.app)) {
|
|
2461
|
+
transformed.extensions = {
|
|
2462
|
+
app: {
|
|
2463
|
+
name: obj.app.name,
|
|
2464
|
+
type: obj.app.type ?? CALIPER_TYPE.SOFTWARE_APPLICATION
|
|
2465
|
+
}
|
|
2466
|
+
};
|
|
2467
|
+
}
|
|
2468
|
+
return transformed;
|
|
2469
|
+
}
|
|
2470
|
+
function transformMetricsCollection(collection, collectionType, itemType, defaultMetricType) {
|
|
2471
|
+
const collectionId = typeof collection?.id === "string" ? collection.id : `urn:uuid:${crypto.randomUUID()}`;
|
|
2472
|
+
const transformed = {
|
|
2473
|
+
id: collectionId,
|
|
2474
|
+
type: collectionType
|
|
2475
|
+
};
|
|
2476
|
+
if (Array.isArray(collection.items)) {
|
|
2477
|
+
transformed.items = collection.items.map((item) => {
|
|
2478
|
+
if (!isDict(item))
|
|
2479
|
+
return item;
|
|
2480
|
+
const metricType = typeof item.type === "string" ? item.type : "";
|
|
2481
|
+
const pascalType = metricType ? metricType[0].toUpperCase() + metricType.slice(1) : defaultMetricType;
|
|
2482
|
+
return {
|
|
2483
|
+
id: `urn:uuid:${crypto.randomUUID()}`,
|
|
2484
|
+
type: itemType,
|
|
2485
|
+
metricType: pascalType,
|
|
2486
|
+
metricValue: item.value
|
|
2487
|
+
};
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
for (const [key, value] of Object.entries(collection)) {
|
|
2491
|
+
if (key !== "id" && key !== "type" && key !== "items") {
|
|
2492
|
+
transformed[key] = value;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
return transformed;
|
|
2496
|
+
}
|
|
2497
|
+
function transformActivityMetrics(collection) {
|
|
2498
|
+
return transformMetricsCollection(collection, CALIPER_TYPE.ACTIVITY_METRICS_COLLECTION, CALIPER_TYPE.ACTIVITY_METRIC, "");
|
|
2499
|
+
}
|
|
2500
|
+
function transformTimeSpentMetrics(collection) {
|
|
2501
|
+
return transformMetricsCollection(collection, CALIPER_TYPE.TIME_SPENT_METRICS_COLLECTION, CALIPER_TYPE.TIME_SPENT_METRIC, "Active");
|
|
2502
|
+
}
|
|
2503
|
+
function isDict(value) {
|
|
2504
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2505
|
+
}
|
|
2386
2506
|
var log3 = createScopedLogger("caliper");
|
|
2387
2507
|
|
|
2388
2508
|
class Transport extends BaseTransport {
|
|
@@ -17564,8 +17684,10 @@ class Paginator2 extends Paginator {
|
|
|
17564
17684
|
|
|
17565
17685
|
class EventsResource {
|
|
17566
17686
|
transport;
|
|
17567
|
-
|
|
17687
|
+
eventTransformer;
|
|
17688
|
+
constructor(transport, options) {
|
|
17568
17689
|
this.transport = transport;
|
|
17690
|
+
this.eventTransformer = options?.eventTransformer;
|
|
17569
17691
|
}
|
|
17570
17692
|
send(sensor, events) {
|
|
17571
17693
|
validateWithSchema(CaliperSendEventsInput, { sensor, events }, "send events");
|
|
@@ -17583,7 +17705,8 @@ class EventsResource {
|
|
|
17583
17705
|
sensor: envelope.sensor,
|
|
17584
17706
|
eventCount: envelope.data.length
|
|
17585
17707
|
});
|
|
17586
|
-
const
|
|
17708
|
+
const body = this.eventTransformer ? this.eventTransformer.transformEnvelope(envelope) : envelope;
|
|
17709
|
+
const response = await this.transport.request(this.transport.paths.send, { method: "POST", body });
|
|
17587
17710
|
log3.debug("Events queued for processing", { jobId: response.jobId });
|
|
17588
17711
|
return { jobId: response.jobId };
|
|
17589
17712
|
}
|
|
@@ -17767,6 +17890,7 @@ function createCaliperClient(registry2 = DEFAULT_PROVIDER_REGISTRY) {
|
|
|
17767
17890
|
jobs;
|
|
17768
17891
|
constructor(config3 = {}) {
|
|
17769
17892
|
const resolved = resolveToProvider2(config3, registry2);
|
|
17893
|
+
let eventTransformer;
|
|
17770
17894
|
if (resolved.mode === "transport") {
|
|
17771
17895
|
this.transport = resolved.transport;
|
|
17772
17896
|
log3.info("Client initialized with custom transport");
|
|
@@ -17784,13 +17908,16 @@ function createCaliperClient(registry2 = DEFAULT_PROVIDER_REGISTRY) {
|
|
|
17784
17908
|
timeout: provider.timeout,
|
|
17785
17909
|
paths
|
|
17786
17910
|
});
|
|
17911
|
+
if (provider.platform === PLATFORM_LEARNWITH_AI) {
|
|
17912
|
+
eventTransformer = new LwaiEventTransformer;
|
|
17913
|
+
}
|
|
17787
17914
|
log3.info("Client initialized", {
|
|
17788
17915
|
platform: provider.platform,
|
|
17789
17916
|
env: provider.env,
|
|
17790
17917
|
baseUrl
|
|
17791
17918
|
});
|
|
17792
17919
|
}
|
|
17793
|
-
this.events = new EventsResource(this.transport);
|
|
17920
|
+
this.events = new EventsResource(this.transport, { eventTransformer });
|
|
17794
17921
|
this.jobs = new JobsResource(this.transport);
|
|
17795
17922
|
}
|
|
17796
17923
|
getTransport() {
|
|
@@ -18234,7 +18361,8 @@ var init_util2 = __esm3(() => {
|
|
|
18234
18361
|
({ TextEncoder: TextEncoder2, TextDecoder: TextDecoder2 } = globalThis);
|
|
18235
18362
|
util_default2 = { TextEncoder: TextEncoder2, TextDecoder: TextDecoder2, promisify: promisify2, log: log4, inherits: inherits2, _extend: _extend2, callbackifyOnRejected: callbackifyOnRejected2, callbackify: callbackify2 };
|
|
18236
18363
|
});
|
|
18237
|
-
var
|
|
18364
|
+
var PLATFORM_BEYOND_AI2 = "BEYOND_AI";
|
|
18365
|
+
var DEFAULT_PLATFORM2 = PLATFORM_BEYOND_AI2;
|
|
18238
18366
|
var BEYONDAI_TOKEN_URLS2 = {
|
|
18239
18367
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
18240
18368
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -35240,7 +35368,8 @@ var init_util3 = __esm4(() => {
|
|
|
35240
35368
|
({ TextEncoder: TextEncoder3, TextDecoder: TextDecoder3 } = globalThis);
|
|
35241
35369
|
util_default3 = { TextEncoder: TextEncoder3, TextDecoder: TextDecoder3, promisify: promisify3, log: log6, inherits: inherits3, _extend: _extend3, callbackifyOnRejected: callbackifyOnRejected3, callbackify: callbackify3 };
|
|
35242
35370
|
});
|
|
35243
|
-
var
|
|
35371
|
+
var PLATFORM_BEYOND_AI3 = "BEYOND_AI";
|
|
35372
|
+
var DEFAULT_PLATFORM3 = PLATFORM_BEYOND_AI3;
|
|
35244
35373
|
var BEYONDAI_TOKEN_URLS3 = {
|
|
35245
35374
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
35246
35375
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -52154,7 +52283,8 @@ var init_util4 = __esm5(() => {
|
|
|
52154
52283
|
({ TextEncoder: TextEncoder4, TextDecoder: TextDecoder4 } = globalThis);
|
|
52155
52284
|
util_default4 = { TextEncoder: TextEncoder4, TextDecoder: TextDecoder4, promisify: promisify4, log: log7, inherits: inherits4, _extend: _extend4, callbackifyOnRejected: callbackifyOnRejected4, callbackify: callbackify4 };
|
|
52156
52285
|
});
|
|
52157
|
-
var
|
|
52286
|
+
var PLATFORM_BEYOND_AI4 = "BEYOND_AI";
|
|
52287
|
+
var DEFAULT_PLATFORM4 = PLATFORM_BEYOND_AI4;
|
|
52158
52288
|
var BEYONDAI_TOKEN_URLS4 = {
|
|
52159
52289
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
52160
52290
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -68945,7 +69075,8 @@ function createEdubridgeClient(registry22 = DEFAULT_PROVIDER_REGISTRY4) {
|
|
|
68945
69075
|
var EdubridgeClient = createEdubridgeClient();
|
|
68946
69076
|
|
|
68947
69077
|
// ../../internal/constants/src/endpoints.ts
|
|
68948
|
-
var
|
|
69078
|
+
var PLATFORM_BEYOND_AI5 = "BEYOND_AI";
|
|
69079
|
+
var DEFAULT_PLATFORM5 = PLATFORM_BEYOND_AI5;
|
|
68949
69080
|
var BEYONDAI_TOKEN_URLS5 = {
|
|
68950
69081
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
68951
69082
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -70477,7 +70608,8 @@ var init_util6 = __esm6(() => {
|
|
|
70477
70608
|
({ TextEncoder: TextEncoder6, TextDecoder: TextDecoder6 } = globalThis);
|
|
70478
70609
|
util_default6 = { TextEncoder: TextEncoder6, TextDecoder: TextDecoder6, promisify: promisify6, log: log10, inherits: inherits6, _extend: _extend6, callbackifyOnRejected: callbackifyOnRejected6, callbackify: callbackify6 };
|
|
70479
70610
|
});
|
|
70480
|
-
var
|
|
70611
|
+
var PLATFORM_BEYOND_AI6 = "BEYOND_AI";
|
|
70612
|
+
var DEFAULT_PLATFORM6 = PLATFORM_BEYOND_AI6;
|
|
70481
70613
|
var BEYONDAI_TOKEN_URLS6 = {
|
|
70482
70614
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
70483
70615
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -89206,7 +89338,8 @@ var init_util7 = __esm7(() => {
|
|
|
89206
89338
|
({ TextEncoder: TextEncoder7, TextDecoder: TextDecoder7 } = globalThis);
|
|
89207
89339
|
util_default7 = { TextEncoder: TextEncoder7, TextDecoder: TextDecoder7, promisify: promisify7, log: log11, inherits: inherits7, _extend: _extend7, callbackifyOnRejected: callbackifyOnRejected7, callbackify: callbackify7 };
|
|
89208
89340
|
});
|
|
89209
|
-
var
|
|
89341
|
+
var PLATFORM_BEYOND_AI7 = "BEYOND_AI";
|
|
89342
|
+
var DEFAULT_PLATFORM7 = PLATFORM_BEYOND_AI7;
|
|
89210
89343
|
var BEYONDAI_TOKEN_URLS7 = {
|
|
89211
89344
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
89212
89345
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -106666,7 +106799,8 @@ var init_util8 = __esm8(() => {
|
|
|
106666
106799
|
({ TextEncoder: TextEncoder8, TextDecoder: TextDecoder8 } = globalThis);
|
|
106667
106800
|
util_default8 = { TextEncoder: TextEncoder8, TextDecoder: TextDecoder8, promisify: promisify8, log: log12, inherits: inherits8, _extend: _extend8, callbackifyOnRejected: callbackifyOnRejected8, callbackify: callbackify8 };
|
|
106668
106801
|
});
|
|
106669
|
-
var
|
|
106802
|
+
var PLATFORM_BEYOND_AI8 = "BEYOND_AI";
|
|
106803
|
+
var DEFAULT_PLATFORM8 = PLATFORM_BEYOND_AI8;
|
|
106670
106804
|
var BEYONDAI_TOKEN_URLS8 = {
|
|
106671
106805
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
106672
106806
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
|
@@ -124271,7 +124405,8 @@ var init_util9 = __esm9(() => {
|
|
|
124271
124405
|
({ TextEncoder: TextEncoder9, TextDecoder: TextDecoder9 } = globalThis);
|
|
124272
124406
|
util_default9 = { TextEncoder: TextEncoder9, TextDecoder: TextDecoder9, promisify: promisify9, log: log13, inherits: inherits9, _extend: _extend9, callbackifyOnRejected: callbackifyOnRejected9, callbackify: callbackify9 };
|
|
124273
124407
|
});
|
|
124274
|
-
var
|
|
124408
|
+
var PLATFORM_BEYOND_AI9 = "BEYOND_AI";
|
|
124409
|
+
var DEFAULT_PLATFORM9 = PLATFORM_BEYOND_AI9;
|
|
124275
124410
|
var BEYONDAI_TOKEN_URLS9 = {
|
|
124276
124411
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
124277
124412
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|
package/dist/utils.js
CHANGED
|
@@ -438,7 +438,8 @@ var init_util = __esm2(() => {
|
|
|
438
438
|
({ TextEncoder, TextDecoder } = globalThis);
|
|
439
439
|
util_default = { TextEncoder, TextDecoder, promisify, log, inherits, _extend, callbackifyOnRejected, callbackify };
|
|
440
440
|
});
|
|
441
|
-
var
|
|
441
|
+
var PLATFORM_BEYOND_AI = "BEYOND_AI";
|
|
442
|
+
var DEFAULT_PLATFORM = PLATFORM_BEYOND_AI;
|
|
442
443
|
var BEYONDAI_TOKEN_URLS = {
|
|
443
444
|
staging: "https://staging-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
444
445
|
production: "https://prod-beyond-timeback-api-2-idp.auth.us-east-1.amazoncognito.com/oauth2/token"
|