tetrons 2.3.73 → 2.3.74
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 +34 -9
- package/dist/app/api/export/route.cjs +29 -4
- package/dist/app/api/register/route.cjs +76 -14
- package/dist/app/api/register/route.mjs +32 -5
- package/dist/app/api/save/route.cjs +48 -13
- package/dist/app/api/transcribe/route.cjs +38 -12
- package/dist/app/api/validate/route.cjs +79 -14
- package/dist/app/api/validate/route.mjs +34 -5
- package/dist/index.cjs +433 -498
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +11 -69
- package/package.json +5 -9
- package/dist/chunk-37LFEKRW.cjs +0 -36
- package/dist/chunk-M2F2EU6B.mjs +0 -36
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
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");
|
|
3
27
|
async function POST(req) {
|
|
4
28
|
try {
|
|
5
29
|
const { content } = await req.json();
|
|
@@ -17,20 +41,21 @@ async function POST(req) {
|
|
|
17
41
|
});
|
|
18
42
|
const data = await response.json();
|
|
19
43
|
if (!response.ok) {
|
|
20
|
-
return
|
|
44
|
+
return import_server.NextResponse.json({ error: data.error.message }, { status: 500 });
|
|
21
45
|
}
|
|
22
|
-
return
|
|
46
|
+
return import_server.NextResponse.json({ response: data.choices[0].message.content });
|
|
23
47
|
} catch (error) {
|
|
24
48
|
console.error("AI generation error:", error);
|
|
25
49
|
if (error instanceof Error) {
|
|
26
|
-
return
|
|
50
|
+
return import_server.NextResponse.json({ error: error.message }, { status: 500 });
|
|
27
51
|
}
|
|
28
|
-
return
|
|
52
|
+
return import_server.NextResponse.json(
|
|
29
53
|
{ error: "Unknown error occurred." },
|
|
30
54
|
{ status: 500 }
|
|
31
55
|
);
|
|
32
56
|
}
|
|
33
57
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
POST
|
|
61
|
+
});
|
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
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);
|
|
2
26
|
function GET(req) {
|
|
3
27
|
console.log(req.method);
|
|
4
28
|
return new Response("Hello, world!", { status: 200 });
|
|
5
29
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
GET
|
|
33
|
+
});
|
|
@@ -1,13 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
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);
|
|
2
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");
|
|
3
37
|
|
|
4
|
-
|
|
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
|
+
};
|
|
5
53
|
|
|
6
|
-
// src/
|
|
7
|
-
var
|
|
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);
|
|
8
69
|
|
|
9
70
|
// src/utils/apiKeyUtils.ts
|
|
10
|
-
var
|
|
71
|
+
var import_crypto = __toESM(require("crypto"));
|
|
11
72
|
var FREE_API_KEY = process.env.TETRONS_FREE_KEY || "TETRONS_FREE_KEY";
|
|
12
73
|
var SECRET_KEY = process.env.API_KEY_SECRET || "default-secret-key";
|
|
13
74
|
function getFreeApiKey() {
|
|
@@ -20,7 +81,7 @@ var VERSION_PREFIXES = {
|
|
|
20
81
|
};
|
|
21
82
|
function generateUserApiKey(email, organization, version) {
|
|
22
83
|
const input = `${email.trim().toLowerCase()}:${organization.trim().toLowerCase()}`;
|
|
23
|
-
const hash =
|
|
84
|
+
const hash = import_crypto.default.createHmac("sha256", SECRET_KEY).update(input).digest("hex").toUpperCase();
|
|
24
85
|
const prefix = VERSION_PREFIXES[version];
|
|
25
86
|
return `${prefix}${hash.slice(0, 48 - prefix.length)}`;
|
|
26
87
|
}
|
|
@@ -30,12 +91,12 @@ async function POST(req) {
|
|
|
30
91
|
const body = await req.json();
|
|
31
92
|
const { email, organization, version } = body;
|
|
32
93
|
if (!email || !organization || !version) {
|
|
33
|
-
return
|
|
94
|
+
return import_server.NextResponse.json({ error: "Missing fields" }, { status: 400 });
|
|
34
95
|
}
|
|
35
|
-
await
|
|
96
|
+
await connectDB();
|
|
36
97
|
const lowerEmail = email.trim().toLowerCase();
|
|
37
98
|
const lowerOrg = organization.trim().toLowerCase();
|
|
38
|
-
await
|
|
99
|
+
await ApiKey.deleteMany({ email: lowerEmail, version });
|
|
39
100
|
let apiKey;
|
|
40
101
|
let expiresAt = null;
|
|
41
102
|
if (version === "free") {
|
|
@@ -44,15 +105,16 @@ async function POST(req) {
|
|
|
44
105
|
} else {
|
|
45
106
|
apiKey = generateUserApiKey(lowerEmail, lowerOrg, version);
|
|
46
107
|
}
|
|
47
|
-
await
|
|
108
|
+
await ApiKey.create({
|
|
48
109
|
email: lowerEmail,
|
|
49
110
|
organization: lowerOrg,
|
|
50
111
|
version,
|
|
51
112
|
apiKey,
|
|
52
113
|
expiresAt
|
|
53
114
|
});
|
|
54
|
-
return
|
|
115
|
+
return import_server.NextResponse.json({ apiKey, expiresAt });
|
|
55
116
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
POST
|
|
120
|
+
});
|
|
@@ -1,11 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiKey,
|
|
3
|
-
connectDB
|
|
4
|
-
} from "../../../chunk-M2F2EU6B.mjs";
|
|
5
|
-
|
|
6
1
|
// src/app/api/register/route.ts
|
|
7
2
|
import { NextResponse } from "next/server";
|
|
8
3
|
|
|
4
|
+
// src/lib/db.js
|
|
5
|
+
import mongoose from "mongoose";
|
|
6
|
+
var MONGO_URL = process.env.MONGO_URL;
|
|
7
|
+
var connectDB = async () => {
|
|
8
|
+
if (mongoose.connection.readyState >= 1) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
await mongoose.connect(MONGO_URL);
|
|
13
|
+
console.log("Connected to MongoDB \u{1F44D}");
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error("MongoDB connection failed \u274C", error);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/models/ApiKey.ts
|
|
21
|
+
import mongoose2 from "mongoose";
|
|
22
|
+
var ApiKeySchema = new mongoose2.Schema({
|
|
23
|
+
email: { type: String, required: true },
|
|
24
|
+
organization: { type: String, required: true },
|
|
25
|
+
version: {
|
|
26
|
+
type: String,
|
|
27
|
+
enum: ["free", "pro", "premium", "platinum"],
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
apiKey: { type: String, required: true, unique: true },
|
|
31
|
+
createdAt: { type: Date, default: Date.now },
|
|
32
|
+
expiresAt: { type: Date }
|
|
33
|
+
});
|
|
34
|
+
var ApiKey = mongoose2.models.ApiKey || mongoose2.model("ApiKey", ApiKeySchema);
|
|
35
|
+
|
|
9
36
|
// src/utils/apiKeyUtils.ts
|
|
10
37
|
import crypto from "crypto";
|
|
11
38
|
var FREE_API_KEY = process.env.TETRONS_FREE_KEY || "TETRONS_FREE_KEY";
|
|
@@ -1,18 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
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"));
|
|
5
39
|
async function POST(request) {
|
|
6
40
|
try {
|
|
7
41
|
const json = await request.json();
|
|
8
|
-
const publicDir =
|
|
9
|
-
const filePath =
|
|
10
|
-
await
|
|
11
|
-
return
|
|
12
|
-
} catch
|
|
13
|
-
return
|
|
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 });
|
|
14
48
|
}
|
|
15
49
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
POST
|
|
53
|
+
});
|
|
@@ -1,12 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
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");
|
|
3
28
|
var runtime = "edge";
|
|
4
29
|
async function POST(req) {
|
|
5
30
|
try {
|
|
6
31
|
const formData = await req.formData();
|
|
7
32
|
const file = formData.get("file");
|
|
8
33
|
if (!file) {
|
|
9
|
-
return
|
|
34
|
+
return import_server.NextResponse.json({ error: "No file uploaded" }, { status: 400 });
|
|
10
35
|
}
|
|
11
36
|
const arrayBuffer = await file.arrayBuffer();
|
|
12
37
|
const buffer = Buffer.from(arrayBuffer);
|
|
@@ -22,25 +47,26 @@ async function POST(req) {
|
|
|
22
47
|
{
|
|
23
48
|
method: "POST",
|
|
24
49
|
headers: {
|
|
25
|
-
Authorization: `Bearer ${
|
|
50
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY ?? ""}`
|
|
26
51
|
},
|
|
27
52
|
body: whisperFormData
|
|
28
53
|
}
|
|
29
54
|
);
|
|
30
55
|
const result = await whisperRes.json();
|
|
31
56
|
if (!whisperRes.ok) {
|
|
32
|
-
return
|
|
33
|
-
{ error:
|
|
57
|
+
return import_server.NextResponse.json(
|
|
58
|
+
{ error: result?.error?.message || "Transcription failed" },
|
|
34
59
|
{ status: 500 }
|
|
35
60
|
);
|
|
36
61
|
}
|
|
37
|
-
return
|
|
62
|
+
return import_server.NextResponse.json({ transcript: result.text });
|
|
38
63
|
} catch (error) {
|
|
39
64
|
const message = error instanceof Error ? error.message : "Unknown server error";
|
|
40
|
-
return
|
|
65
|
+
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
POST,
|
|
71
|
+
runtime
|
|
72
|
+
});
|
|
@@ -1,10 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
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);
|
|
2
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
|
+
};
|
|
3
54
|
|
|
4
|
-
|
|
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);
|
|
5
70
|
|
|
6
71
|
// src/app/api/validate/route.ts
|
|
7
|
-
var _server = require('next/server');
|
|
8
72
|
var corsHeaders = {
|
|
9
73
|
"Access-Control-Allow-Origin": "*",
|
|
10
74
|
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
@@ -21,7 +85,7 @@ async function POST(req) {
|
|
|
21
85
|
const body = await req.json();
|
|
22
86
|
const apiKey = body.apiKey;
|
|
23
87
|
if (!apiKey) {
|
|
24
|
-
return
|
|
88
|
+
return import_server.NextResponse.json(
|
|
25
89
|
{ error: "API key required" },
|
|
26
90
|
{
|
|
27
91
|
status: 400,
|
|
@@ -29,10 +93,10 @@ async function POST(req) {
|
|
|
29
93
|
}
|
|
30
94
|
);
|
|
31
95
|
}
|
|
32
|
-
await
|
|
33
|
-
const keyEntry = await
|
|
96
|
+
await connectDB();
|
|
97
|
+
const keyEntry = await ApiKey.findOne({ apiKey });
|
|
34
98
|
if (!keyEntry) {
|
|
35
|
-
return
|
|
99
|
+
return import_server.NextResponse.json(
|
|
36
100
|
{ error: "Invalid API key" },
|
|
37
101
|
{
|
|
38
102
|
status: 401,
|
|
@@ -41,7 +105,7 @@ async function POST(req) {
|
|
|
41
105
|
);
|
|
42
106
|
}
|
|
43
107
|
if (keyEntry.version === "free" && keyEntry.expiresAt && /* @__PURE__ */ new Date() > new Date(keyEntry.expiresAt)) {
|
|
44
|
-
return
|
|
108
|
+
return import_server.NextResponse.json(
|
|
45
109
|
{ error: "Free trial expired" },
|
|
46
110
|
{
|
|
47
111
|
status: 403,
|
|
@@ -49,7 +113,7 @@ async function POST(req) {
|
|
|
49
113
|
}
|
|
50
114
|
);
|
|
51
115
|
}
|
|
52
|
-
return
|
|
116
|
+
return import_server.NextResponse.json(
|
|
53
117
|
{
|
|
54
118
|
valid: true,
|
|
55
119
|
version: keyEntry.version,
|
|
@@ -63,7 +127,7 @@ async function POST(req) {
|
|
|
63
127
|
);
|
|
64
128
|
} catch (err) {
|
|
65
129
|
console.error("Validation Error:", err);
|
|
66
|
-
return
|
|
130
|
+
return import_server.NextResponse.json(
|
|
67
131
|
{ error: "Server error" },
|
|
68
132
|
{
|
|
69
133
|
status: 500,
|
|
@@ -72,7 +136,8 @@ async function POST(req) {
|
|
|
72
136
|
);
|
|
73
137
|
}
|
|
74
138
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
OPTIONS,
|
|
142
|
+
POST
|
|
143
|
+
});
|
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ApiKey,
|
|
3
|
-
connectDB
|
|
4
|
-
} from "../../../chunk-M2F2EU6B.mjs";
|
|
5
|
-
|
|
6
1
|
// src/app/api/validate/route.ts
|
|
7
2
|
import { NextResponse } from "next/server";
|
|
3
|
+
|
|
4
|
+
// src/lib/db.js
|
|
5
|
+
import mongoose from "mongoose";
|
|
6
|
+
var MONGO_URL = process.env.MONGO_URL;
|
|
7
|
+
var connectDB = async () => {
|
|
8
|
+
if (mongoose.connection.readyState >= 1) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
await mongoose.connect(MONGO_URL);
|
|
13
|
+
console.log("Connected to MongoDB \u{1F44D}");
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error("MongoDB connection failed \u274C", error);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/models/ApiKey.ts
|
|
21
|
+
import mongoose2 from "mongoose";
|
|
22
|
+
var ApiKeySchema = new mongoose2.Schema({
|
|
23
|
+
email: { type: String, required: true },
|
|
24
|
+
organization: { type: String, required: true },
|
|
25
|
+
version: {
|
|
26
|
+
type: String,
|
|
27
|
+
enum: ["free", "pro", "premium", "platinum"],
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
apiKey: { type: String, required: true, unique: true },
|
|
31
|
+
createdAt: { type: Date, default: Date.now },
|
|
32
|
+
expiresAt: { type: Date }
|
|
33
|
+
});
|
|
34
|
+
var ApiKey = mongoose2.models.ApiKey || mongoose2.model("ApiKey", ApiKeySchema);
|
|
35
|
+
|
|
36
|
+
// src/app/api/validate/route.ts
|
|
8
37
|
var corsHeaders = {
|
|
9
38
|
"Access-Control-Allow-Origin": "*",
|
|
10
39
|
"Access-Control-Allow-Methods": "POST, OPTIONS",
|