memrise 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 +80 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +313 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Memrise API Client
|
|
2
|
+
|
|
3
|
+
Unofficial Memrise Community Courses API client JavaScript
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install memrise
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { MemriseClient } from "memrise";
|
|
15
|
+
|
|
16
|
+
// Initialize with username and password
|
|
17
|
+
const client = new MemriseClient("username", "password");
|
|
18
|
+
|
|
19
|
+
// Get your courses
|
|
20
|
+
const courses = await client.getMyCourses();
|
|
21
|
+
console.log(courses);
|
|
22
|
+
|
|
23
|
+
// Get course by ID or slug
|
|
24
|
+
const course = await client.getCourseById("123456");
|
|
25
|
+
const courseBySlug = await client.getCourseBySlug("my-course");
|
|
26
|
+
|
|
27
|
+
// Get course columns (to see what fields are available)
|
|
28
|
+
const columns = await client.getCourseColumns("123456");
|
|
29
|
+
console.log(columns);
|
|
30
|
+
// { "1": { "kind": "text", "label": "Word", ... }, ... }
|
|
31
|
+
|
|
32
|
+
// Add items to a course
|
|
33
|
+
await client.addThingToCourse("123456", {
|
|
34
|
+
"1": "hello",
|
|
35
|
+
"2": "こんにちは",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Get course levels
|
|
39
|
+
const levels = await client.getCourseLevels("123456");
|
|
40
|
+
|
|
41
|
+
// Add items to a specific level
|
|
42
|
+
await client.addThingToLevel("level-id", {
|
|
43
|
+
"1": "word",
|
|
44
|
+
"2": "definition",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Search pool
|
|
48
|
+
const results = await client.searchPool("pool-id", {
|
|
49
|
+
"1": "search term",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Get pool information
|
|
53
|
+
const pool = await client.getPool("pool-id");
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
### Constructor
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
new MemriseClient(username: string, password: string, clientId?: string)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Methods
|
|
65
|
+
|
|
66
|
+
- `getMyCourses(limit?, offset?)` - Get your courses
|
|
67
|
+
- `getCourseById(courseId)` - Get course by ID
|
|
68
|
+
- `getCourseBySlug(slug)` - Get course by slug
|
|
69
|
+
- `getCourseLevels(courseId)` - Get levels for a course
|
|
70
|
+
- `getCourseColumns(courseId)` - Get column configuration for a course
|
|
71
|
+
- `getCourseItems(courseId)` - Get all items in a course
|
|
72
|
+
- `addThingToCourse(courseId, columns, levelIndex?)` - Add item to course (default: first level)
|
|
73
|
+
- `addThingToLevel(levelId, columns)` - Add item to specific level
|
|
74
|
+
- `searchPool(poolId, columns, excludeThingIds?, originalOnly?)` - Search pool
|
|
75
|
+
- `getPool(poolId)` - Get pool information
|
|
76
|
+
- `getLearnable(learnableId)` - Get learnable item
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AddThingResponse, SearchPoolResponse, GetPoolResponse, GetDashboardCoursesResponse, DashboardCourse, CourseLevel, Learnable, AccessTokenResponse, AuthWebResponse, PoolColumnConfig } from "./types";
|
|
2
|
+
export declare class MemriseClient {
|
|
3
|
+
private client;
|
|
4
|
+
private cookie;
|
|
5
|
+
private csrfToken;
|
|
6
|
+
private accessToken;
|
|
7
|
+
private cookieJar;
|
|
8
|
+
private authReady;
|
|
9
|
+
constructor(username: string, password: string, clientId?: string);
|
|
10
|
+
private authenticateWithCredentials;
|
|
11
|
+
private mergeSetCookieCookies;
|
|
12
|
+
private extractFromCookie;
|
|
13
|
+
private ensureAuthenticated;
|
|
14
|
+
getCsrfToken(): Promise<string | null>;
|
|
15
|
+
getAccessToken(username: string, password: string, clientId?: string): Promise<AccessTokenResponse>;
|
|
16
|
+
authenticateWeb(token: string): Promise<AuthWebResponse>;
|
|
17
|
+
addThingToLevel(levelId: string, columns: Record<string, string>): Promise<AddThingResponse>;
|
|
18
|
+
addThingToCourse(courseId: string | number, columns: Record<string, string>, levelIndex?: number): Promise<AddThingResponse>;
|
|
19
|
+
searchPool(poolId: string | number, columns: Record<string, string>, excludeThingIds?: string[], originalOnly?: boolean): Promise<SearchPoolResponse>;
|
|
20
|
+
getPool(poolId: string | number): Promise<GetPoolResponse>;
|
|
21
|
+
getMyCourses(limit?: number, offset?: number): Promise<GetDashboardCoursesResponse>;
|
|
22
|
+
getCourseById(courseId: string | number): Promise<DashboardCourse | null>;
|
|
23
|
+
getCourseBySlug(slug: string): Promise<DashboardCourse | null>;
|
|
24
|
+
getCourseLevels(courseId: string | number, slug?: string): Promise<CourseLevel[]>;
|
|
25
|
+
getLearnable(learnableId: string | number): Promise<Learnable | null>;
|
|
26
|
+
getCourseItems(courseId: string | number): Promise<Learnable[]>;
|
|
27
|
+
getCourseColumns(courseId: string | number): Promise<Record<string, PoolColumnConfig>>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,2BAA2B,EAC3B,eAAe,EACf,WAAW,EACX,SAAS,EAGT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eAAe,CAAC;IAe1D,YAAY,CACjB,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,MAAU,GAChB,OAAO,CAAC,2BAA2B,CAAC;IAmBjC,aAAa,CAClB,QAAQ,EAAE,MAAM,GAAG,MAAM,GACvB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAgB5B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAc9D,eAAe,CACpB,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,EAAE,CAAC;IAUnB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAgBrE,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAuB/D,gBAAgB,CACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAe5C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
const DEFAULT_CLIENT_ID = "1e739f5e77704b57a703";
|
|
3
|
+
export class MemriseClient {
|
|
4
|
+
client = axios.create({
|
|
5
|
+
baseURL: "https://community-courses.memrise.com",
|
|
6
|
+
headers: {
|
|
7
|
+
origin: "https://community-courses.memrise.com",
|
|
8
|
+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
|
|
9
|
+
"x-requested-with": "XMLHttpRequest",
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
cookie;
|
|
13
|
+
csrfToken;
|
|
14
|
+
accessToken;
|
|
15
|
+
cookieJar;
|
|
16
|
+
authReady;
|
|
17
|
+
constructor(username, password, clientId = DEFAULT_CLIENT_ID) {
|
|
18
|
+
this.cookie = "";
|
|
19
|
+
this.csrfToken = null;
|
|
20
|
+
this.accessToken = null;
|
|
21
|
+
this.cookieJar = new Map();
|
|
22
|
+
this.authReady = this.authenticateWithCredentials(username, password, clientId);
|
|
23
|
+
}
|
|
24
|
+
async authenticateWithCredentials(username, password, clientId) {
|
|
25
|
+
const csrf = await this.getCsrfToken();
|
|
26
|
+
if (csrf) {
|
|
27
|
+
this.csrfToken = csrf;
|
|
28
|
+
this.client.defaults.headers.common["x-csrftoken"] = csrf;
|
|
29
|
+
}
|
|
30
|
+
const access = await this.getAccessToken(username, password, clientId);
|
|
31
|
+
this.accessToken = access.access_token.access_token;
|
|
32
|
+
// Don't set authorization header globally - v1.25 endpoints use session cookies only
|
|
33
|
+
// this.client.defaults.headers.common['authorization'] = `Bearer ${this.accessToken}`;
|
|
34
|
+
await this.authenticateWeb(this.accessToken);
|
|
35
|
+
}
|
|
36
|
+
mergeSetCookieCookies(setCookieValues) {
|
|
37
|
+
if (setCookieValues.length === 0)
|
|
38
|
+
return;
|
|
39
|
+
for (const item of setCookieValues) {
|
|
40
|
+
const firstPair = item.split(";")[0];
|
|
41
|
+
if (!firstPair)
|
|
42
|
+
continue;
|
|
43
|
+
const [name, ...rest] = firstPair.split("=");
|
|
44
|
+
if (!name || rest.length === 0)
|
|
45
|
+
continue;
|
|
46
|
+
this.cookieJar.set(name, rest.join("="));
|
|
47
|
+
}
|
|
48
|
+
this.cookie = [...this.cookieJar.entries()]
|
|
49
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
50
|
+
.join("; ");
|
|
51
|
+
this.client.defaults.headers.common["cookie"] = this.cookie;
|
|
52
|
+
}
|
|
53
|
+
extractFromCookie(cookieHeader, name) {
|
|
54
|
+
const match = cookieHeader.match(new RegExp(`${name}=([^;]+)`));
|
|
55
|
+
return match?.[1] ?? null;
|
|
56
|
+
}
|
|
57
|
+
async ensureAuthenticated() {
|
|
58
|
+
await this.authReady;
|
|
59
|
+
}
|
|
60
|
+
async getCsrfToken() {
|
|
61
|
+
const response = await axios.get("https://community-courses.memrise.com/v1.25/web/ensure_csrf", {
|
|
62
|
+
headers: {
|
|
63
|
+
accept: "*/*",
|
|
64
|
+
"sec-fetch-site": "same-origin",
|
|
65
|
+
cookie: this.cookie,
|
|
66
|
+
"sec-fetch-dest": "empty",
|
|
67
|
+
"accept-language": "en-US,en;q=0.9",
|
|
68
|
+
"sec-fetch-mode": "cors",
|
|
69
|
+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15",
|
|
70
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
71
|
+
referer: "https://community-courses.memrise.com/signin?next=%2Fdashboard",
|
|
72
|
+
priority: "u=3, i",
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const setCookie = response.headers?.["set-cookie"];
|
|
76
|
+
const setCookieValues = Array.isArray(setCookie)
|
|
77
|
+
? setCookie
|
|
78
|
+
: typeof setCookie === "string"
|
|
79
|
+
? [setCookie]
|
|
80
|
+
: [];
|
|
81
|
+
this.mergeSetCookieCookies(setCookieValues);
|
|
82
|
+
const tokenFromPayload = typeof response.data?.csrf_token === "string"
|
|
83
|
+
? response.data.csrf_token
|
|
84
|
+
: null;
|
|
85
|
+
const tokenFromCookie = this.extractFromCookie(this.cookie, "csrftoken");
|
|
86
|
+
return tokenFromPayload ?? tokenFromCookie;
|
|
87
|
+
}
|
|
88
|
+
async getAccessToken(username, password, clientId = DEFAULT_CLIENT_ID) {
|
|
89
|
+
const response = await axios.post("https://community-courses.memrise.com/v1.25/auth/access_token/", {
|
|
90
|
+
username,
|
|
91
|
+
password,
|
|
92
|
+
grant_type: "password",
|
|
93
|
+
client_id: clientId,
|
|
94
|
+
}, {
|
|
95
|
+
headers: {
|
|
96
|
+
referer: "https://community-courses.memrise.com/signin?next=%2Fdashboard",
|
|
97
|
+
cookie: this.cookie,
|
|
98
|
+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15",
|
|
99
|
+
origin: "https://community-courses.memrise.com",
|
|
100
|
+
"sec-fetch-dest": "empty",
|
|
101
|
+
"sec-fetch-site": "same-origin",
|
|
102
|
+
"accept-language": "en-US,en;q=0.9",
|
|
103
|
+
accept: "*/*",
|
|
104
|
+
"content-type": "application/json",
|
|
105
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
106
|
+
"sec-fetch-mode": "cors",
|
|
107
|
+
"x-client-type": "web",
|
|
108
|
+
"x-correlation-id": "df0e2b0d-c4de-4cb8-b976-7f807fbbc77c",
|
|
109
|
+
"x-timezone": "Asia/Phnom_Penh",
|
|
110
|
+
"x-device-type": "desktop",
|
|
111
|
+
"x-os": "mac_os",
|
|
112
|
+
...(this.csrfToken ? { "x-csrftoken": this.csrfToken } : {}),
|
|
113
|
+
...(this.accessToken
|
|
114
|
+
? { authorization: `Bearer ${this.accessToken}` }
|
|
115
|
+
: {}),
|
|
116
|
+
"x-os-version": "10.15.7",
|
|
117
|
+
"x-browser": "Safari",
|
|
118
|
+
"x-browser-version": "26.3",
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const setCookie = response.headers?.["set-cookie"];
|
|
122
|
+
const setCookieValues = Array.isArray(setCookie)
|
|
123
|
+
? setCookie
|
|
124
|
+
: typeof setCookie === "string"
|
|
125
|
+
? [setCookie]
|
|
126
|
+
: [];
|
|
127
|
+
this.mergeSetCookieCookies(setCookieValues);
|
|
128
|
+
return response.data;
|
|
129
|
+
}
|
|
130
|
+
async authenticateWeb(token) {
|
|
131
|
+
const response = await axios.get("https://community-courses.memrise.com/v1.25/auth/web/", {
|
|
132
|
+
params: {
|
|
133
|
+
invalidate_token_after: true,
|
|
134
|
+
token,
|
|
135
|
+
},
|
|
136
|
+
headers: {
|
|
137
|
+
accept: "*/*",
|
|
138
|
+
"sec-fetch-site": "same-origin",
|
|
139
|
+
"sec-fetch-mode": "cors",
|
|
140
|
+
"accept-language": "en-US,en;q=0.9",
|
|
141
|
+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15",
|
|
142
|
+
referer: "https://community-courses.memrise.com/signin?next=%2Fdashboard",
|
|
143
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
144
|
+
cookie: this.cookie,
|
|
145
|
+
"sec-fetch-dest": "empty",
|
|
146
|
+
"x-device-type": "desktop",
|
|
147
|
+
"x-correlation-id": crypto.randomUUID(),
|
|
148
|
+
"x-os": "mac_os",
|
|
149
|
+
"x-timezone": "Asia/Phnom_Penh",
|
|
150
|
+
priority: "u=3, i",
|
|
151
|
+
"x-browser": "Safari",
|
|
152
|
+
"x-browser-version": "26.3",
|
|
153
|
+
"x-client-type": "web",
|
|
154
|
+
"x-os-version": "10.15.7",
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
const setCookie = response.headers?.["set-cookie"];
|
|
158
|
+
const setCookieValues = Array.isArray(setCookie)
|
|
159
|
+
? setCookie
|
|
160
|
+
: typeof setCookie === "string"
|
|
161
|
+
? [setCookie]
|
|
162
|
+
: [];
|
|
163
|
+
this.mergeSetCookieCookies(setCookieValues);
|
|
164
|
+
// Update CSRF token from the updated cookies
|
|
165
|
+
const updatedCsrfToken = this.extractFromCookie(this.cookie, "csrftoken");
|
|
166
|
+
if (updatedCsrfToken) {
|
|
167
|
+
this.csrfToken = updatedCsrfToken;
|
|
168
|
+
this.client.defaults.headers.common["x-csrftoken"] = updatedCsrfToken;
|
|
169
|
+
}
|
|
170
|
+
return response.data;
|
|
171
|
+
}
|
|
172
|
+
async addThingToLevel(levelId, columns) {
|
|
173
|
+
await this.ensureAuthenticated();
|
|
174
|
+
const data = new URLSearchParams();
|
|
175
|
+
data.append("columns", JSON.stringify(columns));
|
|
176
|
+
data.append("level_id", levelId);
|
|
177
|
+
const response = await this.client.post("/ajax/level/thing/add/", data, {
|
|
178
|
+
headers: {
|
|
179
|
+
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
return response.data;
|
|
183
|
+
}
|
|
184
|
+
async addThingToCourse(courseId, columns, levelIndex = 0) {
|
|
185
|
+
await this.ensureAuthenticated();
|
|
186
|
+
const levels = await this.getCourseLevels(courseId);
|
|
187
|
+
if (levels.length === 0) {
|
|
188
|
+
throw new Error(`No levels found for course ${courseId}`);
|
|
189
|
+
}
|
|
190
|
+
if (levelIndex < 0 || levelIndex >= levels.length) {
|
|
191
|
+
throw new Error(`Level index ${levelIndex} out of range. Course has ${levels.length} levels.`);
|
|
192
|
+
}
|
|
193
|
+
const level = levels[levelIndex];
|
|
194
|
+
if (!level) {
|
|
195
|
+
throw new Error(`Level at index ${levelIndex} not found`);
|
|
196
|
+
}
|
|
197
|
+
const levelId = String(level.id);
|
|
198
|
+
return this.addThingToLevel(levelId, columns);
|
|
199
|
+
}
|
|
200
|
+
async searchPool(poolId, columns, excludeThingIds = [], originalOnly = false) {
|
|
201
|
+
await this.ensureAuthenticated();
|
|
202
|
+
const params = {
|
|
203
|
+
pool_id: poolId,
|
|
204
|
+
original_only: originalOnly,
|
|
205
|
+
columns: JSON.stringify(columns),
|
|
206
|
+
exclude_thing_ids: JSON.stringify(excludeThingIds),
|
|
207
|
+
_: Date.now(),
|
|
208
|
+
};
|
|
209
|
+
const response = await this.client.get("/ajax/pool/search/", {
|
|
210
|
+
params,
|
|
211
|
+
});
|
|
212
|
+
return response.data;
|
|
213
|
+
}
|
|
214
|
+
async getPool(poolId) {
|
|
215
|
+
await this.ensureAuthenticated();
|
|
216
|
+
const params = {
|
|
217
|
+
pool_id: poolId,
|
|
218
|
+
_: Date.now(),
|
|
219
|
+
};
|
|
220
|
+
const response = await this.client.get("/ajax/pool/get/", {
|
|
221
|
+
params,
|
|
222
|
+
});
|
|
223
|
+
return response.data;
|
|
224
|
+
}
|
|
225
|
+
async getMyCourses(limit = 9, offset = 0) {
|
|
226
|
+
await this.ensureAuthenticated();
|
|
227
|
+
const params = {
|
|
228
|
+
filter: "teaching",
|
|
229
|
+
limit,
|
|
230
|
+
offset,
|
|
231
|
+
};
|
|
232
|
+
const response = await this.client.get("/v1.25/dashboard/courses/", {
|
|
233
|
+
params,
|
|
234
|
+
});
|
|
235
|
+
return response.data;
|
|
236
|
+
}
|
|
237
|
+
async getCourseById(courseId) {
|
|
238
|
+
let offset = 0;
|
|
239
|
+
const limit = 9;
|
|
240
|
+
while (true) {
|
|
241
|
+
const response = await this.getMyCourses(limit, offset);
|
|
242
|
+
const course = response.courses.find((c) => String(c.id) === String(courseId));
|
|
243
|
+
if (course)
|
|
244
|
+
return course;
|
|
245
|
+
if (!response.has_more_pages)
|
|
246
|
+
return null;
|
|
247
|
+
offset += limit;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async getCourseBySlug(slug) {
|
|
251
|
+
let offset = 0;
|
|
252
|
+
const limit = 9;
|
|
253
|
+
while (true) {
|
|
254
|
+
const response = await this.getMyCourses(limit, offset);
|
|
255
|
+
const course = response.courses.find((c) => c.slug === slug);
|
|
256
|
+
if (course)
|
|
257
|
+
return course;
|
|
258
|
+
if (!response.has_more_pages)
|
|
259
|
+
return null;
|
|
260
|
+
offset += limit;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async getCourseLevels(courseId, slug) {
|
|
264
|
+
await this.ensureAuthenticated();
|
|
265
|
+
const response = await this.client.get(`/v1.25/courses/${courseId}/levels/`);
|
|
266
|
+
return response.data.levels;
|
|
267
|
+
}
|
|
268
|
+
async getLearnable(learnableId) {
|
|
269
|
+
await this.ensureAuthenticated();
|
|
270
|
+
try {
|
|
271
|
+
const response = await this.client.get(`/v1.25/learnables/${learnableId}/`);
|
|
272
|
+
return response.data.learnables[String(learnableId)] || null;
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
if (axios.isAxiosError(error) && error.response?.status === 404) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async getCourseItems(courseId) {
|
|
282
|
+
const levels = await this.getCourseLevels(courseId);
|
|
283
|
+
const learnableIds = levels.flatMap((level) => level.learnable_ids || []);
|
|
284
|
+
const uniqueIds = [...new Set(learnableIds)];
|
|
285
|
+
// Fetch in batches (concurrently) to avoid overloading but speed up
|
|
286
|
+
// Since we don't have a batch API, we do parallel requests with a limit
|
|
287
|
+
const items = [];
|
|
288
|
+
const concurrency = 5;
|
|
289
|
+
for (let i = 0; i < uniqueIds.length; i += concurrency) {
|
|
290
|
+
const batch = uniqueIds.slice(i, i + concurrency);
|
|
291
|
+
const promises = batch.map((id) => this.getLearnable(id));
|
|
292
|
+
const results = await Promise.all(promises);
|
|
293
|
+
results.forEach((item) => {
|
|
294
|
+
if (item)
|
|
295
|
+
items.push(item);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return items;
|
|
299
|
+
}
|
|
300
|
+
async getCourseColumns(courseId) {
|
|
301
|
+
const levels = await this.getCourseLevels(courseId);
|
|
302
|
+
if (levels.length === 0) {
|
|
303
|
+
throw new Error(`No levels found for course ${courseId}`);
|
|
304
|
+
}
|
|
305
|
+
const firstLevel = levels[0];
|
|
306
|
+
if (!firstLevel) {
|
|
307
|
+
throw new Error(`No levels found for course ${courseId}`);
|
|
308
|
+
}
|
|
309
|
+
const poolInfo = await this.getPool(firstLevel.pool_id);
|
|
310
|
+
return poolInfo.pool.columns;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAA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
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export interface MemriseColumn {
|
|
2
|
+
val: string;
|
|
3
|
+
kind: string;
|
|
4
|
+
accepted: string[];
|
|
5
|
+
alts: string[];
|
|
6
|
+
choices: string[];
|
|
7
|
+
distractors: {
|
|
8
|
+
typing: string[];
|
|
9
|
+
tapping: string[];
|
|
10
|
+
multiple_choice: string[];
|
|
11
|
+
audio: string[];
|
|
12
|
+
default: string[];
|
|
13
|
+
};
|
|
14
|
+
typing_corrects: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface MemriseThing {
|
|
17
|
+
id: number;
|
|
18
|
+
pool_id: number;
|
|
19
|
+
columns: Record<string, MemriseColumn>;
|
|
20
|
+
attributes: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface AddThingResponse {
|
|
23
|
+
success: boolean;
|
|
24
|
+
thing: MemriseThing;
|
|
25
|
+
rendered_thing: string;
|
|
26
|
+
}
|
|
27
|
+
export interface SearchPoolResultItem {
|
|
28
|
+
id: number;
|
|
29
|
+
columns: Record<string, {
|
|
30
|
+
val: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export interface SearchPoolResponse {
|
|
34
|
+
success: boolean;
|
|
35
|
+
result: SearchPoolResultItem[];
|
|
36
|
+
}
|
|
37
|
+
export interface PoolColumnConfig {
|
|
38
|
+
kind: string;
|
|
39
|
+
label: string;
|
|
40
|
+
typing_disabled: boolean;
|
|
41
|
+
typing_strict: boolean;
|
|
42
|
+
show_after_tests: boolean;
|
|
43
|
+
always_show: boolean;
|
|
44
|
+
keyboard: string;
|
|
45
|
+
tapping_disabled: boolean;
|
|
46
|
+
classes: string[];
|
|
47
|
+
}
|
|
48
|
+
export interface PoolAttributeConfig {
|
|
49
|
+
kind: string;
|
|
50
|
+
label: string;
|
|
51
|
+
show_at_tests: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface Pool {
|
|
54
|
+
id: number;
|
|
55
|
+
name: string;
|
|
56
|
+
columns: Record<string, PoolColumnConfig>;
|
|
57
|
+
attributes: Record<string, PoolAttributeConfig>;
|
|
58
|
+
can_curate: boolean;
|
|
59
|
+
can_moderate: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface GetPoolResponse {
|
|
62
|
+
pool: Pool;
|
|
63
|
+
}
|
|
64
|
+
export interface DashboardCategory {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
photo_url: string;
|
|
68
|
+
slug: string;
|
|
69
|
+
}
|
|
70
|
+
export interface DashboardCourseProgress {
|
|
71
|
+
id: number;
|
|
72
|
+
name: string;
|
|
73
|
+
size: number;
|
|
74
|
+
due_review: number;
|
|
75
|
+
learned: number;
|
|
76
|
+
ignored: number;
|
|
77
|
+
difficult: number;
|
|
78
|
+
completed_this_session: boolean;
|
|
79
|
+
percent_complete: number;
|
|
80
|
+
}
|
|
81
|
+
export interface DashboardCourse {
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
slug: string;
|
|
85
|
+
is_official: boolean;
|
|
86
|
+
photo_url: string;
|
|
87
|
+
progress: DashboardCourseProgress;
|
|
88
|
+
}
|
|
89
|
+
export interface GetDashboardCoursesResponse {
|
|
90
|
+
applied_filter: string;
|
|
91
|
+
applied_category: string | null;
|
|
92
|
+
categories: DashboardCategory[];
|
|
93
|
+
courses: DashboardCourse[];
|
|
94
|
+
has_more_pages: boolean;
|
|
95
|
+
}
|
|
96
|
+
export interface CourseLevel {
|
|
97
|
+
course_id: number;
|
|
98
|
+
id: number;
|
|
99
|
+
index: number;
|
|
100
|
+
kind: number;
|
|
101
|
+
learnable_ids?: number[];
|
|
102
|
+
pool_id: number;
|
|
103
|
+
title: string;
|
|
104
|
+
}
|
|
105
|
+
export interface Learnable {
|
|
106
|
+
id: number;
|
|
107
|
+
learning_element: string;
|
|
108
|
+
definition_element: string;
|
|
109
|
+
item_type: string;
|
|
110
|
+
difficulty: string;
|
|
111
|
+
}
|
|
112
|
+
export interface GetLearnableResponse {
|
|
113
|
+
learnables: Record<string, Learnable>;
|
|
114
|
+
}
|
|
115
|
+
export interface EnsureCsrfResponse {
|
|
116
|
+
csrf_token: string;
|
|
117
|
+
}
|
|
118
|
+
export interface AccessTokenPayload {
|
|
119
|
+
access_token: string;
|
|
120
|
+
token_type: string;
|
|
121
|
+
expires_in: number;
|
|
122
|
+
refresh_token?: string;
|
|
123
|
+
scope: string;
|
|
124
|
+
[key: string]: unknown;
|
|
125
|
+
}
|
|
126
|
+
export interface AccessTokenUser {
|
|
127
|
+
id: number;
|
|
128
|
+
username: string;
|
|
129
|
+
is_new: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface AccessTokenResponse {
|
|
132
|
+
access_token: AccessTokenPayload;
|
|
133
|
+
user: AccessTokenUser;
|
|
134
|
+
}
|
|
135
|
+
export interface AuthWebResponse {
|
|
136
|
+
success?: boolean;
|
|
137
|
+
[key: string]: unknown;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE;QACZ,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,eAAe,EAAE,MAAM,EAAE,CAAC;QAC1B,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,YAA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W,SAAS;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,kBAAkB;IAClC,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IACnC,YAAY,EAAE,kBAAkB,CAAC;IACjC,IAAI,EAAE,eAAe,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "memrise",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unofficial Memrise API client for Node.js and Bun",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepublishOnly": "bun run build"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/dvcrn/memrise.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"memrise",
|
|
22
|
+
"api",
|
|
23
|
+
"language-learning",
|
|
24
|
+
"flashcards"
|
|
25
|
+
],
|
|
26
|
+
"author": "David Mohl",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/dvcrn/memrise/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/dvcrn/memrise#readme",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "latest",
|
|
34
|
+
"typescript": "^5"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"axios": "^1.13.2"
|
|
38
|
+
}
|
|
39
|
+
}
|