@retrivora-ai/rag-engine 2.6.2 → 2.6.4
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/ChromaDBProvider-NDA2IBOH.mjs +8 -0
- package/dist/MilvusProvider-H6GGL5FQ.mjs +8 -0
- package/dist/MongoDBProvider-KC3GF3FH.mjs +8 -0
- package/dist/MultiTablePostgresProvider-6LJBFZL2.mjs +9 -0
- package/dist/PineconeProvider-3PXQFHSO.mjs +10 -0
- package/dist/PostgreSQLProvider-VWFL4OIP.mjs +8 -0
- package/dist/QdrantProvider-UU7RGXBI.mjs +8 -0
- package/dist/RedisProvider-MIIPSAAE.mjs +8 -0
- package/dist/SimpleGraphProvider-HJIS4S7Y.mjs +70 -0
- package/dist/UniversalVectorProvider-NO3L255G.mjs +9 -0
- package/dist/WeaviateProvider-YRZDZFAC.mjs +8 -0
- package/dist/chunk-23PFNEBF.mjs +107 -0
- package/dist/chunk-3SQ4DODU.mjs +238 -0
- package/dist/chunk-6ZZOZFK6.mjs +334 -0
- package/dist/chunk-AHMMUZ4W.mjs +152 -0
- package/dist/chunk-ASBNNEVI.mjs +81 -0
- package/dist/chunk-BEPLYQBS.mjs +89 -0
- package/dist/chunk-BPIATXJ4.mjs +281 -0
- package/dist/chunk-FMQN2K2D.mjs +168 -0
- package/dist/chunk-G7MJRFCO.mjs +340 -0
- package/dist/chunk-IHWKVAUR.mjs +112 -0
- package/dist/chunk-IMP6FUCY.mjs +30 -0
- package/dist/chunk-MAXMVO7B.mjs +211 -0
- package/dist/chunk-MGJ6V2IT.mjs +203 -0
- package/dist/chunk-OMQM7AN6.mjs +219 -0
- package/dist/chunk-SG6XYLQE.mjs +53 -0
- package/dist/chunk-T7XSD76K.mjs +10851 -0
- package/dist/chunk-UT6SZZEC.mjs +69 -0
- package/dist/chunk-VW3U4MMX.mjs +157 -0
- package/dist/chunk-XYBKDJDW.mjs +696 -0
- package/dist/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +56 -23
- package/dist/handlers/index.mjs +24 -14027
- package/dist/{index-D7FuQRSb.d.mts → index-BBbt5A2y.d.mts} +3 -1
- package/dist/{index-CFl4KrKq.d.ts → index-BZ_rR6V8.d.ts} +3 -1
- package/dist/index.css +13 -0
- package/dist/index.js +22 -5
- package/dist/index.min.css +1 -1
- package/dist/index.mjs +56 -1462
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +56 -23
- package/dist/server.mjs +377 -14573
- package/package.json +1 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseVectorProvider
|
|
3
|
+
} from "./chunk-IMP6FUCY.mjs";
|
|
4
|
+
|
|
5
|
+
// src/providers/vectordb/PostgreSQLProvider.ts
|
|
6
|
+
import { Pool } from "pg";
|
|
7
|
+
var PostgreSQLProvider = class extends BaseVectorProvider {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
var _a;
|
|
10
|
+
super(config);
|
|
11
|
+
this.tableName = this.indexName.replace(/[^a-z0-9_]/gi, "_");
|
|
12
|
+
const opts = config.options;
|
|
13
|
+
if (!opts.connectionString) throw new Error("[PostgreSQLProvider] options.connectionString is required");
|
|
14
|
+
this.connectionString = opts.connectionString;
|
|
15
|
+
this.dimensions = (_a = opts.dimensions) != null ? _a : 1536;
|
|
16
|
+
}
|
|
17
|
+
static getValidator() {
|
|
18
|
+
return {
|
|
19
|
+
validate(config) {
|
|
20
|
+
const errors = [];
|
|
21
|
+
const opts = config.options || {};
|
|
22
|
+
if (!opts.connectionString) {
|
|
23
|
+
errors.push({
|
|
24
|
+
field: "vectorDb.options.connectionString",
|
|
25
|
+
message: "PostgreSQL connection string is required",
|
|
26
|
+
suggestion: "Set PGVECTOR_CONNECTION_STRING environment variable",
|
|
27
|
+
severity: "error"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (opts.tables && typeof opts.tables !== "string" && !Array.isArray(opts.tables)) {
|
|
31
|
+
errors.push({
|
|
32
|
+
field: "vectorDb.options.tables",
|
|
33
|
+
message: "PostgreSQL tables must be a string or a string array",
|
|
34
|
+
severity: "error"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return errors;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
static getHealthChecker() {
|
|
42
|
+
return {
|
|
43
|
+
async check(config) {
|
|
44
|
+
const opts = config.options || {};
|
|
45
|
+
const timestamp = Date.now();
|
|
46
|
+
try {
|
|
47
|
+
const { Client } = await import("pg");
|
|
48
|
+
const client = new Client({ connectionString: opts.connectionString });
|
|
49
|
+
await client.connect();
|
|
50
|
+
const result = await client.query(`
|
|
51
|
+
SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'vector');
|
|
52
|
+
`);
|
|
53
|
+
const hasVector = result.rows[0].exists;
|
|
54
|
+
await client.end();
|
|
55
|
+
return {
|
|
56
|
+
healthy: true,
|
|
57
|
+
provider: "postgresql",
|
|
58
|
+
capabilities: { pgvectorInstalled: hasVector },
|
|
59
|
+
timestamp
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
healthy: false,
|
|
64
|
+
provider: "postgresql",
|
|
65
|
+
error: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
66
|
+
timestamp
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async initialize() {
|
|
73
|
+
this.pool = new Pool({ connectionString: this.connectionString });
|
|
74
|
+
const client = await this.pool.connect();
|
|
75
|
+
try {
|
|
76
|
+
await client.query("CREATE EXTENSION IF NOT EXISTS vector");
|
|
77
|
+
await client.query(`
|
|
78
|
+
CREATE TABLE IF NOT EXISTS ${this.tableName} (
|
|
79
|
+
id TEXT PRIMARY KEY,
|
|
80
|
+
namespace TEXT NOT NULL DEFAULT '',
|
|
81
|
+
content TEXT NOT NULL,
|
|
82
|
+
metadata JSONB,
|
|
83
|
+
embedding VECTOR(${this.dimensions})
|
|
84
|
+
)
|
|
85
|
+
`);
|
|
86
|
+
await client.query(`
|
|
87
|
+
CREATE INDEX IF NOT EXISTS ${this.tableName}_embedding_idx
|
|
88
|
+
ON ${this.tableName}
|
|
89
|
+
USING hnsw (embedding vector_cosine_ops)
|
|
90
|
+
`);
|
|
91
|
+
} finally {
|
|
92
|
+
client.release();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async upsert(doc, namespace = "") {
|
|
96
|
+
var _a;
|
|
97
|
+
const vectorLiteral = `[${doc.vector.join(",")}]`;
|
|
98
|
+
await this.pool.query(
|
|
99
|
+
`INSERT INTO ${this.tableName} (id, namespace, content, metadata, embedding)
|
|
100
|
+
VALUES ($1, $2, $3, $4, $5::vector)
|
|
101
|
+
ON CONFLICT (id) DO UPDATE
|
|
102
|
+
SET namespace = EXCLUDED.namespace,
|
|
103
|
+
content = EXCLUDED.content,
|
|
104
|
+
metadata = EXCLUDED.metadata,
|
|
105
|
+
embedding = EXCLUDED.embedding`,
|
|
106
|
+
[doc.id, namespace, doc.content, JSON.stringify((_a = doc.metadata) != null ? _a : {}), vectorLiteral]
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
async batchUpsert(docs, namespace = "") {
|
|
110
|
+
if (docs.length === 0) return;
|
|
111
|
+
const client = await this.pool.connect();
|
|
112
|
+
try {
|
|
113
|
+
await client.query("BEGIN");
|
|
114
|
+
const BATCH_SIZE = 50;
|
|
115
|
+
for (let i = 0; i < docs.length; i += BATCH_SIZE) {
|
|
116
|
+
const batch = docs.slice(i, i + BATCH_SIZE);
|
|
117
|
+
const values = [];
|
|
118
|
+
const valuePlaceholders = batch.map((doc, idx) => {
|
|
119
|
+
var _a;
|
|
120
|
+
const offset = idx * 5;
|
|
121
|
+
values.push(doc.id, namespace, doc.content, JSON.stringify((_a = doc.metadata) != null ? _a : {}), `[${doc.vector.join(",")}]`);
|
|
122
|
+
return `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}::vector)`;
|
|
123
|
+
}).join(", ");
|
|
124
|
+
const query = `
|
|
125
|
+
INSERT INTO ${this.tableName} (id, namespace, content, metadata, embedding)
|
|
126
|
+
VALUES ${valuePlaceholders}
|
|
127
|
+
ON CONFLICT (id) DO UPDATE
|
|
128
|
+
SET namespace = EXCLUDED.namespace,
|
|
129
|
+
content = EXCLUDED.content,
|
|
130
|
+
metadata = EXCLUDED.metadata,
|
|
131
|
+
embedding = EXCLUDED.embedding
|
|
132
|
+
`;
|
|
133
|
+
await client.query(query, values);
|
|
134
|
+
}
|
|
135
|
+
await client.query("COMMIT");
|
|
136
|
+
} catch (error) {
|
|
137
|
+
await client.query("ROLLBACK");
|
|
138
|
+
throw error;
|
|
139
|
+
} finally {
|
|
140
|
+
client.release();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async query(vector, topK, namespace, filter) {
|
|
144
|
+
const vectorLiteral = `[${vector.join(",")}]`;
|
|
145
|
+
let whereClause = namespace ? `WHERE namespace = $3` : "";
|
|
146
|
+
const params = [vectorLiteral, topK];
|
|
147
|
+
if (namespace) params.push(namespace);
|
|
148
|
+
const publicFilter = this.sanitizeFilter(filter);
|
|
149
|
+
if (Object.keys(publicFilter).length > 0) {
|
|
150
|
+
const filterConditions = Object.entries(publicFilter).map(([key, val]) => {
|
|
151
|
+
const paramIdx = params.length + 1;
|
|
152
|
+
params.push(String(val));
|
|
153
|
+
return `metadata->>'${key.replace(/[^a-zA-Z0-9_.-]/g, "")}' = $${paramIdx}`;
|
|
154
|
+
}).join(" AND ");
|
|
155
|
+
whereClause = whereClause ? `${whereClause} AND ${filterConditions}` : `WHERE ${filterConditions}`;
|
|
156
|
+
}
|
|
157
|
+
const client = await this.pool.connect();
|
|
158
|
+
try {
|
|
159
|
+
const rawEfSearch = Number(this.config.options.efSearch) || Math.max(topK * 10, 40);
|
|
160
|
+
const efSearch = Math.max(1, Math.min(1e3, Math.floor(Number.isFinite(rawEfSearch) ? rawEfSearch : 40)));
|
|
161
|
+
await client.query(`SET LOCAL hnsw.ef_search = ${efSearch}`);
|
|
162
|
+
const result = await client.query(
|
|
163
|
+
`SELECT id, content, metadata, 1 - (embedding <=> $1::vector) AS score
|
|
164
|
+
FROM ${this.tableName}
|
|
165
|
+
${whereClause}
|
|
166
|
+
ORDER BY embedding <=> $1::vector
|
|
167
|
+
LIMIT $2`,
|
|
168
|
+
params
|
|
169
|
+
);
|
|
170
|
+
return result.rows.map((row) => ({
|
|
171
|
+
id: String(row["id"]),
|
|
172
|
+
score: parseFloat(String(row["score"])),
|
|
173
|
+
content: String(row["content"]),
|
|
174
|
+
metadata: row["metadata"]
|
|
175
|
+
}));
|
|
176
|
+
} finally {
|
|
177
|
+
client.release();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async delete(id, namespace) {
|
|
181
|
+
const where = namespace ? "WHERE id = $1 AND namespace = $2" : "WHERE id = $1";
|
|
182
|
+
const params = namespace ? [id, namespace] : [id];
|
|
183
|
+
await this.pool.query(`DELETE FROM ${this.tableName} ${where}`, params);
|
|
184
|
+
}
|
|
185
|
+
async deleteNamespace(namespace) {
|
|
186
|
+
await this.pool.query(`DELETE FROM ${this.tableName} WHERE namespace = $1`, [namespace]);
|
|
187
|
+
}
|
|
188
|
+
async ping() {
|
|
189
|
+
try {
|
|
190
|
+
await this.pool.query("SELECT 1");
|
|
191
|
+
return true;
|
|
192
|
+
} catch (e) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async disconnect() {
|
|
197
|
+
await this.pool.end();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export {
|
|
202
|
+
PostgreSQLProvider
|
|
203
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LicenseValidationError,
|
|
3
|
+
LicenseVerifier,
|
|
4
|
+
SDKVersionUnsupportedError
|
|
5
|
+
} from "./chunk-XYBKDJDW.mjs";
|
|
6
|
+
import {
|
|
7
|
+
SDK_VERSION
|
|
8
|
+
} from "./chunk-FMQN2K2D.mjs";
|
|
9
|
+
import {
|
|
10
|
+
__spreadValues
|
|
11
|
+
} from "./chunk-UT6SZZEC.mjs";
|
|
12
|
+
|
|
13
|
+
// src/core/LicenseValidator.ts
|
|
14
|
+
function canUseLocalValidationFallback(baseUrl, status) {
|
|
15
|
+
const explicitFallback = typeof process !== "undefined" && process.env.RETRIVORA_ALLOW_LOCAL_LICENSE_FALLBACK === "true";
|
|
16
|
+
const isLocalSdkRoute = baseUrl.startsWith("/api/retrivora") || baseUrl.includes("/api/retrivora");
|
|
17
|
+
if (status !== void 0) {
|
|
18
|
+
return status === 404 && (explicitFallback || isLocalSdkRoute);
|
|
19
|
+
}
|
|
20
|
+
return explicitFallback || isLocalSdkRoute;
|
|
21
|
+
}
|
|
22
|
+
var _LicenseValidator = class _LicenseValidator {
|
|
23
|
+
// 5-minute TTL for successful validation only
|
|
24
|
+
constructor() {
|
|
25
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
26
|
+
/** In-flight deduplication: concurrent calls for same key share one network request */
|
|
27
|
+
this.inflight = /* @__PURE__ */ new Map();
|
|
28
|
+
}
|
|
29
|
+
/** @returns Singleton instance of the validator (shared cache across all consumers). */
|
|
30
|
+
static getInstance() {
|
|
31
|
+
if (!_LicenseValidator.instance) {
|
|
32
|
+
_LicenseValidator.instance = new _LicenseValidator();
|
|
33
|
+
}
|
|
34
|
+
return _LicenseValidator.instance;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Purge entries from the local success cache.
|
|
38
|
+
*
|
|
39
|
+
* @param licenseKey - Optional. If provided, only that key's cache entry is
|
|
40
|
+
* removed. If omitted the entire cache is cleared.
|
|
41
|
+
* Callers use this after any 401/403 to ensure the next
|
|
42
|
+
* validate() call re-validates against the server.
|
|
43
|
+
*/
|
|
44
|
+
purgeCache(licenseKey) {
|
|
45
|
+
if (licenseKey) {
|
|
46
|
+
this.cache.delete(licenseKey);
|
|
47
|
+
} else {
|
|
48
|
+
this.cache.clear();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Primary validation entry-point for UI / hook consumers.
|
|
53
|
+
*
|
|
54
|
+
* Resolves the license key, consults the local success cache, performs a
|
|
55
|
+
* server POST for authoritative status, and falls back to `LicenseVerifier.verifyAsync()`
|
|
56
|
+
* if the server can't be reached.
|
|
57
|
+
*
|
|
58
|
+
* @throws LicenseValidationError - When no key is provided OR both the
|
|
59
|
+
* server call AND the fallback report an invalid/expired key.
|
|
60
|
+
* @throws SDKVersionUnsupportedError - When server reports forceUpgrade=true.
|
|
61
|
+
* @returns A `LicenseValidationResponse` that the UI can use to enable or
|
|
62
|
+
* lock the chat widget.
|
|
63
|
+
*/
|
|
64
|
+
async validate(request) {
|
|
65
|
+
const {
|
|
66
|
+
licenseKey,
|
|
67
|
+
projectId,
|
|
68
|
+
sdkVersion = SDK_VERSION,
|
|
69
|
+
sdk = "@retrivora-ai/rag-engine",
|
|
70
|
+
platform = typeof window !== "undefined" ? "browser" : "node",
|
|
71
|
+
retrivoraApiBase,
|
|
72
|
+
headers: customHeaders
|
|
73
|
+
} = request;
|
|
74
|
+
const effectiveProjectId = projectId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_PROJECT_ID || process.env.RETRIVORA_PROJECT_ID : "") || "";
|
|
75
|
+
const getHeader = (name) => {
|
|
76
|
+
if (!customHeaders) return void 0;
|
|
77
|
+
const target = name.toLowerCase();
|
|
78
|
+
for (const [k, v] of Object.entries(customHeaders)) {
|
|
79
|
+
if (k.toLowerCase() === target) return v;
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
};
|
|
83
|
+
const authHeader = getHeader("authorization");
|
|
84
|
+
let authHeaderKey = "";
|
|
85
|
+
if (authHeader && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
86
|
+
authHeaderKey = authHeader.replace(/^Bearer\s+/i, "");
|
|
87
|
+
if (authHeaderKey) {
|
|
88
|
+
console.warn(
|
|
89
|
+
'[Retrivora SDK] DEPRECATION WARNING (SEC-7): Repurposing the standard "Authorization: Bearer" header to carry the license key is deprecated and will be removed in a future release. Please use the custom "x-license-key" header instead.'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const rawKey = licenseKey || getHeader("x-license-key") || authHeaderKey || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
|
|
94
|
+
const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
95
|
+
if (!effectiveLicenseKey) {
|
|
96
|
+
this.purgeCache(effectiveLicenseKey);
|
|
97
|
+
throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
|
|
98
|
+
}
|
|
99
|
+
const cached = this.cache.get(effectiveLicenseKey);
|
|
100
|
+
if (cached) {
|
|
101
|
+
const isFresh = Date.now() - cached.timestamp < _LicenseValidator.SUCCESS_CACHE_TTL_MS;
|
|
102
|
+
if (isFresh && cached.response.valid && cached.response.licenseStatus === "ACTIVE" && !cached.response.forceUpgrade) {
|
|
103
|
+
return cached.response;
|
|
104
|
+
} else {
|
|
105
|
+
this.cache.delete(effectiveLicenseKey);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const existing = this.inflight.get(effectiveLicenseKey);
|
|
109
|
+
if (existing) return existing;
|
|
110
|
+
const inflightPromise = this._doNetworkValidate(
|
|
111
|
+
effectiveLicenseKey,
|
|
112
|
+
effectiveProjectId,
|
|
113
|
+
sdkVersion,
|
|
114
|
+
sdk,
|
|
115
|
+
platform,
|
|
116
|
+
retrivoraApiBase,
|
|
117
|
+
customHeaders
|
|
118
|
+
);
|
|
119
|
+
this.inflight.set(effectiveLicenseKey, inflightPromise);
|
|
120
|
+
try {
|
|
121
|
+
return await inflightPromise;
|
|
122
|
+
} finally {
|
|
123
|
+
this.inflight.delete(effectiveLicenseKey);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Performs the actual network request. Called once; result shared by in-flight dedup. */
|
|
127
|
+
async _doNetworkValidate(effectiveLicenseKey, effectiveProjectId, sdkVersion, sdk, platform, retrivoraApiBase, customHeaders) {
|
|
128
|
+
const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
|
|
129
|
+
const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
|
|
130
|
+
let res = null;
|
|
131
|
+
try {
|
|
132
|
+
res = await fetch(validateUrl, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
cache: "no-store",
|
|
135
|
+
headers: __spreadValues({
|
|
136
|
+
"Content-Type": "application/json",
|
|
137
|
+
"x-license-key": effectiveLicenseKey,
|
|
138
|
+
"x-sdk-version": sdkVersion
|
|
139
|
+
}, customHeaders || {}),
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
licenseKey: effectiveLicenseKey,
|
|
142
|
+
projectId: effectiveProjectId,
|
|
143
|
+
sdkVersion,
|
|
144
|
+
sdk,
|
|
145
|
+
platform
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
} catch (err) {
|
|
149
|
+
try {
|
|
150
|
+
if (!canUseLocalValidationFallback(base)) {
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
154
|
+
const fallbackResp = {
|
|
155
|
+
valid: true,
|
|
156
|
+
licenseStatus: "ACTIVE",
|
|
157
|
+
minimumSupportedVersion: "2.1.0",
|
|
158
|
+
latestVersion: SDK_VERSION,
|
|
159
|
+
forceUpgrade: false,
|
|
160
|
+
expiresAt: payload.expiresAt ? new Date(payload.expiresAt * 1e3).toISOString() : null,
|
|
161
|
+
message: "Local license verification active."
|
|
162
|
+
};
|
|
163
|
+
this.cache.set(effectiveLicenseKey, { response: fallbackResp, timestamp: Date.now() });
|
|
164
|
+
return fallbackResp;
|
|
165
|
+
} catch (e) {
|
|
166
|
+
this.purgeCache(effectiveLicenseKey);
|
|
167
|
+
throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
|
|
171
|
+
try {
|
|
172
|
+
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
173
|
+
const fallbackResp = {
|
|
174
|
+
valid: true,
|
|
175
|
+
licenseStatus: "ACTIVE",
|
|
176
|
+
minimumSupportedVersion: "2.1.0",
|
|
177
|
+
latestVersion: SDK_VERSION,
|
|
178
|
+
forceUpgrade: false,
|
|
179
|
+
expiresAt: payload.expiresAt ? new Date(payload.expiresAt * 1e3).toISOString() : null,
|
|
180
|
+
message: "Local license verification active."
|
|
181
|
+
};
|
|
182
|
+
this.cache.set(effectiveLicenseKey, { response: fallbackResp, timestamp: Date.now() });
|
|
183
|
+
return fallbackResp;
|
|
184
|
+
} catch (e) {
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const data = await res.json().catch(() => ({
|
|
188
|
+
valid: false,
|
|
189
|
+
licenseStatus: "REVOKED",
|
|
190
|
+
minimumSupportedVersion: "2.1.0",
|
|
191
|
+
latestVersion: SDK_VERSION,
|
|
192
|
+
forceUpgrade: false,
|
|
193
|
+
expiresAt: null,
|
|
194
|
+
message: "Failed to parse license validation response."
|
|
195
|
+
}));
|
|
196
|
+
if (!res.ok || !data.valid || data.licenseStatus !== "ACTIVE" || data.forceUpgrade) {
|
|
197
|
+
this.purgeCache(effectiveLicenseKey);
|
|
198
|
+
if (data.forceUpgrade || res.status === 426) {
|
|
199
|
+
throw new SDKVersionUnsupportedError(
|
|
200
|
+
data.message || `This SDK version (${sdkVersion}) is no longer supported. Upgrade to version ${data.latestVersion || "2.2.6"} or later.`,
|
|
201
|
+
data
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const errMsg = data.message || `License validation failed with status: ${data.licenseStatus}. Access denied.`;
|
|
205
|
+
throw new LicenseValidationError(errMsg, data);
|
|
206
|
+
}
|
|
207
|
+
this.cache.set(effectiveLicenseKey, {
|
|
208
|
+
response: data,
|
|
209
|
+
timestamp: Date.now()
|
|
210
|
+
});
|
|
211
|
+
return data;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
_LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
215
|
+
var LicenseValidator = _LicenseValidator;
|
|
216
|
+
|
|
217
|
+
export {
|
|
218
|
+
LicenseValidator
|
|
219
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadValues
|
|
3
|
+
} from "./chunk-UT6SZZEC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/templateUtils.ts
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null;
|
|
8
|
+
}
|
|
9
|
+
function resolvePath(obj, path) {
|
|
10
|
+
if (!path || !obj) return void 0;
|
|
11
|
+
return path.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "").split(".").reduce((current, segment) => {
|
|
12
|
+
if (segment === "__proto__" || segment === "constructor" || segment === "prototype") {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
if (!isRecord(current) && !Array.isArray(current)) {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
return current[segment];
|
|
19
|
+
}, obj);
|
|
20
|
+
}
|
|
21
|
+
function buildPayload(template, vars) {
|
|
22
|
+
let raw = template;
|
|
23
|
+
for (const [key, val] of Object.entries(vars)) {
|
|
24
|
+
const stringifiedVal = val === void 0 ? "null" : JSON.stringify(val);
|
|
25
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
26
|
+
raw = raw.replace(new RegExp(`"\\{\\{${escapedKey}\\}\\}"`, "g"), () => stringifiedVal);
|
|
27
|
+
raw = raw.replace(new RegExp(`\\{\\{${escapedKey}\\}\\}`, "g"), () => stringifiedVal);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(raw);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new Error(`Failed to parse payload template: ${err.message}
|
|
33
|
+
Raw payload: ${raw}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function mergeDefined(base, override) {
|
|
37
|
+
const merged = __spreadValues({}, base || {});
|
|
38
|
+
if (!override) {
|
|
39
|
+
return merged;
|
|
40
|
+
}
|
|
41
|
+
for (const [key, value] of Object.entries(override)) {
|
|
42
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
43
|
+
merged[key] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return merged;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
resolvePath,
|
|
51
|
+
buildPayload,
|
|
52
|
+
mergeDefined
|
|
53
|
+
};
|