@rimori/client 2.3.0-next.2 → 2.3.0-next.4

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.
@@ -11,6 +11,7 @@ export interface CreateExerciseParams {
11
11
  name: string;
12
12
  description: string;
13
13
  estimated_duration: number;
14
+ topics: string[];
14
15
  }
15
16
  export interface Exercise {
16
17
  id: string;
@@ -35,13 +36,14 @@ export declare class ExerciseController {
35
36
  */
36
37
  viewWeeklyExercises(): Promise<Exercise[]>;
37
38
  /**
38
- * Creates a new exercise via the backend API.
39
+ * Creates multiple exercises via the backend API.
40
+ * All requests are made in parallel but only one event is emitted.
39
41
  * @param token The token to use for authentication.
40
42
  * @param backendUrl The URL of the backend API.
41
- * @param params Exercise creation parameters.
42
- * @returns Created exercise object.
43
+ * @param exercises Exercise creation parameters.
44
+ * @returns Created exercise objects.
43
45
  */
44
- addExercise(token: string, backendUrl: string, params: CreateExerciseParams): Promise<Exercise>;
46
+ addExercise(token: string, backendUrl: string, exercises: CreateExerciseParams[]): Promise<Exercise[]>;
45
47
  /**
46
48
  * Deletes an exercise via the backend API.
47
49
  * @param token The token to use for authentication.
@@ -27,28 +27,32 @@ export class ExerciseController {
27
27
  });
28
28
  }
29
29
  /**
30
- * Creates a new exercise via the backend API.
30
+ * Creates multiple exercises via the backend API.
31
+ * All requests are made in parallel but only one event is emitted.
31
32
  * @param token The token to use for authentication.
32
33
  * @param backendUrl The URL of the backend API.
33
- * @param params Exercise creation parameters.
34
- * @returns Created exercise object.
34
+ * @param exercises Exercise creation parameters.
35
+ * @returns Created exercise objects.
35
36
  */
36
- addExercise(token, backendUrl, params) {
37
+ addExercise(token, backendUrl, exercises) {
37
38
  return __awaiter(this, void 0, void 0, function* () {
38
- const response = yield fetch(`${backendUrl}/exercises`, {
39
- method: 'POST',
40
- headers: {
41
- 'Content-Type': 'application/json',
42
- Authorization: `Bearer ${token}`,
43
- },
44
- body: JSON.stringify(params),
45
- });
46
- if (!response.ok) {
47
- const errorText = yield response.text();
48
- throw new Error(`Failed to create exercise: ${errorText}`);
49
- }
39
+ const responses = yield Promise.all(exercises.map((exercise) => __awaiter(this, void 0, void 0, function* () {
40
+ const response = yield fetch(`${backendUrl}/exercises`, {
41
+ method: 'POST',
42
+ headers: {
43
+ 'Content-Type': 'application/json',
44
+ Authorization: `Bearer ${token}`,
45
+ },
46
+ body: JSON.stringify(exercise),
47
+ });
48
+ if (!response.ok) {
49
+ const errorText = yield response.text();
50
+ throw new Error(`Failed to create exercise: ${errorText}`);
51
+ }
52
+ return yield response.json();
53
+ })));
50
54
  this.rimoriClient.event.emit('global.exercises.triggerChange');
51
- return yield response.json();
55
+ return responses;
52
56
  });
53
57
  }
54
58
  /**
@@ -253,11 +253,12 @@ export declare class RimoriClient {
253
253
  */
254
254
  view: () => Promise<import("../controller/ExerciseController").Exercise[]>;
255
255
  /**
256
- * Creates a new exercise via the backend API.
257
- * @param params Exercise creation parameters.
258
- * @returns Created exercise object.
256
+ * Creates a new exercise or multiple exercises via the backend API.
257
+ * When creating multiple exercises, all requests are made in parallel but only one event is emitted.
258
+ * @param params Exercise creation parameters (single or array).
259
+ * @returns Created exercise objects.
259
260
  */
260
- add: (params: CreateExerciseParams) => Promise<import("../controller/ExerciseController").Exercise>;
261
+ add: (params: CreateExerciseParams | CreateExerciseParams[]) => Promise<import("../controller/ExerciseController").Exercise[]>;
261
262
  /**
262
263
  * Deletes an exercise via the backend API.
263
264
  * @param id The exercise ID to delete.
@@ -250,14 +250,16 @@ export class RimoriClient {
250
250
  return this.exerciseController.viewWeeklyExercises();
251
251
  }),
252
252
  /**
253
- * Creates a new exercise via the backend API.
254
- * @param params Exercise creation parameters.
255
- * @returns Created exercise object.
253
+ * Creates a new exercise or multiple exercises via the backend API.
254
+ * When creating multiple exercises, all requests are made in parallel but only one event is emitted.
255
+ * @param params Exercise creation parameters (single or array).
256
+ * @returns Created exercise objects.
256
257
  */
257
258
  add: (params) => __awaiter(this, void 0, void 0, function* () {
258
259
  const token = yield this.pluginController.getToken();
259
260
  const backendUrl = this.pluginController.getBackendUrl();
260
- return this.exerciseController.addExercise(token, backendUrl, params);
261
+ const exercises = Array.isArray(params) ? params : [params];
262
+ return this.exerciseController.addExercise(token, backendUrl, exercises);
261
263
  }),
262
264
  /**
263
265
  * Deletes an exercise via the backend API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.3.0-next.2",
3
+ "version": "2.3.0-next.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -11,6 +11,7 @@ export interface CreateExerciseParams {
11
11
  name: string;
12
12
  description: string;
13
13
  estimated_duration: number;
14
+ topics: string[]; // Required: Array of topics in format "skillCategory.accomplishmentKeyword" for matching accomplishments
14
15
  }
15
16
 
16
17
  export interface Exercise {
@@ -51,29 +52,37 @@ export class ExerciseController {
51
52
  }
52
53
 
53
54
  /**
54
- * Creates a new exercise via the backend API.
55
+ * Creates multiple exercises via the backend API.
56
+ * All requests are made in parallel but only one event is emitted.
55
57
  * @param token The token to use for authentication.
56
58
  * @param backendUrl The URL of the backend API.
57
- * @param params Exercise creation parameters.
58
- * @returns Created exercise object.
59
+ * @param exercises Exercise creation parameters.
60
+ * @returns Created exercise objects.
59
61
  */
60
- public async addExercise(token: string, backendUrl: string, params: CreateExerciseParams): Promise<Exercise> {
61
- const response = await fetch(`${backendUrl}/exercises`, {
62
- method: 'POST',
63
- headers: {
64
- 'Content-Type': 'application/json',
65
- Authorization: `Bearer ${token}`,
66
- },
67
- body: JSON.stringify(params),
68
- });
62
+ public async addExercise(token: string, backendUrl: string, exercises: CreateExerciseParams[]): Promise<Exercise[]> {
63
+ const responses = await Promise.all(
64
+ exercises.map(async (exercise) => {
65
+ const response = await fetch(`${backendUrl}/exercises`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ Authorization: `Bearer ${token}`,
70
+ },
71
+ body: JSON.stringify(exercise),
72
+ });
73
+
74
+ if (!response.ok) {
75
+ const errorText = await response.text();
76
+ throw new Error(`Failed to create exercise: ${errorText}`);
77
+ }
78
+
79
+ return await response.json();
80
+ }),
81
+ );
69
82
 
70
- if (!response.ok) {
71
- const errorText = await response.text();
72
- throw new Error(`Failed to create exercise: ${errorText}`);
73
- }
74
83
  this.rimoriClient.event.emit('global.exercises.triggerChange');
75
84
 
76
- return await response.json();
85
+ return responses;
77
86
  }
78
87
 
79
88
  /**
@@ -475,14 +475,16 @@ export class RimoriClient {
475
475
  },
476
476
 
477
477
  /**
478
- * Creates a new exercise via the backend API.
479
- * @param params Exercise creation parameters.
480
- * @returns Created exercise object.
478
+ * Creates a new exercise or multiple exercises via the backend API.
479
+ * When creating multiple exercises, all requests are made in parallel but only one event is emitted.
480
+ * @param params Exercise creation parameters (single or array).
481
+ * @returns Created exercise objects.
481
482
  */
482
- add: async (params: CreateExerciseParams) => {
483
+ add: async (params: CreateExerciseParams | CreateExerciseParams[]) => {
483
484
  const token = await this.pluginController.getToken();
484
485
  const backendUrl = this.pluginController.getBackendUrl();
485
- return this.exerciseController.addExercise(token, backendUrl, params);
486
+ const exercises = Array.isArray(params) ? params : [params];
487
+ return this.exerciseController.addExercise(token, backendUrl, exercises);
486
488
  },
487
489
 
488
490
  /**