@timeback/caliper 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.
- package/README.md +278 -0
- package/dist/client.d.ts +85 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +27 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/factory.d.ts +38 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1707 -0
- package/dist/lib/event-factories.d.ts +67 -0
- package/dist/lib/event-factories.d.ts.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/pagination.d.ts +26 -0
- package/dist/lib/pagination.d.ts.map +1 -0
- package/dist/lib/resolve.d.ts +21 -0
- package/dist/lib/resolve.d.ts.map +1 -0
- package/dist/lib/transport.d.ts +32 -0
- package/dist/lib/transport.d.ts.map +1 -0
- package/dist/resources/events.d.ts +241 -0
- package/dist/resources/events.d.ts.map +1 -0
- package/dist/resources/index.d.ts +6 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/jobs.d.ts +49 -0
- package/dist/resources/jobs.d.ts.map +1 -0
- package/dist/types/api.d.ts +101 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/client.d.ts +57 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/events.d.ts +203 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/timeback.d.ts +395 -0
- package/dist/types/timeback.d.ts.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +83 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# @timeback/caliper
|
|
2
|
+
|
|
3
|
+
TypeScript client for IMS Caliper Analytics v1.2 — learning activity events with Timeback Profile support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @timeback/caliper
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { CaliperClient } from '@timeback/caliper'
|
|
15
|
+
|
|
16
|
+
const caliper = new CaliperClient({
|
|
17
|
+
env: 'staging', // or 'production'
|
|
18
|
+
auth: {
|
|
19
|
+
clientId: 'your-client-id',
|
|
20
|
+
clientSecret: 'your-client-secret',
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Send a Timeback activity completion event
|
|
25
|
+
const result = await caliper.events.sendActivity('https://myapp.example.com/sensors/main', {
|
|
26
|
+
actor: {
|
|
27
|
+
id: 'https://api.example.com/users/123',
|
|
28
|
+
type: 'TimebackUser',
|
|
29
|
+
email: 'student@example.edu',
|
|
30
|
+
},
|
|
31
|
+
object: {
|
|
32
|
+
id: 'https://myapp.example.com/activities/456',
|
|
33
|
+
type: 'TimebackActivityContext',
|
|
34
|
+
subject: 'Math',
|
|
35
|
+
app: { name: 'My Learning App' },
|
|
36
|
+
},
|
|
37
|
+
metrics: [
|
|
38
|
+
{ type: 'totalQuestions', value: 10 },
|
|
39
|
+
{ type: 'correctQuestions', value: 8 },
|
|
40
|
+
{ type: 'xpEarned', value: 150 },
|
|
41
|
+
],
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const status = await caliper.jobs.waitForCompletion(result.jobId)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API Design
|
|
48
|
+
|
|
49
|
+
### Standalone vs Composed
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Composed
|
|
53
|
+
import { TimebackClient } from '@timeback/core'
|
|
54
|
+
|
|
55
|
+
// Standalone
|
|
56
|
+
const caliper = new CaliperClient({ env: 'staging', auth })
|
|
57
|
+
|
|
58
|
+
const client = new TimebackClient({ env: 'staging', auth })
|
|
59
|
+
client.caliper.events.sendActivity(sensor, input)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Client Structure
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const client = new CaliperClient(options)
|
|
66
|
+
|
|
67
|
+
// Events
|
|
68
|
+
client.events.send(sensor, events) // Send events
|
|
69
|
+
client.events.sendEnvelope(envelope) // Send raw envelope
|
|
70
|
+
client.events.validate(envelope) // Validate without storing
|
|
71
|
+
client.events.sendActivity(sensor, input) // Timeback Profile
|
|
72
|
+
client.events.sendTimeSpent(sensor, input) // Timeback Profile
|
|
73
|
+
client.events.list(params?) // List events
|
|
74
|
+
client.events.get(externalId) // Get event by ID
|
|
75
|
+
|
|
76
|
+
// Jobs
|
|
77
|
+
client.jobs.getStatus(jobId) // Check job status
|
|
78
|
+
client.jobs.waitForCompletion(jobId, options?) // Poll until complete
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Timeback Profile (Recommended)
|
|
82
|
+
|
|
83
|
+
The Timeback Profile extends Caliper with events optimized for the Timeback platform:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// Activity completion with metrics
|
|
87
|
+
await client.events.sendActivity(sensor, {
|
|
88
|
+
actor: {
|
|
89
|
+
id: 'https://api.example.com/users/123',
|
|
90
|
+
type: 'TimebackUser',
|
|
91
|
+
email: 'student@example.edu',
|
|
92
|
+
role: 'student',
|
|
93
|
+
},
|
|
94
|
+
object: {
|
|
95
|
+
id: 'https://myapp.example.com/activities/456',
|
|
96
|
+
type: 'TimebackActivityContext',
|
|
97
|
+
subject: 'Math', // Reading, Language, Science, etc.
|
|
98
|
+
app: { name: 'My Learning App' },
|
|
99
|
+
course: { name: 'Algebra 101' },
|
|
100
|
+
activity: { name: 'Chapter 1 Quiz' },
|
|
101
|
+
},
|
|
102
|
+
metrics: [
|
|
103
|
+
{ type: 'totalQuestions', value: 10 },
|
|
104
|
+
{ type: 'correctQuestions', value: 8 },
|
|
105
|
+
{ type: 'xpEarned', value: 150 },
|
|
106
|
+
{ type: 'masteredUnits', value: 2 },
|
|
107
|
+
],
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// Time spent tracking
|
|
111
|
+
await client.events.sendTimeSpent(sensor, {
|
|
112
|
+
actor: { id: '...', type: 'TimebackUser', email: 'student@example.edu' },
|
|
113
|
+
object: {
|
|
114
|
+
id: '...',
|
|
115
|
+
type: 'TimebackActivityContext',
|
|
116
|
+
subject: 'Reading',
|
|
117
|
+
app: { name: 'My App' },
|
|
118
|
+
},
|
|
119
|
+
metrics: [
|
|
120
|
+
{ type: 'active', value: 1800 }, // 30 minutes in seconds
|
|
121
|
+
{ type: 'inactive', value: 300 }, // 5 minutes
|
|
122
|
+
],
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Batching Events
|
|
127
|
+
|
|
128
|
+
Use factory functions to batch multiple events in a single envelope:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import {
|
|
132
|
+
CaliperClient,
|
|
133
|
+
createActivityEvent,
|
|
134
|
+
createTimeSpentEvent,
|
|
135
|
+
} from '@timeback/caliper'
|
|
136
|
+
|
|
137
|
+
const activityEvent = createActivityEvent({
|
|
138
|
+
actor: { ... },
|
|
139
|
+
object: { ... },
|
|
140
|
+
metrics: [{ type: 'correctQuestions', value: 8 }],
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
const timeSpentEvent = createTimeSpentEvent({
|
|
144
|
+
actor: { ... },
|
|
145
|
+
object: { ... },
|
|
146
|
+
metrics: [{ type: 'active', value: 1800 }],
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// Send both in one API call
|
|
150
|
+
const result = await client.events.send(sensor, [activityEvent, timeSpentEvent])
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Generic Caliper Events
|
|
154
|
+
|
|
155
|
+
For non-Timeback events, use the generic API:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const event = {
|
|
159
|
+
id: 'urn:uuid:...',
|
|
160
|
+
type: 'NavigationEvent',
|
|
161
|
+
actor: 'https://example.edu/users/123',
|
|
162
|
+
action: 'NavigatedTo',
|
|
163
|
+
object: 'https://example.edu/courses/456',
|
|
164
|
+
eventTime: new Date().toISOString(),
|
|
165
|
+
profile: 'GeneralProfile',
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
await client.events.send(sensor, [event])
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Job Tracking
|
|
172
|
+
|
|
173
|
+
Events are processed asynchronously. Track status with the jobs resource:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const result = await client.events.sendActivity(sensor, input)
|
|
177
|
+
|
|
178
|
+
// Poll until complete
|
|
179
|
+
const status = await client.jobs.waitForCompletion(result.jobId, {
|
|
180
|
+
timeoutMs: 30000, // Max wait time (default: 30s)
|
|
181
|
+
pollIntervalMs: 1000, // Check interval (default: 1s)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
if (status.state === 'completed') {
|
|
185
|
+
console.log('Processed:', status.returnValue?.results)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Or check manually
|
|
189
|
+
const status = await client.jobs.getStatus(result.jobId)
|
|
190
|
+
// status.state: 'waiting' | 'active' | 'completed' | 'failed'
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Authentication
|
|
194
|
+
|
|
195
|
+
The client handles OAuth2 token management automatically:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
// Environment mode (recommended for Timeback APIs)
|
|
199
|
+
const client = new CaliperClient({
|
|
200
|
+
env: 'staging', // or 'production'
|
|
201
|
+
auth: {
|
|
202
|
+
clientId: 'xxx',
|
|
203
|
+
clientSecret: 'xxx',
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
// Explicit mode (custom API)
|
|
208
|
+
const client = new CaliperClient({
|
|
209
|
+
baseUrl: 'https://caliper.example.com',
|
|
210
|
+
auth: {
|
|
211
|
+
clientId: 'xxx',
|
|
212
|
+
clientSecret: 'xxx',
|
|
213
|
+
authUrl: 'https://auth.example.com/oauth2/token',
|
|
214
|
+
},
|
|
215
|
+
})
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Tokens are cached and refreshed automatically before expiry.
|
|
219
|
+
|
|
220
|
+
### Error Handling
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { ApiError } from '@timeback/caliper'
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
await client.events.get('invalid-id')
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (error instanceof ApiError) {
|
|
229
|
+
console.log(error.status) // HTTP status
|
|
230
|
+
console.log(error.message) // Error message
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Configuration
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
new CaliperClient({
|
|
239
|
+
// Environment mode (Timeback APIs)
|
|
240
|
+
env: 'staging' | 'production',
|
|
241
|
+
auth: {
|
|
242
|
+
clientId: string,
|
|
243
|
+
clientSecret: string,
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
// OR Explicit mode (custom API)
|
|
247
|
+
baseUrl: string,
|
|
248
|
+
auth: {
|
|
249
|
+
clientId: string,
|
|
250
|
+
clientSecret: string,
|
|
251
|
+
authUrl: string,
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
// Optional
|
|
255
|
+
fetch?: typeof fetch, // Custom fetch implementation
|
|
256
|
+
timeout?: number, // Request timeout in ms (default: 30000)
|
|
257
|
+
|
|
258
|
+
// Internal (for composition with @timeback/core)
|
|
259
|
+
transport?: Transport, // Shared HTTP transport
|
|
260
|
+
})
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Debug Mode
|
|
264
|
+
|
|
265
|
+
Enable debug logging by setting `DEBUG=1` or `DEBUG=true`:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
DEBUG=1 bun run my-script.ts
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
This outputs detailed logs for HTTP requests and authentication:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
[2025-01-15T10:30:00.000Z] DEBUG [caliper:auth] Fetching new access token...
|
|
275
|
+
[2025-01-15T10:30:00.500Z] DEBUG [caliper:auth] Token acquired (500ms, expires in 3600s)
|
|
276
|
+
[2025-01-15T10:30:00.501Z] DEBUG [caliper:http] → POST https://api.example.com/caliper/event
|
|
277
|
+
[2025-01-15T10:30:00.800Z] DEBUG [caliper:http] ← 202 Accepted (299ms)
|
|
278
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caliper Client
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Caliper Analytics SDK.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Caliper Analytics API client.
|
|
8
|
+
*
|
|
9
|
+
* Provides methods to send, list, and retrieve Caliper learning events,
|
|
10
|
+
* as well as track async processing jobs.
|
|
11
|
+
*
|
|
12
|
+
* @example Environment mode (Timeback APIs)
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const client = new CaliperClient({
|
|
15
|
+
* env: 'staging', // or 'production'
|
|
16
|
+
* auth: {
|
|
17
|
+
* clientId: 'your-client-id',
|
|
18
|
+
* clientSecret: 'your-client-secret',
|
|
19
|
+
* },
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Provider mode (shared tokens)
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { TimebackProvider } from '@timeback/internal-client-infra'
|
|
26
|
+
*
|
|
27
|
+
* const provider = new TimebackProvider({
|
|
28
|
+
* platform: 'BEYOND_AI',
|
|
29
|
+
* env: 'staging',
|
|
30
|
+
* auth: { clientId: '...', clientSecret: '...' },
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* const client = new CaliperClient({ provider })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example Explicit mode (custom API)
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const client = new CaliperClient({
|
|
39
|
+
* baseUrl: 'https://caliper.example.com',
|
|
40
|
+
* auth: {
|
|
41
|
+
* clientId: 'your-client-id',
|
|
42
|
+
* clientSecret: 'your-client-secret',
|
|
43
|
+
* authUrl: 'https://auth.example.com/oauth2/token',
|
|
44
|
+
* },
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Environment variables fallback
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Set CALIPER_BASE_URL, CALIPER_TOKEN_URL,
|
|
51
|
+
* // CALIPER_CLIENT_ID, CALIPER_CLIENT_SECRET
|
|
52
|
+
* const client = new CaliperClient()
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example Sending events
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const result = await client.events.send(
|
|
58
|
+
* 'https://example.edu/sensors/lms',
|
|
59
|
+
* [{
|
|
60
|
+
* id: 'urn:uuid:...',
|
|
61
|
+
* type: 'NavigationEvent',
|
|
62
|
+
* actor: 'https://example.edu/users/123',
|
|
63
|
+
* action: 'NavigatedTo',
|
|
64
|
+
* object: 'https://example.edu/courses/456',
|
|
65
|
+
* eventTime: new Date().toISOString(),
|
|
66
|
+
* profile: 'GeneralProfile',
|
|
67
|
+
* }]
|
|
68
|
+
* )
|
|
69
|
+
*
|
|
70
|
+
* // Wait for processing
|
|
71
|
+
* const status = await client.jobs.waitForCompletion(result.jobId)
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const CaliperClient: {
|
|
75
|
+
new (config?: import("./types").CaliperClientConfig): {
|
|
76
|
+
readonly transport: import("./types").CaliperTransportLike;
|
|
77
|
+
readonly _provider?: import("@timeback/internal-client-infra").TimebackProvider | undefined;
|
|
78
|
+
readonly events: import("./resources").EventsResource;
|
|
79
|
+
readonly jobs: import("./resources").JobsResource;
|
|
80
|
+
getTransport(): import("./types").CaliperTransportLike;
|
|
81
|
+
checkAuth(): Promise<import("@timeback/internal-client-infra").AuthCheckResult>;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export type { CaliperClientInstance } from './types';
|
|
85
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;CAAwB,CAAA;AAElD,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caliper Constants
|
|
3
|
+
*
|
|
4
|
+
* Configuration constants for the Caliper Analytics client.
|
|
5
|
+
*/
|
|
6
|
+
import type { ClientUrlMaps, Platform } from '@timeback/internal-client-infra';
|
|
7
|
+
/**
|
|
8
|
+
* Environment variable names for Caliper configuration.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CALIPER_ENV_VARS: {
|
|
11
|
+
readonly baseUrl: "CALIPER_BASE_URL";
|
|
12
|
+
readonly authUrl: "CALIPER_TOKEN_URL";
|
|
13
|
+
readonly clientId: "CALIPER_CLIENT_ID";
|
|
14
|
+
readonly clientSecret: "CALIPER_CLIENT_SECRET";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Caliper JSON-LD context version.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CALIPER_DATA_VERSION = "http://purl.imsglobal.org/ctx/caliper/v1p2";
|
|
20
|
+
/**
|
|
21
|
+
* Get URL maps for a specific platform.
|
|
22
|
+
* Defaults to 'BEYOND_AI' for backwards compatibility.
|
|
23
|
+
* @param platform - Platform name
|
|
24
|
+
* @returns Client URL maps for the platform
|
|
25
|
+
*/
|
|
26
|
+
export declare function getUrlMapsForPlatform(platform?: Platform): ClientUrlMaps;
|
|
27
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAE9E;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAA;AAEV;;GAEG;AACH,eAAO,MAAM,oBAAoB,+CAA+C,CAAA;AAEhF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,GAAE,QAA2B,GAAG,aAAa,CAM1F"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caliper Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Re-exports common errors from `@timeback/internal-client-infra`.
|
|
5
|
+
*/
|
|
6
|
+
export { ApiError as CaliperError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError, } from '@timeback/internal-client-infra';
|
|
7
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,QAAQ,IAAI,YAAY,EACxB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,GACf,MAAM,iCAAiC,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caliper Client Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates CaliperClient classes bound to specific provider registries.
|
|
5
|
+
*/
|
|
6
|
+
import { EventsResource, JobsResource } from './resources';
|
|
7
|
+
import type { AuthCheckResult, ProviderRegistry, TimebackProvider } from '@timeback/internal-client-infra';
|
|
8
|
+
import type { CaliperClientConfig, CaliperTransportLike } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Create a CaliperClient class bound to a specific provider registry.
|
|
11
|
+
*
|
|
12
|
+
* @param registry - Provider registry to use (defaults to all Timeback platforms)
|
|
13
|
+
* @returns CaliperClient class bound to the registry
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCaliperClient(registry?: ProviderRegistry): {
|
|
16
|
+
new (config?: CaliperClientConfig): {
|
|
17
|
+
/** @internal */
|
|
18
|
+
readonly transport: CaliperTransportLike;
|
|
19
|
+
/** @internal */
|
|
20
|
+
readonly _provider?: TimebackProvider | undefined;
|
|
21
|
+
/** Send and query Caliper learning events for analytics and activity tracking */
|
|
22
|
+
readonly events: EventsResource;
|
|
23
|
+
/** Create and monitor batch event processing jobs for high-volume event ingestion */
|
|
24
|
+
readonly jobs: JobsResource;
|
|
25
|
+
/**
|
|
26
|
+
* Get the underlying transport for advanced use cases.
|
|
27
|
+
* @returns The transport instance used by this client
|
|
28
|
+
*/
|
|
29
|
+
getTransport(): CaliperTransportLike;
|
|
30
|
+
/**
|
|
31
|
+
* Verify that OAuth authentication is working.
|
|
32
|
+
* @returns Auth check result
|
|
33
|
+
* @throws {Error} If client was initialized with custom transport (no provider)
|
|
34
|
+
*/
|
|
35
|
+
checkAuth(): Promise<AuthCheckResult>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAC1G,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAExE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,gBAA4C;;QAQxF,gBAAgB;;QAGhB,gBAAgB;;QAGhB,iFAAiF;;QAEjF,qFAAqF;;QA0CrF;;;WAGG;;QAKH;;;;WAIG;;;EASJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caliper Analytics client SDK for Timeback.
|
|
3
|
+
*
|
|
4
|
+
* Caliper Analytics client SDK for Timeback.
|
|
5
|
+
*
|
|
6
|
+
* @example Timeback Profile - Activity Completed (recommended)
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { CaliperClient } from '@timeback/caliper'
|
|
9
|
+
*
|
|
10
|
+
* const client = new CaliperClient({
|
|
11
|
+
* env: 'staging',
|
|
12
|
+
* auth: {
|
|
13
|
+
* clientId: 'your-client-id',
|
|
14
|
+
* clientSecret: 'your-client-secret',
|
|
15
|
+
* },
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Send activity completion with metrics
|
|
19
|
+
* const result = await client.events.sendActivity(
|
|
20
|
+
* 'https://myapp.example.com/sensors/main',
|
|
21
|
+
* {
|
|
22
|
+
* actor: {
|
|
23
|
+
* id: 'https://api.example.com/users/123',
|
|
24
|
+
* type: 'TimebackUser',
|
|
25
|
+
* email: 'student@example.edu',
|
|
26
|
+
* },
|
|
27
|
+
* object: {
|
|
28
|
+
* id: 'https://myapp.example.com/activities/456',
|
|
29
|
+
* type: 'TimebackActivityContext',
|
|
30
|
+
* subject: 'Math',
|
|
31
|
+
* app: { name: 'My Learning App' },
|
|
32
|
+
* },
|
|
33
|
+
* metrics: [
|
|
34
|
+
* { type: 'totalQuestions', value: 10 },
|
|
35
|
+
* { type: 'correctQuestions', value: 8 },
|
|
36
|
+
* { type: 'xpEarned', value: 150 },
|
|
37
|
+
* ],
|
|
38
|
+
* },
|
|
39
|
+
* )
|
|
40
|
+
*
|
|
41
|
+
* // Wait for processing
|
|
42
|
+
* const status = await client.jobs.waitForCompletion(result.jobId)
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Timeback Profile - Time Spent
|
|
46
|
+
* ```typescript
|
|
47
|
+
* await client.events.sendTimeSpent(
|
|
48
|
+
* 'https://myapp.example.com/sensors/main',
|
|
49
|
+
* {
|
|
50
|
+
* actor: { id: '...', type: 'TimebackUser', email: 'student@example.edu' },
|
|
51
|
+
* object: { id: '...', type: 'TimebackActivityContext', subject: 'Reading', app: { name: 'My App' } },
|
|
52
|
+
* metrics: [
|
|
53
|
+
* { type: 'active', value: 1800 }, // 30 minutes
|
|
54
|
+
* { type: 'inactive', value: 300 }, // 5 minutes
|
|
55
|
+
* ],
|
|
56
|
+
* },
|
|
57
|
+
* )
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Generic Caliper Events
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // For non-Timeback Caliper events, use the generic method
|
|
63
|
+
* await client.events.send('https://sensor.url', [genericCaliperEvent])
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export { CaliperClient } from './client';
|
|
67
|
+
export { createCaliperClient } from './factory';
|
|
68
|
+
export type { CaliperClientInstance } from './client';
|
|
69
|
+
export type { CaliperClientConfig, Environment, EnvAuth, ExplicitAuth } from './types/client';
|
|
70
|
+
export type { AuthCheckResult } from '@timeback/internal-client-infra';
|
|
71
|
+
export { createActivityEvent, createTimeSpentEvent } from './lib/event-factories';
|
|
72
|
+
export type { TimebackUser, TimebackUserRole, TimebackActivityContext, TimebackSubject, TimebackApp, TimebackCourse, TimebackActivity, TimebackActivityMetric, TimebackActivityMetricsCollection, ActivityMetricType, TimeSpentMetric, TimebackTimeSpentMetricsCollection, TimeSpentMetricType, ActivityCompletedEvent, TimeSpentEvent, TimebackEvent, ActivityCompletedInput, TimeSpentInput, } from './types/timeback';
|
|
73
|
+
export { CALIPER_DATA_VERSION } from './constants';
|
|
74
|
+
export type { CaliperEnvelope, CaliperEvent, CaliperProfile, JobStatus, ListEventsParams, SendEventsResult, StoredEvent, ValidationResult, } from './types';
|
|
75
|
+
export { Transport } from './lib';
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAMH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAE/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7F,YAAY,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAMtE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjF,YAAY,EACX,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,iCAAiC,EACjC,kBAAkB,EAClB,eAAe,EACf,kCAAkC,EAClC,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,cAAc,GACd,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,YAAY,EACX,eAAe,EACf,YAAY,EACZ,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GAChB,MAAM,SAAS,CAAA;AAMhB,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA"}
|