logggai
Version:
AI-powered CLI for transforming your development work into professional content
65 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LimitExceededError = void 0;
exports.isLimitExceededError = isLimitExceededError;
exports.formatLimitType = formatLimitType;
exports.formatLimit = formatLimit;
exports.parseLimitExceededResponse = parseLimitExceededResponse;
class LimitExceededError extends Error {
constructor(message, limitType, currentUsage, limit, planId, baseUrl = 'https://logggai.run') {
super(message);
this.type = 'LIMIT_EXCEEDED';
this.name = 'LimitExceededError';
this.limitType = limitType;
this.currentUsage = currentUsage;
this.limit = limit;
this.planId = planId;
this.upgradeUrl = `${baseUrl}/billing`;
}
}
exports.LimitExceededError = LimitExceededError;
function isLimitExceededError(error) {
return error instanceof LimitExceededError || error?.type === 'LIMIT_EXCEEDED';
}
function formatLimitType(limitType) {
switch (limitType) {
case 'posts':
return 'Posts created';
case 'ai':
return 'AI processing';
case 'apiCalls':
return 'API calls';
case 'integrations':
return 'Active integrations';
default:
return limitType;
}
}
function formatLimit(limit) {
if (limit === -1)
return 'Unlimited';
if (limit >= 1000)
return `${(limit / 1000).toFixed(0)}K`;
return limit.toString();
}
function parseLimitExceededResponse(errorData, baseUrl) {
const message = errorData.message || 'Limite atteinte';
let limitType = 'posts';
let currentUsage, limit;
// Extraire le type de limite du message
if (message.includes('ai'))
limitType = 'ai';
else if (message.includes('apiCalls'))
limitType = 'apiCalls';
else if (message.includes('integrations'))
limitType = 'integrations';
// Extraire usage et limite du message (ex: "Remaining: 0/10")
const remainingMatch = message.match(/Remaining: (\d+)\/(\d+)/);
if (remainingMatch) {
const remaining = parseInt(remainingMatch[1]);
limit = parseInt(remainingMatch[2]);
currentUsage = limit - remaining;
}
return new LimitExceededError(message, limitType, currentUsage, limit, errorData.planId, baseUrl);
}
//# sourceMappingURL=errors.js.map