tetrons 2.3.28 → 2.3.29
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/app/api/ai-action/route.cjs +61 -0
- package/dist/app/api/ai-action/route.d.ts +9 -0
- package/dist/app/api/export/route.cjs +33 -0
- package/dist/app/api/export/route.d.ts +3 -0
- package/dist/app/api/register/route.cjs +120 -0
- package/dist/app/api/register/route.d.ts +10 -0
- package/dist/app/api/save/route.cjs +53 -0
- package/dist/app/api/save/route.d.ts +9 -0
- package/dist/app/api/transcribe/route.cjs +72 -0
- package/dist/app/api/transcribe/route.d.ts +10 -0
- package/dist/app/api/validate/route.cjs +143 -0
- package/dist/app/api/validate/route.d.ts +13 -0
- package/dist/index.cjs +17012 -0
- package/dist/index.d.ts +12 -0
- package/package.json +2 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/app/api/ai-action/route.ts
|
|
21
|
+
var route_exports = {};
|
|
22
|
+
__export(route_exports, {
|
|
23
|
+
POST: () => POST
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(route_exports);
|
|
26
|
+
var import_server = require("next/server");
|
|
27
|
+
async function POST(req) {
|
|
28
|
+
try {
|
|
29
|
+
const { content } = await req.json();
|
|
30
|
+
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
model: "gpt-4",
|
|
38
|
+
messages: [{ role: "user", content }],
|
|
39
|
+
temperature: 0.7
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
return import_server.NextResponse.json({ error: data.error.message }, { status: 500 });
|
|
45
|
+
}
|
|
46
|
+
return import_server.NextResponse.json({ response: data.choices[0].message.content });
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("AI generation error:", error);
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
return import_server.NextResponse.json({ error: error.message }, { status: 500 });
|
|
51
|
+
}
|
|
52
|
+
return import_server.NextResponse.json(
|
|
53
|
+
{ error: "Unknown error occurred." },
|
|
54
|
+
{ status: 500 }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
POST
|
|
61
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/app/api/export/route.ts
|
|
21
|
+
var route_exports = {};
|
|
22
|
+
__export(route_exports, {
|
|
23
|
+
GET: () => GET
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(route_exports);
|
|
26
|
+
function GET(req) {
|
|
27
|
+
console.log(req.method);
|
|
28
|
+
return new Response("Hello, world!", { status: 200 });
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
GET
|
|
33
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/app/api/register/route.ts
|
|
31
|
+
var route_exports = {};
|
|
32
|
+
__export(route_exports, {
|
|
33
|
+
POST: () => POST
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(route_exports);
|
|
36
|
+
var import_server = require("next/server");
|
|
37
|
+
|
|
38
|
+
// src/lib/db.js
|
|
39
|
+
var import_mongoose = __toESM(require("mongoose"));
|
|
40
|
+
var MONGO_URL = process.env.MONGO_URL;
|
|
41
|
+
var connectDB = async () => {
|
|
42
|
+
if (import_mongoose.default.connection.readyState >= 1) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await import_mongoose.default.connect(MONGO_URL);
|
|
47
|
+
console.log("Connected to MongoDB \u{1F44D}");
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("MongoDB connection failed \u274C", error);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/models/ApiKey.ts
|
|
55
|
+
var import_mongoose2 = __toESM(require("mongoose"));
|
|
56
|
+
var ApiKeySchema = new import_mongoose2.default.Schema({
|
|
57
|
+
email: { type: String, required: true },
|
|
58
|
+
organization: { type: String, required: true },
|
|
59
|
+
version: {
|
|
60
|
+
type: String,
|
|
61
|
+
enum: ["free", "pro", "premium", "platinum"],
|
|
62
|
+
required: true
|
|
63
|
+
},
|
|
64
|
+
apiKey: { type: String, required: true, unique: true },
|
|
65
|
+
createdAt: { type: Date, default: Date.now },
|
|
66
|
+
expiresAt: { type: Date }
|
|
67
|
+
});
|
|
68
|
+
var ApiKey = import_mongoose2.default.models.ApiKey || import_mongoose2.default.model("ApiKey", ApiKeySchema);
|
|
69
|
+
|
|
70
|
+
// src/utils/apiKeyUtils.ts
|
|
71
|
+
var import_crypto = __toESM(require("crypto"));
|
|
72
|
+
var FREE_API_KEY = process.env.TETRONS_FREE_KEY || "TETRONS_FREE_KEY";
|
|
73
|
+
var SECRET_KEY = process.env.API_KEY_SECRET || "default-secret-key";
|
|
74
|
+
function getFreeApiKey() {
|
|
75
|
+
return FREE_API_KEY;
|
|
76
|
+
}
|
|
77
|
+
var VERSION_PREFIXES = {
|
|
78
|
+
pro: "PRO",
|
|
79
|
+
premium: "PREMIUM",
|
|
80
|
+
platinum: "PLATINUM"
|
|
81
|
+
};
|
|
82
|
+
function generateUserApiKey(email, organization, version) {
|
|
83
|
+
const input = `${email.trim().toLowerCase()}:${organization.trim().toLowerCase()}`;
|
|
84
|
+
const hash = import_crypto.default.createHmac("sha256", SECRET_KEY).update(input).digest("hex").toUpperCase();
|
|
85
|
+
const prefix = VERSION_PREFIXES[version];
|
|
86
|
+
return `${prefix}${hash.slice(0, 48 - prefix.length)}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/app/api/register/route.ts
|
|
90
|
+
async function POST(req) {
|
|
91
|
+
const body = await req.json();
|
|
92
|
+
const { email, organization, version } = body;
|
|
93
|
+
if (!email || !organization || !version) {
|
|
94
|
+
return import_server.NextResponse.json({ error: "Missing fields" }, { status: 400 });
|
|
95
|
+
}
|
|
96
|
+
await connectDB();
|
|
97
|
+
const lowerEmail = email.trim().toLowerCase();
|
|
98
|
+
const lowerOrg = organization.trim().toLowerCase();
|
|
99
|
+
await ApiKey.deleteMany({ email: lowerEmail, version });
|
|
100
|
+
let apiKey;
|
|
101
|
+
let expiresAt = null;
|
|
102
|
+
if (version === "free") {
|
|
103
|
+
apiKey = getFreeApiKey();
|
|
104
|
+
expiresAt = new Date(Date.now() + 14 * 24 * 60 * 60 * 1e3);
|
|
105
|
+
} else {
|
|
106
|
+
apiKey = generateUserApiKey(lowerEmail, lowerOrg, version);
|
|
107
|
+
}
|
|
108
|
+
await ApiKey.create({
|
|
109
|
+
email: lowerEmail,
|
|
110
|
+
organization: lowerOrg,
|
|
111
|
+
version,
|
|
112
|
+
apiKey,
|
|
113
|
+
expiresAt
|
|
114
|
+
});
|
|
115
|
+
return import_server.NextResponse.json({ apiKey, expiresAt });
|
|
116
|
+
}
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
POST
|
|
120
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/app/api/save/route.ts
|
|
31
|
+
var route_exports = {};
|
|
32
|
+
__export(route_exports, {
|
|
33
|
+
POST: () => POST
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(route_exports);
|
|
36
|
+
var import_server = require("next/server");
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
39
|
+
async function POST(request) {
|
|
40
|
+
try {
|
|
41
|
+
const json = await request.json();
|
|
42
|
+
const publicDir = import_path.default.join(process.cwd(), "public");
|
|
43
|
+
const filePath = import_path.default.join(publicDir, "editor-content.json");
|
|
44
|
+
await import_promises.default.writeFile(filePath, JSON.stringify(json, null, 2), "utf-8");
|
|
45
|
+
return import_server.NextResponse.json({ message: "File saved successfully" });
|
|
46
|
+
} catch {
|
|
47
|
+
return import_server.NextResponse.json({ error: "Failed to save file" }, { status: 500 });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
POST
|
|
53
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/app/api/transcribe/route.ts
|
|
21
|
+
var route_exports = {};
|
|
22
|
+
__export(route_exports, {
|
|
23
|
+
POST: () => POST,
|
|
24
|
+
runtime: () => runtime
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(route_exports);
|
|
27
|
+
var import_server = require("next/server");
|
|
28
|
+
var runtime = "edge";
|
|
29
|
+
async function POST(req) {
|
|
30
|
+
try {
|
|
31
|
+
const formData = await req.formData();
|
|
32
|
+
const file = formData.get("file");
|
|
33
|
+
if (!file) {
|
|
34
|
+
return import_server.NextResponse.json({ error: "No file uploaded" }, { status: 400 });
|
|
35
|
+
}
|
|
36
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
37
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
38
|
+
const whisperFormData = new FormData();
|
|
39
|
+
whisperFormData.append(
|
|
40
|
+
"file",
|
|
41
|
+
new Blob([buffer], { type: file.type || "audio/webm" }),
|
|
42
|
+
"voice.webm"
|
|
43
|
+
);
|
|
44
|
+
whisperFormData.append("model", "whisper-1");
|
|
45
|
+
const whisperRes = await fetch(
|
|
46
|
+
"https://api.openai.com/v1/audio/transcriptions",
|
|
47
|
+
{
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY ?? ""}`
|
|
51
|
+
},
|
|
52
|
+
body: whisperFormData
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
const result = await whisperRes.json();
|
|
56
|
+
if (!whisperRes.ok) {
|
|
57
|
+
return import_server.NextResponse.json(
|
|
58
|
+
{ error: result?.error?.message || "Transcription failed" },
|
|
59
|
+
{ status: 500 }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return import_server.NextResponse.json({ transcript: result.text });
|
|
63
|
+
} catch (error) {
|
|
64
|
+
const message = error instanceof Error ? error.message : "Unknown server error";
|
|
65
|
+
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
POST,
|
|
71
|
+
runtime
|
|
72
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/app/api/validate/route.ts
|
|
31
|
+
var route_exports = {};
|
|
32
|
+
__export(route_exports, {
|
|
33
|
+
OPTIONS: () => OPTIONS,
|
|
34
|
+
POST: () => POST
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(route_exports);
|
|
37
|
+
var import_server = require("next/server");
|
|
38
|
+
|
|
39
|
+
// src/lib/db.js
|
|
40
|
+
var import_mongoose = __toESM(require("mongoose"));
|
|
41
|
+
var MONGO_URL = process.env.MONGO_URL;
|
|
42
|
+
var connectDB = async () => {
|
|
43
|
+
if (import_mongoose.default.connection.readyState >= 1) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await import_mongoose.default.connect(MONGO_URL);
|
|
48
|
+
console.log("Connected to MongoDB \u{1F44D}");
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error("MongoDB connection failed \u274C", error);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/models/ApiKey.ts
|
|
56
|
+
var import_mongoose2 = __toESM(require("mongoose"));
|
|
57
|
+
var ApiKeySchema = new import_mongoose2.default.Schema({
|
|
58
|
+
email: { type: String, required: true },
|
|
59
|
+
organization: { type: String, required: true },
|
|
60
|
+
version: {
|
|
61
|
+
type: String,
|
|
62
|
+
enum: ["free", "pro", "premium", "platinum"],
|
|
63
|
+
required: true
|
|
64
|
+
},
|
|
65
|
+
apiKey: { type: String, required: true, unique: true },
|
|
66
|
+
createdAt: { type: Date, default: Date.now },
|
|
67
|
+
expiresAt: { type: Date }
|
|
68
|
+
});
|
|
69
|
+
var ApiKey = import_mongoose2.default.models.ApiKey || import_mongoose2.default.model("ApiKey", ApiKeySchema);
|
|
70
|
+
|
|
71
|
+
// src/app/api/validate/route.ts
|
|
72
|
+
var corsHeaders = {
|
|
73
|
+
"Access-Control-Allow-Origin": "*",
|
|
74
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
75
|
+
"Access-Control-Allow-Headers": "Content-Type"
|
|
76
|
+
};
|
|
77
|
+
async function OPTIONS() {
|
|
78
|
+
return new Response(null, {
|
|
79
|
+
status: 204,
|
|
80
|
+
headers: corsHeaders
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async function POST(req) {
|
|
84
|
+
try {
|
|
85
|
+
const body = await req.json();
|
|
86
|
+
const apiKey = body.apiKey;
|
|
87
|
+
if (!apiKey) {
|
|
88
|
+
return import_server.NextResponse.json(
|
|
89
|
+
{ error: "API key required" },
|
|
90
|
+
{
|
|
91
|
+
status: 400,
|
|
92
|
+
headers: corsHeaders
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
await connectDB();
|
|
97
|
+
const keyEntry = await ApiKey.findOne({ apiKey });
|
|
98
|
+
if (!keyEntry) {
|
|
99
|
+
return import_server.NextResponse.json(
|
|
100
|
+
{ error: "Invalid API key" },
|
|
101
|
+
{
|
|
102
|
+
status: 401,
|
|
103
|
+
headers: corsHeaders
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (keyEntry.version === "free" && keyEntry.expiresAt && /* @__PURE__ */ new Date() > new Date(keyEntry.expiresAt)) {
|
|
108
|
+
return import_server.NextResponse.json(
|
|
109
|
+
{ error: "Free trial expired" },
|
|
110
|
+
{
|
|
111
|
+
status: 403,
|
|
112
|
+
headers: corsHeaders
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return import_server.NextResponse.json(
|
|
117
|
+
{
|
|
118
|
+
valid: true,
|
|
119
|
+
version: keyEntry.version,
|
|
120
|
+
email: keyEntry.email,
|
|
121
|
+
organization: keyEntry.organization
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
status: 200,
|
|
125
|
+
headers: corsHeaders
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error("Validation Error:", err);
|
|
130
|
+
return import_server.NextResponse.json(
|
|
131
|
+
{ error: "Server error" },
|
|
132
|
+
{
|
|
133
|
+
status: 500,
|
|
134
|
+
headers: corsHeaders
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
OPTIONS,
|
|
142
|
+
POST
|
|
143
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
declare function OPTIONS(): Promise<Response>;
|
|
4
|
+
declare function POST(req: NextRequest): Promise<NextResponse<{
|
|
5
|
+
error: string;
|
|
6
|
+
}> | NextResponse<{
|
|
7
|
+
valid: boolean;
|
|
8
|
+
version: any;
|
|
9
|
+
email: any;
|
|
10
|
+
organization: any;
|
|
11
|
+
}>>;
|
|
12
|
+
|
|
13
|
+
export { OPTIONS, POST };
|