chefu-academy-sdk 1.0.2 → 1.0.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.
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -20
- package/dist/index.mjs +24 -20
- package/package.json +5 -3
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ declare class CheFuAcademyClient {
|
|
|
16
16
|
* Centralized error handler
|
|
17
17
|
*/
|
|
18
18
|
private handleError;
|
|
19
|
+
private logRequest;
|
|
19
20
|
/**
|
|
20
21
|
* HTTP GET
|
|
21
22
|
*/
|
|
@@ -24,6 +25,8 @@ declare class CheFuAcademyClient {
|
|
|
24
25
|
* HTTP POST
|
|
25
26
|
*/
|
|
26
27
|
post<T = any>(path: string, data?: any): Promise<T>;
|
|
28
|
+
put<T = any>(path: string, data?: any): Promise<T>;
|
|
29
|
+
delete<T = any>(path: string): Promise<T>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
interface LoginResponse {
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare class CheFuAcademyClient {
|
|
|
16
16
|
* Centralized error handler
|
|
17
17
|
*/
|
|
18
18
|
private handleError;
|
|
19
|
+
private logRequest;
|
|
19
20
|
/**
|
|
20
21
|
* HTTP GET
|
|
21
22
|
*/
|
|
@@ -24,6 +25,8 @@ declare class CheFuAcademyClient {
|
|
|
24
25
|
* HTTP POST
|
|
25
26
|
*/
|
|
26
27
|
post<T = any>(path: string, data?: any): Promise<T>;
|
|
28
|
+
put<T = any>(path: string, data?: any): Promise<T>;
|
|
29
|
+
delete<T = any>(path: string): Promise<T>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
interface LoginResponse {
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var CheFuAcademyClient = class {
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
this.apiKey = config.apiKey;
|
|
57
|
-
this.baseURL = config.baseURL || "https://
|
|
57
|
+
this.baseURL = config.baseURL || "https://chefu-academy-sdk.onrender.com/api";
|
|
58
58
|
this.client = import_axios.default.create({
|
|
59
59
|
baseURL: this.baseURL,
|
|
60
60
|
timeout: config.timeout || 1e4,
|
|
@@ -127,6 +127,11 @@ var CheFuAcademyClient = class {
|
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
+
logRequest(method, url, data) {
|
|
131
|
+
if (process.env.CHEFU_SDK_DEBUG === "true") {
|
|
132
|
+
console.log(`[CheFu SDK] ${method.toUpperCase()} ${url}`, data || "");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
130
135
|
/**
|
|
131
136
|
* HTTP GET
|
|
132
137
|
*/
|
|
@@ -141,6 +146,14 @@ var CheFuAcademyClient = class {
|
|
|
141
146
|
const res = await this.client.post(path, data);
|
|
142
147
|
return res.data;
|
|
143
148
|
}
|
|
149
|
+
async put(path, data) {
|
|
150
|
+
const res = await this.client.put(path, data);
|
|
151
|
+
return res.data;
|
|
152
|
+
}
|
|
153
|
+
async delete(path) {
|
|
154
|
+
const res = await this.client.delete(path);
|
|
155
|
+
return res.data;
|
|
156
|
+
}
|
|
144
157
|
};
|
|
145
158
|
|
|
146
159
|
// src/auth.ts
|
|
@@ -257,7 +270,7 @@ var Courses = class {
|
|
|
257
270
|
try {
|
|
258
271
|
return await this.client.get("/courses");
|
|
259
272
|
} catch (error) {
|
|
260
|
-
this.handleCourseError(error, "fetch
|
|
273
|
+
this.handleCourseError(error, "fetch course");
|
|
261
274
|
}
|
|
262
275
|
}
|
|
263
276
|
/**
|
|
@@ -282,33 +295,24 @@ var Courses = class {
|
|
|
282
295
|
* Centralized course error handler
|
|
283
296
|
*/
|
|
284
297
|
handleCourseError(error, action) {
|
|
298
|
+
var _a;
|
|
285
299
|
if (error instanceof CheFuAcademyError) {
|
|
300
|
+
const message = ((_a = error.details) == null ? void 0 : _a.message) || error.message || `Failed to ${action}.`;
|
|
286
301
|
switch (error.statusCode) {
|
|
287
302
|
case 401:
|
|
288
|
-
throw new CheFuAcademyError(
|
|
289
|
-
"Unauthorized. Please check your API key.",
|
|
290
|
-
401
|
|
291
|
-
);
|
|
303
|
+
throw new CheFuAcademyError(`Unauthorized: ${message}`, 401, error.details);
|
|
292
304
|
case 404:
|
|
293
|
-
throw new CheFuAcademyError(
|
|
294
|
-
"Course not found.",
|
|
295
|
-
404
|
|
296
|
-
);
|
|
305
|
+
throw new CheFuAcademyError(`Course not found: ${message}`, 404, error.details);
|
|
297
306
|
case 429:
|
|
298
|
-
throw new CheFuAcademyError(
|
|
299
|
-
"Rate limit exceeded while trying to " + action + ".",
|
|
300
|
-
429
|
|
301
|
-
);
|
|
307
|
+
throw new CheFuAcademyError(`Rate limit exceeded while trying to ${action}: ${message}`, 429, error.details);
|
|
302
308
|
default:
|
|
303
|
-
throw new CheFuAcademyError(
|
|
304
|
-
`Failed to ${action}.`,
|
|
305
|
-
error.statusCode,
|
|
306
|
-
error.details
|
|
307
|
-
);
|
|
309
|
+
throw new CheFuAcademyError(`Failed to ${action}: ${message}`, error.statusCode, error.details);
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
throw new CheFuAcademyError(
|
|
311
|
-
`Unexpected error while trying to ${action}
|
|
313
|
+
`Unexpected error while trying to ${action}: ${(error == null ? void 0 : error.message) || "Unknown error"}`,
|
|
314
|
+
error == null ? void 0 : error.statusCode,
|
|
315
|
+
error == null ? void 0 : error.details
|
|
312
316
|
);
|
|
313
317
|
}
|
|
314
318
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ var CheFuAcademyClient = class {
|
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
this.apiKey = config.apiKey;
|
|
20
|
-
this.baseURL = config.baseURL || "https://
|
|
20
|
+
this.baseURL = config.baseURL || "https://chefu-academy-sdk.onrender.com/api";
|
|
21
21
|
this.client = axios.create({
|
|
22
22
|
baseURL: this.baseURL,
|
|
23
23
|
timeout: config.timeout || 1e4,
|
|
@@ -90,6 +90,11 @@ var CheFuAcademyClient = class {
|
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
logRequest(method, url, data) {
|
|
94
|
+
if (process.env.CHEFU_SDK_DEBUG === "true") {
|
|
95
|
+
console.log(`[CheFu SDK] ${method.toUpperCase()} ${url}`, data || "");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
93
98
|
/**
|
|
94
99
|
* HTTP GET
|
|
95
100
|
*/
|
|
@@ -104,6 +109,14 @@ var CheFuAcademyClient = class {
|
|
|
104
109
|
const res = await this.client.post(path, data);
|
|
105
110
|
return res.data;
|
|
106
111
|
}
|
|
112
|
+
async put(path, data) {
|
|
113
|
+
const res = await this.client.put(path, data);
|
|
114
|
+
return res.data;
|
|
115
|
+
}
|
|
116
|
+
async delete(path) {
|
|
117
|
+
const res = await this.client.delete(path);
|
|
118
|
+
return res.data;
|
|
119
|
+
}
|
|
107
120
|
};
|
|
108
121
|
|
|
109
122
|
// src/auth.ts
|
|
@@ -220,7 +233,7 @@ var Courses = class {
|
|
|
220
233
|
try {
|
|
221
234
|
return await this.client.get("/courses");
|
|
222
235
|
} catch (error) {
|
|
223
|
-
this.handleCourseError(error, "fetch
|
|
236
|
+
this.handleCourseError(error, "fetch course");
|
|
224
237
|
}
|
|
225
238
|
}
|
|
226
239
|
/**
|
|
@@ -245,33 +258,24 @@ var Courses = class {
|
|
|
245
258
|
* Centralized course error handler
|
|
246
259
|
*/
|
|
247
260
|
handleCourseError(error, action) {
|
|
261
|
+
var _a;
|
|
248
262
|
if (error instanceof CheFuAcademyError) {
|
|
263
|
+
const message = ((_a = error.details) == null ? void 0 : _a.message) || error.message || `Failed to ${action}.`;
|
|
249
264
|
switch (error.statusCode) {
|
|
250
265
|
case 401:
|
|
251
|
-
throw new CheFuAcademyError(
|
|
252
|
-
"Unauthorized. Please check your API key.",
|
|
253
|
-
401
|
|
254
|
-
);
|
|
266
|
+
throw new CheFuAcademyError(`Unauthorized: ${message}`, 401, error.details);
|
|
255
267
|
case 404:
|
|
256
|
-
throw new CheFuAcademyError(
|
|
257
|
-
"Course not found.",
|
|
258
|
-
404
|
|
259
|
-
);
|
|
268
|
+
throw new CheFuAcademyError(`Course not found: ${message}`, 404, error.details);
|
|
260
269
|
case 429:
|
|
261
|
-
throw new CheFuAcademyError(
|
|
262
|
-
"Rate limit exceeded while trying to " + action + ".",
|
|
263
|
-
429
|
|
264
|
-
);
|
|
270
|
+
throw new CheFuAcademyError(`Rate limit exceeded while trying to ${action}: ${message}`, 429, error.details);
|
|
265
271
|
default:
|
|
266
|
-
throw new CheFuAcademyError(
|
|
267
|
-
`Failed to ${action}.`,
|
|
268
|
-
error.statusCode,
|
|
269
|
-
error.details
|
|
270
|
-
);
|
|
272
|
+
throw new CheFuAcademyError(`Failed to ${action}: ${message}`, error.statusCode, error.details);
|
|
271
273
|
}
|
|
272
274
|
}
|
|
273
275
|
throw new CheFuAcademyError(
|
|
274
|
-
`Unexpected error while trying to ${action}
|
|
276
|
+
`Unexpected error while trying to ${action}: ${(error == null ? void 0 : error.message) || "Unknown error"}`,
|
|
277
|
+
error == null ? void 0 : error.statusCode,
|
|
278
|
+
error == null ? void 0 : error.details
|
|
275
279
|
);
|
|
276
280
|
}
|
|
277
281
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chefu-academy-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -21,10 +21,12 @@
|
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"description": "",
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@types/node": "^25.0.10",
|
|
24
25
|
"tsup": "^8.5.1",
|
|
25
26
|
"typescript": "^5.9.3"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"axios": "^1.13.2"
|
|
29
|
+
"axios": "^1.13.2",
|
|
30
|
+
"chefu-academy-sdk": "file:chefu-academy-sdk-1.0.3.tgz"
|
|
29
31
|
}
|
|
30
|
-
}
|
|
32
|
+
}
|