@timeback/edubridge 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 +220 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +1217 -0
- package/dist/factory.d.ts +46 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1566 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/index.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 +49 -0
- package/dist/lib/transport.d.ts.map +1 -0
- package/dist/resources/analytics.d.ts +56 -0
- package/dist/resources/analytics.d.ts.map +1 -0
- package/dist/resources/applications.d.ts +30 -0
- package/dist/resources/applications.d.ts.map +1 -0
- package/dist/resources/enrollments.d.ts +71 -0
- package/dist/resources/enrollments.d.ts.map +1 -0
- package/dist/resources/index.d.ts +10 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/learning-reports.d.ts +30 -0
- package/dist/resources/learning-reports.d.ts.map +1 -0
- package/dist/resources/subject-track.d.ts +48 -0
- package/dist/resources/subject-track.d.ts.map +1 -0
- package/dist/resources/users.d.ts +53 -0
- package/dist/resources/users.d.ts.map +1 -0
- package/dist/types/analytics.d.ts +208 -0
- package/dist/types/analytics.d.ts.map +1 -0
- package/dist/types/applications.d.ts +27 -0
- package/dist/types/applications.d.ts.map +1 -0
- package/dist/types/base.d.ts +38 -0
- package/dist/types/base.d.ts.map +1 -0
- package/dist/types/client.d.ts +52 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/enrollments.d.ts +113 -0
- package/dist/types/enrollments.d.ts.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/learning-reports.d.ts +27 -0
- package/dist/types/learning-reports.d.ts.map +1 -0
- package/dist/types/subject-track.d.ts +54 -0
- package/dist/types/subject-track.d.ts.map +1 -0
- package/dist/types/users.d.ts +107 -0
- package/dist/types/users.d.ts.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +64 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# @timeback/edubridge
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Edubridge API — simplified course enrollment and analytics, abstracting OneRoster complexity.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @timeback/edubridge
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { EdubridgeClient } from '@timeback/edubridge'
|
|
15
|
+
|
|
16
|
+
const edubridge = new EdubridgeClient({
|
|
17
|
+
env: 'staging', // or 'production'
|
|
18
|
+
auth: {
|
|
19
|
+
clientId: 'your-client-id',
|
|
20
|
+
clientSecret: 'your-client-secret',
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const enrollment = await edubridge.enrollments.enroll(userId, courseId)
|
|
25
|
+
const enrollments = await edubridge.enrollments.getByUser(userId)
|
|
26
|
+
const students = await edubridge.users.listStudents()
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Design
|
|
30
|
+
|
|
31
|
+
### Standalone vs Composed
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Composed
|
|
35
|
+
import { TimebackClient } from '@timeback/core'
|
|
36
|
+
|
|
37
|
+
// Standalone
|
|
38
|
+
const edubridge = new EdubridgeClient({ env: 'staging', auth })
|
|
39
|
+
|
|
40
|
+
const client = new TimebackClient({ env: 'staging', auth })
|
|
41
|
+
client.edubridge.enrollments.enroll(userId, courseId)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Client Structure
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const client = new EdubridgeClient(options)
|
|
48
|
+
|
|
49
|
+
// Enrollments
|
|
50
|
+
client.enrollments.getByUser(userId)
|
|
51
|
+
client.enrollments.enroll(userId, courseId, schoolId?, options?)
|
|
52
|
+
client.enrollments.unenroll(userId, courseId, schoolId?)
|
|
53
|
+
client.enrollments.resetGoals(courseId)
|
|
54
|
+
client.enrollments.resetProgress(userId, courseId)
|
|
55
|
+
client.enrollments.getDefaultClass(courseId, schoolId?)
|
|
56
|
+
|
|
57
|
+
// Users
|
|
58
|
+
client.users.listByRole(params)
|
|
59
|
+
client.users.listStudents(params?)
|
|
60
|
+
client.users.listTeachers(params?)
|
|
61
|
+
client.users.search(roles, searchTerm, limit?)
|
|
62
|
+
|
|
63
|
+
// Analytics
|
|
64
|
+
client.analytics.getActivity(params)
|
|
65
|
+
client.analytics.getWeeklyFacts(params)
|
|
66
|
+
client.analytics.getEnrollmentFacts(params)
|
|
67
|
+
client.analytics.getHighestGradeMastered(studentId, subject)
|
|
68
|
+
|
|
69
|
+
// Applications
|
|
70
|
+
client.applications.list()
|
|
71
|
+
client.applications.getMetrics(applicationSourcedId)
|
|
72
|
+
|
|
73
|
+
// Subject Tracks
|
|
74
|
+
client.subjectTracks.list()
|
|
75
|
+
client.subjectTracks.get(id)
|
|
76
|
+
client.subjectTracks.create(data)
|
|
77
|
+
client.subjectTracks.update(id, data)
|
|
78
|
+
client.subjectTracks.delete(id)
|
|
79
|
+
client.subjectTracks.listGroups()
|
|
80
|
+
|
|
81
|
+
// Learning Reports
|
|
82
|
+
client.learningReports.getMapProfile(userId)
|
|
83
|
+
client.learningReports.getTimeSaved(userId)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Enrollments
|
|
87
|
+
|
|
88
|
+
The enrollments resource handles OneRoster complexity automatically:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Enroll a student in a course (creates class, term, etc. automatically)
|
|
92
|
+
const enrollment = await client.enrollments.enroll(userId, courseId, schoolId, {
|
|
93
|
+
role: 'student',
|
|
94
|
+
metadata: {
|
|
95
|
+
goals: {
|
|
96
|
+
dailyXp: 100,
|
|
97
|
+
dailyActiveMinutes: 30,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// Get all enrollments for a user
|
|
103
|
+
const enrollments = await client.enrollments.getByUser(userId)
|
|
104
|
+
|
|
105
|
+
// Unenroll from a course
|
|
106
|
+
await client.enrollments.unenroll(userId, courseId)
|
|
107
|
+
|
|
108
|
+
// Reset goals for all users in a course
|
|
109
|
+
const result = await client.enrollments.resetGoals(courseId)
|
|
110
|
+
console.log(`Updated ${result.updated} enrollments`)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Analytics
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// Get activity for a date range
|
|
117
|
+
const activity = await client.analytics.getActivity({
|
|
118
|
+
userId: 'user-id',
|
|
119
|
+
startDate: '2025-01-01',
|
|
120
|
+
endDate: '2025-01-31',
|
|
121
|
+
timezone: 'America/New_York',
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// Get weekly facts
|
|
125
|
+
const facts = await client.analytics.getWeeklyFacts({
|
|
126
|
+
userId: 'user-id',
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// Get highest grade mastered
|
|
130
|
+
const gradeData = await client.analytics.getHighestGradeMastered('student-id', 'math')
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Authentication
|
|
134
|
+
|
|
135
|
+
The client handles OAuth2 token management automatically:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// Environment mode (recommended for Timeback APIs)
|
|
139
|
+
const client = new EdubridgeClient({
|
|
140
|
+
env: 'staging', // or 'production'
|
|
141
|
+
auth: {
|
|
142
|
+
clientId: 'xxx',
|
|
143
|
+
clientSecret: 'xxx',
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// Explicit mode (custom API)
|
|
148
|
+
const client = new EdubridgeClient({
|
|
149
|
+
baseUrl: 'https://api.example.com',
|
|
150
|
+
auth: {
|
|
151
|
+
clientId: 'xxx',
|
|
152
|
+
clientSecret: 'xxx',
|
|
153
|
+
authUrl: 'https://auth.example.com/oauth2/token',
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Tokens are cached and refreshed automatically before expiry.
|
|
159
|
+
|
|
160
|
+
### Error Handling
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { EdubridgeError, NotFoundError } from '@timeback/edubridge'
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
await client.enrollments.getByUser('invalid-id')
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof NotFoundError) {
|
|
169
|
+
console.log('User not found')
|
|
170
|
+
} else if (error instanceof EdubridgeError) {
|
|
171
|
+
console.log(error.statusCode) // HTTP status
|
|
172
|
+
console.log(error.message)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Configuration
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
new EdubridgeClient({
|
|
181
|
+
// Environment mode (Timeback APIs)
|
|
182
|
+
env: 'staging' | 'production',
|
|
183
|
+
auth: {
|
|
184
|
+
clientId: string,
|
|
185
|
+
clientSecret: string,
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
// OR Explicit mode (custom API)
|
|
189
|
+
baseUrl: string,
|
|
190
|
+
auth: {
|
|
191
|
+
clientId: string,
|
|
192
|
+
clientSecret: string,
|
|
193
|
+
authUrl: string,
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
// Optional
|
|
197
|
+
fetch?: typeof fetch, // Custom fetch implementation
|
|
198
|
+
timeout?: number, // Request timeout in ms (default: 30000)
|
|
199
|
+
|
|
200
|
+
// Internal (for composition with @timeback/core)
|
|
201
|
+
transport?: Transport, // Shared HTTP transport
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Debug Mode
|
|
206
|
+
|
|
207
|
+
Enable debug logging by setting `DEBUG=1` or `DEBUG=true`:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
DEBUG=1 bun run my-script.ts
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
This outputs detailed logs for HTTP requests and authentication:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
[2025-01-15T10:30:00.000Z] DEBUG [edubridge:auth] Fetching new access token...
|
|
217
|
+
[2025-01-15T10:30:00.500Z] DEBUG [edubridge:auth] Token acquired (500ms, expires in 3600s)
|
|
218
|
+
[2025-01-15T10:30:00.501Z] DEBUG [edubridge:http] → POST https://api.example.com/edubridge/enrollments/enroll/...
|
|
219
|
+
[2025-01-15T10:30:00.800Z] DEBUG [edubridge:http] ← 201 Created (299ms)
|
|
220
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edubridge Client
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Edubridge SDK.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Edubridge API client for simplified enrollment and analytics operations.
|
|
8
|
+
*
|
|
9
|
+
* Provides access to Edubridge endpoints including course-centric enrollments,
|
|
10
|
+
* user management, analytics, and learning reports.
|
|
11
|
+
*
|
|
12
|
+
* @example Environment mode (Timeback APIs)
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const client = new EdubridgeClient({
|
|
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 EdubridgeClient({ provider })
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example Explicit mode (custom API)
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const client = new EdubridgeClient({
|
|
39
|
+
* baseUrl: 'https://api.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 EDUBRIDGE_BASE_URL, EDUBRIDGE_TOKEN_URL,
|
|
51
|
+
* // EDUBRIDGE_CLIENT_ID, EDUBRIDGE_CLIENT_SECRET
|
|
52
|
+
* const client = new EdubridgeClient()
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const EdubridgeClient: {
|
|
56
|
+
new (config?: import("./types").EdubridgeClientConfig): {
|
|
57
|
+
readonly transport: import("./types").EdubridgeTransportLike;
|
|
58
|
+
readonly _provider?: import("@timeback/internal-client-infra").TimebackProvider | undefined;
|
|
59
|
+
readonly enrollments: import("./resources").EnrollmentsResource;
|
|
60
|
+
readonly users: import("./resources").UsersResource;
|
|
61
|
+
readonly analytics: import("./resources").AnalyticsResource;
|
|
62
|
+
readonly applications: import("./resources").ApplicationsResource;
|
|
63
|
+
readonly subjectTracks: import("./resources").SubjectTrackResource;
|
|
64
|
+
readonly learningReports: import("./resources").LearningReportsResource;
|
|
65
|
+
getTransport(): import("./types").EdubridgeTransportLike;
|
|
66
|
+
checkAuth(): Promise<import("@timeback/internal-client-infra").AuthCheckResult>;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
export type { EdubridgeClientInstance } from './types';
|
|
70
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;CAA0B,CAAA;AAEtD,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edubridge Constants
|
|
3
|
+
*
|
|
4
|
+
* Configuration constants for the Edubridge client.
|
|
5
|
+
*/
|
|
6
|
+
import type { ClientUrlMaps, Platform } from '@timeback/internal-client-infra';
|
|
7
|
+
/**
|
|
8
|
+
* Environment variable names for fallback config.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EDUBRIDGE_ENV_VARS: {
|
|
11
|
+
readonly baseUrl: "EDUBRIDGE_BASE_URL";
|
|
12
|
+
readonly clientId: "EDUBRIDGE_CLIENT_ID";
|
|
13
|
+
readonly clientSecret: "EDUBRIDGE_CLIENT_SECRET";
|
|
14
|
+
readonly authUrl: "EDUBRIDGE_TOKEN_URL";
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get URL maps for a specific platform.
|
|
18
|
+
* Defaults to 'BEYOND_AI' for backwards compatibility.
|
|
19
|
+
*
|
|
20
|
+
* Note: Edubridge uses the main API server (same as OneRoster).
|
|
21
|
+
* @param platform - Platform name
|
|
22
|
+
* @returns Client URL maps for the platform
|
|
23
|
+
*/
|
|
24
|
+
export declare function getUrlMapsForPlatform(platform?: Platform): ClientUrlMaps;
|
|
25
|
+
//# 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;AAM9E;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;CAKrB,CAAA;AAMV;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,GAAE,QAA2B,GAAG,aAAa,CAM1F"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edubridge Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Re-exports common errors from `@timeback/internal-client-infra`.
|
|
5
|
+
* Edubridge uses the same error format as other Timeback clients.
|
|
6
|
+
*/
|
|
7
|
+
import { ApiError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError } from '@timeback/internal-client-infra';
|
|
8
|
+
export { ApiError as EdubridgeError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError, };
|
|
9
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,QAAQ,EACR,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,MAAM,iCAAiC,CAAA;AAExC,OAAO,EACN,QAAQ,IAAI,cAAc,EAC1B,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,GACf,CAAA"}
|