@learnpack/learnpack 5.0.320 → 5.0.323

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.
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createError = exports.errorHandler = exports.notFoundHandler = exports.asyncHandler = exports.InternalServerError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.ValidationError = exports.OperationalError = void 0;
4
+ /**
5
+ * Base class for operational errors (expected errors)
6
+ */
7
+ class OperationalError extends Error {
8
+ constructor(message, details, statusCode = 500, code = "OPERATIONAL_ERROR") {
9
+ super(message);
10
+ this.name = this.constructor.name;
11
+ this.statusCode = statusCode;
12
+ this.code = code;
13
+ this.isOperational = true;
14
+ this.details = details;
15
+ // Maintains correct stack trace
16
+ Error.captureStackTrace(this, this.constructor);
17
+ }
18
+ }
19
+ exports.OperationalError = OperationalError;
20
+ /**
21
+ * Validation error (400)
22
+ */
23
+ class ValidationError extends OperationalError {
24
+ constructor(message, details) {
25
+ super(message, details, 400, "VALIDATION_ERROR");
26
+ }
27
+ }
28
+ exports.ValidationError = ValidationError;
29
+ /**
30
+ * Authentication error (401)
31
+ */
32
+ class UnauthorizedError extends OperationalError {
33
+ constructor(message, details) {
34
+ super(message, details, 401, "UNAUTHORIZED");
35
+ }
36
+ }
37
+ exports.UnauthorizedError = UnauthorizedError;
38
+ /**
39
+ * Authorization error (403)
40
+ */
41
+ class ForbiddenError extends OperationalError {
42
+ constructor(message, details) {
43
+ super(message, details, 403, "FORBIDDEN");
44
+ }
45
+ }
46
+ exports.ForbiddenError = ForbiddenError;
47
+ /**
48
+ * Resource not found error (404)
49
+ */
50
+ class NotFoundError extends OperationalError {
51
+ constructor(message, details) {
52
+ super(message, details, 404, "NOT_FOUND");
53
+ }
54
+ }
55
+ exports.NotFoundError = NotFoundError;
56
+ /**
57
+ * Conflict error (409)
58
+ */
59
+ class ConflictError extends OperationalError {
60
+ constructor(message, details) {
61
+ super(message, details, 409, "CONFLICT");
62
+ }
63
+ }
64
+ exports.ConflictError = ConflictError;
65
+ /**
66
+ * Internal server error (500)
67
+ */
68
+ class InternalServerError extends OperationalError {
69
+ constructor(message, details) {
70
+ super(message, details, 500, "INTERNAL_SERVER_ERROR");
71
+ }
72
+ }
73
+ exports.InternalServerError = InternalServerError;
74
+ /**
75
+ * Determines if an error is operational (expected) or programming (unexpected)
76
+ * @param error - The error to check
77
+ * @returns true if the error is operational, false otherwise
78
+ */
79
+ function isOperationalError(error) {
80
+ if (error instanceof OperationalError) {
81
+ return error.isOperational === true;
82
+ }
83
+ return false;
84
+ }
85
+ /**
86
+ * Formats the error for HTTP response
87
+ * @param error - The error to format
88
+ * @param isDevelopment - Whether in development mode
89
+ * @returns Object with the formatted response
90
+ */
91
+ function formatError(error, isDevelopment = false) {
92
+ const isOperational = isOperationalError(error);
93
+ const appError = error;
94
+ const baseResponse = {
95
+ status: "error",
96
+ message: appError.message || "An unexpected error occurred",
97
+ code: appError.code || "INTERNAL_ERROR",
98
+ };
99
+ // In development, include more details
100
+ if (isDevelopment) {
101
+ baseResponse.stack = appError.stack;
102
+ baseResponse.details = appError.details;
103
+ }
104
+ // If it's an operational error, include details if they exist
105
+ if (isOperational && appError.details) {
106
+ baseResponse.details = appError.details;
107
+ }
108
+ // If not operational, don't expose details in production
109
+ if (!isOperational && !isDevelopment) {
110
+ baseResponse.message = "An unexpected error occurred";
111
+ baseResponse.code = "INTERNAL_ERROR";
112
+ }
113
+ return baseResponse;
114
+ }
115
+ /**
116
+ * Determines the appropriate HTTP status code
117
+ * @param error - The error from which to get the status code
118
+ * @returns The HTTP status code
119
+ */
120
+ function getStatusCode(error) {
121
+ if (error.statusCode) {
122
+ return error.statusCode;
123
+ }
124
+ // Common Node.js errors
125
+ if (error.name === "ValidationError")
126
+ return 400;
127
+ if (error.name === "UnauthorizedError")
128
+ return 401;
129
+ if (error.name === "ForbiddenError")
130
+ return 403;
131
+ if (error.name === "NotFoundError")
132
+ return 404;
133
+ if (error.name === "ConflictError")
134
+ return 409;
135
+ // Default to server error
136
+ return 500;
137
+ }
138
+ /**
139
+ * Logs the error in a structured format
140
+ * @param error - The error to log
141
+ * @param req - Express Request object
142
+ * @returns void
143
+ */
144
+ function logError(error, req) {
145
+ const appError = error;
146
+ const isOperational = isOperationalError(error);
147
+ const logData = {
148
+ timestamp: new Date().toISOString(),
149
+ method: req.method,
150
+ url: req.originalUrl,
151
+ statusCode: getStatusCode(error),
152
+ error: {
153
+ name: error.name,
154
+ message: error.message,
155
+ code: appError.code,
156
+ isOperational,
157
+ stack: error.stack,
158
+ details: appError.details,
159
+ },
160
+ ip: req.ip || req.socket.remoteAddress,
161
+ userAgent: req.get("user-agent"),
162
+ };
163
+ // Different log based on error type
164
+ if (isOperational) {
165
+ console.error("⚠️ Operational Error:", JSON.stringify(logData, null, 2));
166
+ }
167
+ else {
168
+ console.error("❌ Unexpected Error:", JSON.stringify(logData, null, 2));
169
+ }
170
+ }
171
+ /**
172
+ * Wrapper for async handlers that automatically catches errors
173
+ *
174
+ * Usage:
175
+ * app.get('/route', asyncHandler(async (req, res) => {
176
+ * // your async code here
177
+ * }))
178
+ * @param fn - Async handler function to wrap
179
+ * @returns Express middleware that automatically catches errors
180
+ */
181
+ const asyncHandler = (fn) => {
182
+ return (req, res, next) => {
183
+ Promise.resolve(fn(req, res, next)).catch(next);
184
+ };
185
+ };
186
+ exports.asyncHandler = asyncHandler;
187
+ /**
188
+ * Middleware to handle not found routes (404)
189
+ * Must be placed after all routes but before the error handler
190
+ * @param req - Express Request object
191
+ * @param res - Express Response object
192
+ * @param next - Express next function
193
+ * @returns void
194
+ */
195
+ const notFoundHandler = (req, res, next) => {
196
+ const error = new NotFoundError(`Route ${req.method} ${req.originalUrl} not found`);
197
+ next(error);
198
+ };
199
+ exports.notFoundHandler = notFoundHandler;
200
+ /**
201
+ * Global error handling middleware
202
+ * Must be the last middleware in the chain
203
+ *
204
+ * Catches all unhandled synchronous and asynchronous errors
205
+ * @param error - The caught error
206
+ * @param req - Express Request object
207
+ * @param res - Express Response object
208
+ * @param next - Express next function
209
+ * @returns void
210
+ */
211
+ const errorHandler = (error, req, res, next) => {
212
+ // If response already sent, delegate to Express default handler
213
+ if (res.headersSent) {
214
+ return next(error);
215
+ }
216
+ // Determine if we're in development mode
217
+ const isDevelopment = process.env.NODE_ENV === "development" || process.env.DEBUG === "true";
218
+ // Log the error
219
+ logError(error, req);
220
+ // Get status code
221
+ const statusCode = getStatusCode(error);
222
+ // Format response
223
+ const response = formatError(error, isDevelopment);
224
+ // Send response
225
+ res.status(statusCode).json(response);
226
+ };
227
+ exports.errorHandler = errorHandler;
228
+ /**
229
+ * Helper to quickly create operational errors
230
+ * @param message - Error message
231
+ * @param details - Additional error details
232
+ * @param statusCode - HTTP status code
233
+ * @param code - Custom error code
234
+ * @returns New OperationalError instance
235
+ */
236
+ const createError = (message, details, statusCode, code) => {
237
+ return new OperationalError(message, details, statusCode || 500, code || "OPERATIONAL_ERROR");
238
+ };
239
+ exports.createError = createError;
@@ -95,6 +95,8 @@ type TInitialContentGeneratorInputs = {
95
95
  output_language: string;
96
96
  current_syllabus: string;
97
97
  lesson_description: string;
98
+ target_word_count: string;
99
+ topic_description?: string;
98
100
  };
99
101
  export declare const initialContentGenerator: (token: string, inputs: TInitialContentGeneratorInputs, webhookUrl?: string, endpointSlug?: string) => Promise<any>;
100
102
  type TAddInteractivityInputs = {
@@ -327,7 +327,7 @@ const addInteractivity = async (token, inputs, webhookUrl) => {
327
327
  exports.addInteractivity = addInteractivity;
328
328
  const generateCodeChallenge = async (token, inputs, webhookUrl) => {
329
329
  try {
330
- const response = await axios_1.default.post(`${api_1.RIGOBOT_HOST}/v1/prompting/completion/generate-code-challenge-files/`, {
330
+ const response = await axios_1.default.post(`${api_1.RIGOBOT_HOST}/v1/prompting/completion/create-structured-coding-filles/`, {
331
331
  inputs,
332
332
  include_purpose_objective: false,
333
333
  execute_async: !!webhookUrl,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@learnpack/learnpack",
3
3
  "description": "Seamlessly build, sell and/or take interactive & auto-graded tutorials, start learning now or build a new tutorial to your audience.",
4
- "version": "5.0.320",
4
+ "version": "5.0.323",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "contributors": [
7
7
  {