@retrivora-ai/rag-engine 2.3.7 → 2.3.8
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/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +227 -117
- package/dist/handlers/index.mjs +229 -119
- package/dist/{index-ejOWsaqb.d.ts → index-BQd6Bax0.d.ts} +1 -1
- package/dist/{index-xxQOFx-u.d.mts → index-C7aHK7_g.d.mts} +1 -1
- package/dist/index.js +114 -87
- package/dist/index.mjs +114 -87
- package/dist/server.d.mts +12 -32
- package/dist/server.d.ts +12 -32
- package/dist/server.js +232 -121
- package/dist/server.mjs +234 -123
- package/package.json +1 -1
- package/src/components/ChatWidget.tsx +0 -1
- package/src/components/ConfigProvider.tsx +2 -1
- package/src/config/serverConfig.ts +1 -2
- package/src/core/ConfigFetcher.ts +36 -3
- package/src/core/DatabaseStorage.ts +13 -13
- package/src/core/LicenseValidator.ts +5 -3
- package/src/core/LicenseVerifier.ts +85 -120
- package/src/core/Retrivora.ts +1 -1
- package/src/core/VectorPlugin.ts +1 -1
- package/src/handlers/index.ts +23 -13
- package/src/providers/vectordb/PineconeProvider.ts +69 -2
package/dist/handlers/index.mjs
CHANGED
|
@@ -302,7 +302,7 @@ var init_package = __esm({
|
|
|
302
302
|
"package.json"() {
|
|
303
303
|
package_default = {
|
|
304
304
|
name: "@retrivora-ai/rag-engine",
|
|
305
|
-
version: "2.3.
|
|
305
|
+
version: "2.3.8",
|
|
306
306
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
307
307
|
author: "Abhinav Alkuchi",
|
|
308
308
|
license: "UNLICENSED",
|
|
@@ -488,7 +488,12 @@ var init_ConfigFetcher = __esm({
|
|
|
488
488
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
489
489
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
490
490
|
CONTROL_PLANE_URL
|
|
491
|
-
].filter((url) =>
|
|
491
|
+
].filter((url) => {
|
|
492
|
+
if (!url) return false;
|
|
493
|
+
const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
|
|
494
|
+
if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
|
|
495
|
+
return true;
|
|
496
|
+
}).map((url) => url.replace(/\/$/, ""));
|
|
492
497
|
for (const baseUrl of controlPlaneUrls) {
|
|
493
498
|
try {
|
|
494
499
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
@@ -509,8 +514,7 @@ var init_ConfigFetcher = __esm({
|
|
|
509
514
|
isActive: data.isActive,
|
|
510
515
|
expiresAt: data.expiresAt,
|
|
511
516
|
vectorDb: {
|
|
512
|
-
// apiKey
|
|
513
|
-
// The SDK uses local PINECONE_API_KEY if available.
|
|
517
|
+
// Fetch apiKey from credentials API if available, else fallback to empty
|
|
514
518
|
apiKey: data.vectorDb.apiKey || "",
|
|
515
519
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
516
520
|
provider: data.vectorDb.provider || "pinecone",
|
|
@@ -542,6 +546,32 @@ var init_ConfigFetcher = __esm({
|
|
|
542
546
|
data.projectSettings || data.settings
|
|
543
547
|
)
|
|
544
548
|
};
|
|
549
|
+
if (licenseKey) {
|
|
550
|
+
try {
|
|
551
|
+
const credUrl = `${baseUrl}/api/v1/credentials`;
|
|
552
|
+
const credRes = await fetch(credUrl, {
|
|
553
|
+
method: "POST",
|
|
554
|
+
headers: {
|
|
555
|
+
"Content-Type": "application/json"
|
|
556
|
+
},
|
|
557
|
+
body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
|
|
558
|
+
});
|
|
559
|
+
if (credRes.ok) {
|
|
560
|
+
const credData = await credRes.json();
|
|
561
|
+
if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
|
|
562
|
+
if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
|
|
563
|
+
config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
|
|
564
|
+
}
|
|
565
|
+
if (credData.credentials.litellmApiKey) {
|
|
566
|
+
config.llm.apiKey = credData.credentials.litellmApiKey;
|
|
567
|
+
config.embedding.apiKey = credData.credentials.litellmApiKey;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
} catch (e) {
|
|
572
|
+
console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
545
575
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
546
576
|
return config;
|
|
547
577
|
}
|
|
@@ -581,6 +611,14 @@ var init_PineconeProvider = __esm({
|
|
|
581
611
|
const opts = config.options || {};
|
|
582
612
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
|
|
583
613
|
}
|
|
614
|
+
getControlPlaneUrl() {
|
|
615
|
+
const urls = [
|
|
616
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
617
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
618
|
+
"https://www.retrivora.com"
|
|
619
|
+
].filter((url) => Boolean(url));
|
|
620
|
+
return urls[0].replace(/\/$/, "");
|
|
621
|
+
}
|
|
584
622
|
static getValidator() {
|
|
585
623
|
return {
|
|
586
624
|
validate(config) {
|
|
@@ -644,6 +682,7 @@ var init_PineconeProvider = __esm({
|
|
|
644
682
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
645
683
|
if (!key) {
|
|
646
684
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
685
|
+
this.licenseKey = licenseKey;
|
|
647
686
|
const jwtProjectId = (() => {
|
|
648
687
|
if (!licenseKey) return void 0;
|
|
649
688
|
try {
|
|
@@ -657,6 +696,7 @@ var init_PineconeProvider = __esm({
|
|
|
657
696
|
return void 0;
|
|
658
697
|
})();
|
|
659
698
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
699
|
+
this.projectId = projectId;
|
|
660
700
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
661
701
|
if (remoteConfig) {
|
|
662
702
|
if (remoteConfig.apiKey) {
|
|
@@ -702,19 +742,59 @@ var init_PineconeProvider = __esm({
|
|
|
702
742
|
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
703
743
|
}
|
|
704
744
|
async upsert(doc, namespace) {
|
|
705
|
-
var _a3;
|
|
745
|
+
var _a3, _b;
|
|
746
|
+
if (!this.client) {
|
|
747
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
748
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
749
|
+
method: "POST",
|
|
750
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
751
|
+
body: JSON.stringify({
|
|
752
|
+
projectId: this.projectId,
|
|
753
|
+
indexName: this.indexName,
|
|
754
|
+
namespace: namespace || this.projectId,
|
|
755
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a3 = doc.metadata) != null ? _a3 : {}) }]
|
|
756
|
+
})
|
|
757
|
+
});
|
|
758
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
706
761
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
707
762
|
await targetIdx.upsert({
|
|
708
763
|
records: [{
|
|
709
764
|
id: String(doc.id),
|
|
710
765
|
values: doc.vector,
|
|
711
|
-
metadata: __spreadValues({ content: doc.content }, (
|
|
766
|
+
metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
|
|
712
767
|
}]
|
|
713
768
|
});
|
|
714
769
|
}
|
|
715
770
|
async batchUpsert(docs, namespace) {
|
|
716
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
717
771
|
const BATCH = 100;
|
|
772
|
+
if (!this.client) {
|
|
773
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
774
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
775
|
+
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
776
|
+
var _a3;
|
|
777
|
+
return {
|
|
778
|
+
id: String(d.id),
|
|
779
|
+
values: d.vector,
|
|
780
|
+
metadata: __spreadValues({ content: d.content }, (_a3 = d.metadata) != null ? _a3 : {})
|
|
781
|
+
};
|
|
782
|
+
});
|
|
783
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
784
|
+
method: "POST",
|
|
785
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
786
|
+
body: JSON.stringify({
|
|
787
|
+
projectId: this.projectId,
|
|
788
|
+
indexName: this.indexName,
|
|
789
|
+
namespace: namespace || this.projectId,
|
|
790
|
+
records
|
|
791
|
+
})
|
|
792
|
+
});
|
|
793
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
794
|
+
}
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
718
798
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
719
799
|
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
720
800
|
var _a3;
|
|
@@ -728,20 +808,46 @@ var init_PineconeProvider = __esm({
|
|
|
728
808
|
}
|
|
729
809
|
}
|
|
730
810
|
async query(vector, topK, namespace, filter) {
|
|
731
|
-
var _a3;
|
|
732
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
811
|
+
var _a3, _b;
|
|
733
812
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
813
|
+
if (!this.client) {
|
|
814
|
+
if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
|
|
815
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
816
|
+
method: "POST",
|
|
817
|
+
headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
|
|
818
|
+
body: JSON.stringify({
|
|
819
|
+
projectId: this.projectId,
|
|
820
|
+
indexName: this.indexName,
|
|
821
|
+
namespace: namespace || this.projectId,
|
|
822
|
+
vector,
|
|
823
|
+
topK,
|
|
824
|
+
filter: pineconeFilter
|
|
825
|
+
})
|
|
826
|
+
});
|
|
827
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
828
|
+
const data = await res.json();
|
|
829
|
+
return ((_a3 = data.matches) != null ? _a3 : []).map((m) => {
|
|
830
|
+
var _a4, _b2;
|
|
831
|
+
return {
|
|
832
|
+
id: m.id,
|
|
833
|
+
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
834
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
835
|
+
metadata: m.metadata
|
|
836
|
+
};
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
734
840
|
const result = await targetIdx.query(__spreadValues({
|
|
735
841
|
vector,
|
|
736
842
|
topK,
|
|
737
843
|
includeMetadata: true
|
|
738
844
|
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
739
|
-
return ((
|
|
740
|
-
var _a4,
|
|
845
|
+
return ((_b = result.matches) != null ? _b : []).map((m) => {
|
|
846
|
+
var _a4, _b2;
|
|
741
847
|
return {
|
|
742
848
|
id: m.id,
|
|
743
849
|
score: (_a4 = m.score) != null ? _a4 : 0,
|
|
744
|
-
content: ((
|
|
850
|
+
content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
|
|
745
851
|
metadata: m.metadata
|
|
746
852
|
};
|
|
747
853
|
});
|
|
@@ -1720,7 +1826,7 @@ __export(QdrantProvider_exports, {
|
|
|
1720
1826
|
QdrantProvider: () => QdrantProvider
|
|
1721
1827
|
});
|
|
1722
1828
|
import axios4 from "axios";
|
|
1723
|
-
import
|
|
1829
|
+
import crypto from "crypto";
|
|
1724
1830
|
var QdrantProvider;
|
|
1725
1831
|
var init_QdrantProvider = __esm({
|
|
1726
1832
|
"src/providers/vectordb/QdrantProvider.ts"() {
|
|
@@ -1952,7 +2058,7 @@ var init_QdrantProvider = __esm({
|
|
|
1952
2058
|
if (typeof id === "number") return id;
|
|
1953
2059
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1954
2060
|
if (uuidRegex.test(id)) return id.toLowerCase();
|
|
1955
|
-
const hash =
|
|
2061
|
+
const hash = crypto.createHash("md5").update(id).digest("hex");
|
|
1956
2062
|
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
|
|
1957
2063
|
}
|
|
1958
2064
|
async disconnect() {
|
|
@@ -2537,9 +2643,6 @@ import { NextResponse } from "next/server";
|
|
|
2537
2643
|
// src/core/ConfigResolver.ts
|
|
2538
2644
|
init_templateUtils();
|
|
2539
2645
|
|
|
2540
|
-
// src/core/LicenseVerifier.ts
|
|
2541
|
-
import * as crypto from "crypto";
|
|
2542
|
-
|
|
2543
2646
|
// src/exceptions/index.ts
|
|
2544
2647
|
var RetrivoraError = class extends Error {
|
|
2545
2648
|
constructor(message, code, details) {
|
|
@@ -2615,29 +2718,18 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2615
2718
|
}
|
|
2616
2719
|
|
|
2617
2720
|
// src/core/LicenseVerifier.ts
|
|
2618
|
-
var
|
|
2721
|
+
var _LicenseVerifier = class _LicenseVerifier {
|
|
2722
|
+
// Cache verified license for 5 minutes
|
|
2619
2723
|
/**
|
|
2620
|
-
*
|
|
2724
|
+
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2621
2725
|
*
|
|
2622
2726
|
* @param licenseKey - Base64url signed JWT license key.
|
|
2623
2727
|
* @param currentProjectId - Project namespace ID.
|
|
2624
|
-
* @param
|
|
2728
|
+
* @param provider - Optional provider for tier checks.
|
|
2625
2729
|
*/
|
|
2626
|
-
static
|
|
2730
|
+
static async verifyAsync(licenseKey, currentProjectId, provider) {
|
|
2627
2731
|
const isProduction = process.env.NODE_ENV === "production";
|
|
2628
2732
|
const now = Date.now();
|
|
2629
|
-
if (licenseKey) {
|
|
2630
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2631
|
-
const cached = this.cache.get(cacheKey);
|
|
2632
|
-
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2633
|
-
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2634
|
-
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2635
|
-
this.cache.delete(cacheKey);
|
|
2636
|
-
} else {
|
|
2637
|
-
return cached.payload;
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
2733
|
if (!licenseKey) {
|
|
2642
2734
|
if (isProduction) {
|
|
2643
2735
|
throw new ConfigurationException(
|
|
@@ -2654,52 +2746,61 @@ var LicenseVerifier = class {
|
|
|
2654
2746
|
tier: "hobby"
|
|
2655
2747
|
};
|
|
2656
2748
|
}
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
const
|
|
2661
|
-
if (
|
|
2662
|
-
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2665
|
-
const dataToVerify = `${headerB64}.${payloadB64}`;
|
|
2666
|
-
const publicKey = publicKeyOverride != null ? publicKeyOverride : this.PUBLIC_KEY;
|
|
2667
|
-
const signature = Buffer.from(signatureB64, "base64url");
|
|
2668
|
-
const data = Buffer.from(dataToVerify);
|
|
2669
|
-
const isValid = crypto.verify(
|
|
2670
|
-
"sha256",
|
|
2671
|
-
data,
|
|
2672
|
-
publicKey,
|
|
2673
|
-
signature
|
|
2674
|
-
);
|
|
2675
|
-
if (!isValid) {
|
|
2676
|
-
throw new Error("Signature verification failed.");
|
|
2749
|
+
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}`;
|
|
2750
|
+
const cached = this.cache.get(cacheKey);
|
|
2751
|
+
if (cached && now - cached.cachedAt < this.CACHE_TTL_MS) {
|
|
2752
|
+
const currentTimestampSec = Math.floor(now / 1e3);
|
|
2753
|
+
if (cached.payload.expiresAt && currentTimestampSec > cached.payload.expiresAt) {
|
|
2754
|
+
this.cache.delete(cacheKey);
|
|
2755
|
+
} else {
|
|
2756
|
+
return cached.payload;
|
|
2677
2757
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
if (
|
|
2682
|
-
|
|
2758
|
+
}
|
|
2759
|
+
try {
|
|
2760
|
+
let baseUrl = typeof process !== "undefined" && process.env.RETRIVORA_CONTROL_PLANE_URL ? process.env.RETRIVORA_CONTROL_PLANE_URL : "https://retrivora.com";
|
|
2761
|
+
if (typeof process !== "undefined" && process.env.TELEMETRY_URL) {
|
|
2762
|
+
baseUrl = process.env.TELEMETRY_URL.replace(/\/api\/telemetry\/?$/, "");
|
|
2683
2763
|
}
|
|
2684
|
-
const
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2764
|
+
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2765
|
+
const response = await fetch(endpoint, {
|
|
2766
|
+
method: "POST",
|
|
2767
|
+
headers: {
|
|
2768
|
+
"Content-Type": "application/json",
|
|
2769
|
+
"x-license-key": licenseKey
|
|
2770
|
+
},
|
|
2771
|
+
body: JSON.stringify({
|
|
2772
|
+
licenseKey,
|
|
2773
|
+
projectId: currentProjectId,
|
|
2774
|
+
provider
|
|
2775
|
+
})
|
|
2776
|
+
});
|
|
2777
|
+
if (!response.ok) {
|
|
2778
|
+
let errMessage = `HTTP ${response.status}`;
|
|
2779
|
+
try {
|
|
2780
|
+
const body = await response.json();
|
|
2781
|
+
if (body.message) errMessage = body.message;
|
|
2782
|
+
} catch (e) {
|
|
2783
|
+
}
|
|
2784
|
+
throw new Error(errMessage);
|
|
2689
2785
|
}
|
|
2690
|
-
|
|
2691
|
-
|
|
2786
|
+
const data = await response.json();
|
|
2787
|
+
if (!data.valid) {
|
|
2788
|
+
throw new Error(data.message || "License validation failed by server.");
|
|
2692
2789
|
}
|
|
2693
|
-
|
|
2694
|
-
if (
|
|
2695
|
-
|
|
2696
|
-
`License key has expired. Expiration: ${new Date(
|
|
2697
|
-
payload.expiresAt * 1e3
|
|
2698
|
-
).toDateString()}`
|
|
2699
|
-
);
|
|
2790
|
+
let expiresAtNum = Math.floor(Date.now() / 1e3) + 100 * 365 * 24 * 60 * 60;
|
|
2791
|
+
if (data.expiresAt) {
|
|
2792
|
+
expiresAtNum = Math.floor(new Date(data.expiresAt).getTime() / 1e3);
|
|
2700
2793
|
}
|
|
2794
|
+
const tier = _LicenseVerifier.extractTier(licenseKey);
|
|
2795
|
+
const payload = {
|
|
2796
|
+
projectId: currentProjectId,
|
|
2797
|
+
expiresAt: expiresAtNum,
|
|
2798
|
+
tier,
|
|
2799
|
+
licenseStatus: data.licenseStatus,
|
|
2800
|
+
minimumSupportedVersion: data.minimumSupportedVersion,
|
|
2801
|
+
forceUpgrade: data.forceUpgrade
|
|
2802
|
+
};
|
|
2701
2803
|
if (isProduction && provider) {
|
|
2702
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
2703
2804
|
const normalizedProvider = provider.toLowerCase();
|
|
2704
2805
|
if (tier === "hobby") {
|
|
2705
2806
|
const allowedHobby = ["postgresql", "pgvector", "supabase"];
|
|
@@ -2727,15 +2828,12 @@ var LicenseVerifier = class {
|
|
|
2727
2828
|
}
|
|
2728
2829
|
}
|
|
2729
2830
|
}
|
|
2730
|
-
|
|
2731
|
-
const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
|
|
2732
|
-
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2733
|
-
}
|
|
2831
|
+
this.cache.set(cacheKey, { payload, cachedAt: now });
|
|
2734
2832
|
return payload;
|
|
2735
2833
|
} catch (err) {
|
|
2736
2834
|
const message = err instanceof Error ? err.message : String(err);
|
|
2737
2835
|
throw new ConfigurationException(
|
|
2738
|
-
`[Retrivora SDK] License key validation failed: ${message}`
|
|
2836
|
+
`[Retrivora SDK] License key validation failed via API: ${message}`
|
|
2739
2837
|
);
|
|
2740
2838
|
}
|
|
2741
2839
|
}
|
|
@@ -2804,23 +2902,25 @@ var LicenseVerifier = class {
|
|
|
2804
2902
|
}
|
|
2805
2903
|
}
|
|
2806
2904
|
}
|
|
2905
|
+
static extractTier(licenseKey) {
|
|
2906
|
+
if (!licenseKey) return "hobby";
|
|
2907
|
+
try {
|
|
2908
|
+
const sanitizedKey = licenseKey.trim().replace(/^["']|["']$/g, "").trim();
|
|
2909
|
+
const rawToken = sanitizedKey.replace(/^rtv_/i, "").trim();
|
|
2910
|
+
const parts = rawToken.split(".");
|
|
2911
|
+
if (parts.length === 3) {
|
|
2912
|
+
const decodedPayload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
2913
|
+
if (decodedPayload.tier) return decodedPayload.tier;
|
|
2914
|
+
}
|
|
2915
|
+
} catch (e) {
|
|
2916
|
+
}
|
|
2917
|
+
return "hobby";
|
|
2918
|
+
}
|
|
2807
2919
|
};
|
|
2808
|
-
//
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
// Retrivora's Public Key used to verify the license key signature.
|
|
2813
|
-
// In production, this matches the private key held by Retrivora SaaS.
|
|
2814
|
-
// Rotate this key only when the signing private key is replaced.
|
|
2815
|
-
LicenseVerifier.PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
2816
|
-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyKvvOSYdCimG3b236ebV
|
|
2817
|
-
jpG88xQiU8dSiaMahtBJDf4w0AewRj7hMNgmeZ1wyTOj8kVgeGBOolp1Z0QmTr6O
|
|
2818
|
-
Tj4EDQ/zjsg12If7hSf3NiwLHCYmMLslyK0aaP6PQoTrYkBv3GNdkMecrIjKCijb
|
|
2819
|
-
6VvDLLF3X696melTVM0z/d2e50BW2AlRw/rf1EqYi10d0BcPo5zje0XETr/WGmqu
|
|
2820
|
-
sDiXtsP5MlwkL9X7RQY2uovRa+l/vOAqAfdmJ+OzXuk5P7mDUPb+gCtKnoDbb1tr
|
|
2821
|
-
6UAu733dkUnetAcMqyT3fNPBLO66DCc6m9rGCYYAaG7piMEDwG0/ZySZBFbgllJc
|
|
2822
|
-
6QIDAQAB
|
|
2823
|
-
-----END PUBLIC KEY-----`;
|
|
2920
|
+
// In-memory cache to save network overhead on hot paths.
|
|
2921
|
+
_LicenseVerifier.cache = /* @__PURE__ */ new Map();
|
|
2922
|
+
_LicenseVerifier.CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
2923
|
+
var LicenseVerifier = _LicenseVerifier;
|
|
2824
2924
|
|
|
2825
2925
|
// src/config/constants.ts
|
|
2826
2926
|
var VECTOR_DB_PROVIDERS = [
|
|
@@ -2977,8 +3077,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2977
3077
|
const isFreeTier2 = (() => {
|
|
2978
3078
|
if (!licenseKey) return true;
|
|
2979
3079
|
try {
|
|
2980
|
-
const
|
|
2981
|
-
const tier = (payload.tier || "").toLowerCase();
|
|
3080
|
+
const tier = LicenseVerifier.extractTier(licenseKey).toLowerCase();
|
|
2982
3081
|
return tier === "free_trial" || tier === "free_tier" || tier === "free" || tier === "hobby";
|
|
2983
3082
|
} catch (e) {
|
|
2984
3083
|
return true;
|
|
@@ -10053,7 +10152,7 @@ var VectorPlugin = class {
|
|
|
10053
10152
|
this.validationPromise = (async () => {
|
|
10054
10153
|
var _a3;
|
|
10055
10154
|
await ConfigValidator.validateAndThrow(resolvedConfig);
|
|
10056
|
-
LicenseVerifier.
|
|
10155
|
+
await LicenseVerifier.verifyAsync(
|
|
10057
10156
|
resolvedConfig.licenseKey,
|
|
10058
10157
|
resolvedConfig.projectId,
|
|
10059
10158
|
(_a3 = resolvedConfig.vectorDb) == null ? void 0 : _a3.provider
|
|
@@ -10326,7 +10425,7 @@ var DatabaseStorage = class {
|
|
|
10326
10425
|
* In non-production (development / test) environments this is a complete no-op —
|
|
10327
10426
|
* all History and Feedback features are freely accessible for local development.
|
|
10328
10427
|
*/
|
|
10329
|
-
checkPremiumSubscription() {
|
|
10428
|
+
async checkPremiumSubscription() {
|
|
10330
10429
|
if (process.env.NODE_ENV !== "production") {
|
|
10331
10430
|
return;
|
|
10332
10431
|
}
|
|
@@ -10336,7 +10435,7 @@ var DatabaseStorage = class {
|
|
|
10336
10435
|
);
|
|
10337
10436
|
}
|
|
10338
10437
|
try {
|
|
10339
|
-
const payload = LicenseVerifier.
|
|
10438
|
+
const payload = await LicenseVerifier.verifyAsync(this.config.licenseKey, this.config.projectId);
|
|
10340
10439
|
const tier = (payload.tier || "").toLowerCase();
|
|
10341
10440
|
if (tier !== "premium" && tier !== "enterprise" && tier !== "growth" && tier !== "pro" && tier !== "developer_pro" && tier !== "free_trial" && tier !== "free_tier" && tier !== "free" && tier !== "hobby") {
|
|
10342
10441
|
throw new Error(
|
|
@@ -10349,16 +10448,16 @@ var DatabaseStorage = class {
|
|
|
10349
10448
|
);
|
|
10350
10449
|
}
|
|
10351
10450
|
}
|
|
10352
|
-
checkHistoryEnabled() {
|
|
10451
|
+
async checkHistoryEnabled() {
|
|
10353
10452
|
var _a3, _b;
|
|
10354
|
-
this.checkPremiumSubscription();
|
|
10453
|
+
await this.checkPremiumSubscription();
|
|
10355
10454
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.history) == null ? void 0 : _b.enabled) === false) {
|
|
10356
10455
|
throw new Error("[Retrivora SDK] Chat History is disabled in RagConfig.");
|
|
10357
10456
|
}
|
|
10358
10457
|
}
|
|
10359
|
-
checkFeedbackEnabled() {
|
|
10458
|
+
async checkFeedbackEnabled() {
|
|
10360
10459
|
var _a3, _b;
|
|
10361
|
-
this.checkPremiumSubscription();
|
|
10460
|
+
await this.checkPremiumSubscription();
|
|
10362
10461
|
if (((_b = (_a3 = this.config.rag) == null ? void 0 : _a3.feedback) == null ? void 0 : _b.enabled) === false) {
|
|
10363
10462
|
throw new Error("[Retrivora SDK] User Feedback is disabled in RagConfig.");
|
|
10364
10463
|
}
|
|
@@ -10464,7 +10563,7 @@ var DatabaseStorage = class {
|
|
|
10464
10563
|
}
|
|
10465
10564
|
// ─── Message History Operations ──────────────────────────────────────────
|
|
10466
10565
|
async saveMessage(sessionId, message) {
|
|
10467
|
-
this.checkHistoryEnabled();
|
|
10566
|
+
await this.checkHistoryEnabled();
|
|
10468
10567
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10469
10568
|
const msgId = message.id || `msg_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10470
10569
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10527,7 +10626,7 @@ var DatabaseStorage = class {
|
|
|
10527
10626
|
}
|
|
10528
10627
|
}
|
|
10529
10628
|
async getHistory(sessionId, projectIds) {
|
|
10530
|
-
this.checkHistoryEnabled();
|
|
10629
|
+
await this.checkHistoryEnabled();
|
|
10531
10630
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10532
10631
|
return [];
|
|
10533
10632
|
}
|
|
@@ -10561,7 +10660,7 @@ var DatabaseStorage = class {
|
|
|
10561
10660
|
}
|
|
10562
10661
|
}
|
|
10563
10662
|
async clearHistory(sessionId, projectIds) {
|
|
10564
|
-
this.checkHistoryEnabled();
|
|
10663
|
+
await this.checkHistoryEnabled();
|
|
10565
10664
|
if (projectIds && projectIds.length > 0 && !this.sessionInScope(sessionId, projectIds)) {
|
|
10566
10665
|
return;
|
|
10567
10666
|
}
|
|
@@ -10597,7 +10696,7 @@ var DatabaseStorage = class {
|
|
|
10597
10696
|
);
|
|
10598
10697
|
}
|
|
10599
10698
|
async listSessions(projectIds) {
|
|
10600
|
-
this.checkHistoryEnabled();
|
|
10699
|
+
await this.checkHistoryEnabled();
|
|
10601
10700
|
let raw = [];
|
|
10602
10701
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10603
10702
|
const pool = await this.getPGPool();
|
|
@@ -10616,7 +10715,7 @@ var DatabaseStorage = class {
|
|
|
10616
10715
|
}
|
|
10617
10716
|
// ─── Feedback Operations ──────────────────────────────────────────────────
|
|
10618
10717
|
async saveFeedback(feedback) {
|
|
10619
|
-
this.checkFeedbackEnabled();
|
|
10718
|
+
await this.checkFeedbackEnabled();
|
|
10620
10719
|
const id = `fb_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
10621
10720
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10622
10721
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
@@ -10666,7 +10765,7 @@ var DatabaseStorage = class {
|
|
|
10666
10765
|
}
|
|
10667
10766
|
}
|
|
10668
10767
|
async getFeedback(messageId, projectIds) {
|
|
10669
|
-
this.checkFeedbackEnabled();
|
|
10768
|
+
await this.checkFeedbackEnabled();
|
|
10670
10769
|
let item = null;
|
|
10671
10770
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10672
10771
|
const pool = await this.getPGPool();
|
|
@@ -10702,7 +10801,7 @@ var DatabaseStorage = class {
|
|
|
10702
10801
|
return item;
|
|
10703
10802
|
}
|
|
10704
10803
|
async listFeedback(projectIds) {
|
|
10705
|
-
this.checkFeedbackEnabled();
|
|
10804
|
+
await this.checkFeedbackEnabled();
|
|
10706
10805
|
let raw = [];
|
|
10707
10806
|
if (this.provider === "postgresql" || this.provider === "pgvector") {
|
|
10708
10807
|
const pool = await this.getPGPool();
|
|
@@ -10852,12 +10951,23 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
|
|
|
10852
10951
|
var _a3;
|
|
10853
10952
|
return req.headers.get("x-license-key") || bodyLicenseKey || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.RAG_LICENSE_KEY || "";
|
|
10854
10953
|
}
|
|
10855
|
-
function enforceLicense(req, config, bodyLicenseKey) {
|
|
10954
|
+
async function enforceLicense(req, config, bodyLicenseKey) {
|
|
10856
10955
|
const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
|
|
10857
10956
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
10858
10957
|
const projectId = config.projectId || "";
|
|
10859
10958
|
try {
|
|
10860
|
-
|
|
10959
|
+
let payload;
|
|
10960
|
+
try {
|
|
10961
|
+
payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
10962
|
+
} catch (err) {
|
|
10963
|
+
return {
|
|
10964
|
+
ok: false,
|
|
10965
|
+
response: NextResponse.json(
|
|
10966
|
+
{ error: `License validation failed: ${err.message}` },
|
|
10967
|
+
{ status: 401 }
|
|
10968
|
+
)
|
|
10969
|
+
};
|
|
10970
|
+
}
|
|
10861
10971
|
return { ok: true, payload };
|
|
10862
10972
|
} catch (err) {
|
|
10863
10973
|
const message = err instanceof Error ? err.message : "Missing or invalid RETRIVORA_LICENSE_KEY. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or contact your administrator.";
|
|
@@ -11032,7 +11142,7 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11032
11142
|
try {
|
|
11033
11143
|
const body = await req.json();
|
|
11034
11144
|
const bodyObj = body != null ? body : {};
|
|
11035
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11145
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11036
11146
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11037
11147
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11038
11148
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11126,7 +11236,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11126
11236
|
});
|
|
11127
11237
|
}
|
|
11128
11238
|
const bodyObj = body != null ? body : {};
|
|
11129
|
-
const licenseCheck = enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11239
|
+
const licenseCheck = await enforceLicense(req, config, bodyObj == null ? void 0 : bodyObj.licenseKey);
|
|
11130
11240
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11131
11241
|
if (isFreeTier(licenseCheck.payload.tier)) {
|
|
11132
11242
|
const estimatedInputTokens = Math.ceil(
|
|
@@ -11291,7 +11401,7 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11291
11401
|
const config = plugin.getConfig();
|
|
11292
11402
|
try {
|
|
11293
11403
|
const body = await req.json();
|
|
11294
|
-
const licenseCheck = enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11404
|
+
const licenseCheck = await enforceLicense(req, config, body == null ? void 0 : body.licenseKey);
|
|
11295
11405
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11296
11406
|
const { documents, namespace } = body;
|
|
11297
11407
|
if (!Array.isArray(documents) || documents.length === 0) {
|
|
@@ -11367,7 +11477,7 @@ function createLicenseHandler(configOrPlugin, options) {
|
|
|
11367
11477
|
const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
|
|
11368
11478
|
const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
11369
11479
|
const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
|
|
11370
|
-
const payload = LicenseVerifier.
|
|
11480
|
+
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
11371
11481
|
return NextResponse.json({
|
|
11372
11482
|
valid: true,
|
|
11373
11483
|
licenseStatus: "ACTIVE",
|
|
@@ -11401,7 +11511,7 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11401
11511
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11402
11512
|
if (authResult) return authResult;
|
|
11403
11513
|
const config = plugin.getConfig();
|
|
11404
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11514
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11405
11515
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11406
11516
|
try {
|
|
11407
11517
|
const formData = await req.formData();
|
|
@@ -11545,7 +11655,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11545
11655
|
const authResult = await checkAuth(req, onAuthorize);
|
|
11546
11656
|
if (authResult) return authResult;
|
|
11547
11657
|
const config = plugin.getConfig();
|
|
11548
|
-
const licenseCheck = enforceLicense(req, config);
|
|
11658
|
+
const licenseCheck = await enforceLicense(req, config);
|
|
11549
11659
|
if (!licenseCheck.ok) return licenseCheck.response;
|
|
11550
11660
|
let effectiveLicensePayload = licenseCheck.payload;
|
|
11551
11661
|
try {
|
|
@@ -11558,7 +11668,7 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11558
11668
|
namespace = body.namespace;
|
|
11559
11669
|
bodyLicenseKey = body.licenseKey;
|
|
11560
11670
|
if (bodyLicenseKey) {
|
|
11561
|
-
const recheck = enforceLicense(req, config, bodyLicenseKey);
|
|
11671
|
+
const recheck = await enforceLicense(req, config, bodyLicenseKey);
|
|
11562
11672
|
if (!recheck.ok) return recheck.response;
|
|
11563
11673
|
effectiveLicensePayload = recheck.payload;
|
|
11564
11674
|
}
|
|
@@ -263,7 +263,7 @@ declare function createHealthHandler(configOrPlugin?: Partial<RagConfig> | Vecto
|
|
|
263
263
|
*
|
|
264
264
|
* Client flow: `LicenseValidator.validate()` calls this URL, receives
|
|
265
265
|
* authoritative DB-backed status (ACTIVE / TERMINATED / SUSPENDED / EXPIRED /
|
|
266
|
-
|
|
266
|
+
// REVOKED), and falls back to pure-local `LicenseVerifier.verifyAsync()` if the
|
|
267
267
|
* server is unreachable or returns an error.
|
|
268
268
|
*
|
|
269
269
|
* This handler does NOT enforce license — it is the verifier itself. It does,
|
|
@@ -263,7 +263,7 @@ declare function createHealthHandler(configOrPlugin?: Partial<RagConfig> | Vecto
|
|
|
263
263
|
*
|
|
264
264
|
* Client flow: `LicenseValidator.validate()` calls this URL, receives
|
|
265
265
|
* authoritative DB-backed status (ACTIVE / TERMINATED / SUSPENDED / EXPIRED /
|
|
266
|
-
|
|
266
|
+
// REVOKED), and falls back to pure-local `LicenseVerifier.verifyAsync()` if the
|
|
267
267
|
* server is unreachable or returns an error.
|
|
268
268
|
*
|
|
269
269
|
* This handler does NOT enforce license — it is the verifier itself. It does,
|