@axiom-lattice/local-stores 3.2.1 → 3.2.3
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +24 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +59 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalConnectionStore.test.ts +176 -0
- package/src/stores/LocalConnectionStore.ts +46 -7
package/dist/index.mjs
CHANGED
|
@@ -1993,6 +1993,7 @@ function encryptPasswordInConfig(config) {
|
|
|
1993
1993
|
|
|
1994
1994
|
// src/stores/LocalConnectionStore.ts
|
|
1995
1995
|
import { v4 as uuid } from "uuid";
|
|
1996
|
+
import { encryptConfigFields, decryptConfigFields } from "@axiom-lattice/core";
|
|
1996
1997
|
var DDL9 = `
|
|
1997
1998
|
CREATE TABLE IF NOT EXISTS connection_configs (
|
|
1998
1999
|
id TEXT NOT NULL,
|
|
@@ -2002,6 +2003,7 @@ CREATE TABLE IF NOT EXISTS connection_configs (
|
|
|
2002
2003
|
name TEXT NOT NULL,
|
|
2003
2004
|
description TEXT,
|
|
2004
2005
|
config TEXT NOT NULL,
|
|
2006
|
+
secret_fields TEXT,
|
|
2005
2007
|
created_at TEXT NOT NULL,
|
|
2006
2008
|
updated_at TEXT NOT NULL,
|
|
2007
2009
|
PRIMARY KEY (tenant_id, id),
|
|
@@ -2009,10 +2011,28 @@ CREATE TABLE IF NOT EXISTS connection_configs (
|
|
|
2009
2011
|
);
|
|
2010
2012
|
CREATE INDEX IF NOT EXISTS idx_conn_type ON connection_configs(tenant_id, type);
|
|
2011
2013
|
`;
|
|
2014
|
+
function parseSecretFields(raw) {
|
|
2015
|
+
if (!raw) return void 0;
|
|
2016
|
+
try {
|
|
2017
|
+
const parsed = JSON.parse(raw);
|
|
2018
|
+
if (Array.isArray(parsed) && parsed.every((v) => typeof v === "string") && parsed.length > 0) {
|
|
2019
|
+
return parsed;
|
|
2020
|
+
}
|
|
2021
|
+
} catch {
|
|
2022
|
+
}
|
|
2023
|
+
return void 0;
|
|
2024
|
+
}
|
|
2012
2025
|
var LocalConnectionStore = class {
|
|
2013
2026
|
constructor(db) {
|
|
2014
2027
|
this.db = db;
|
|
2015
2028
|
ensureTable(db, DDL9);
|
|
2029
|
+
this.ensureColumn("connection_configs", "secret_fields", "secret_fields TEXT");
|
|
2030
|
+
}
|
|
2031
|
+
ensureColumn(table, column, ddl2) {
|
|
2032
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
2033
|
+
if (!cols.some((c) => c.name === column)) {
|
|
2034
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl2}`);
|
|
2035
|
+
}
|
|
2016
2036
|
}
|
|
2017
2037
|
async listByTenant(tenantId) {
|
|
2018
2038
|
const rows2 = this.db.prepare(
|
|
@@ -2035,11 +2055,23 @@ var LocalConnectionStore = class {
|
|
|
2035
2055
|
async create(entry) {
|
|
2036
2056
|
const id = uuid();
|
|
2037
2057
|
const now = nowISO();
|
|
2058
|
+
const secretFields = entry.secretFields?.length ? entry.secretFields : void 0;
|
|
2038
2059
|
this.db.prepare(
|
|
2039
|
-
`INSERT INTO connection_configs (id, tenant_id, type, key, name, description, config, created_at, updated_at)
|
|
2040
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
2041
|
-
).run(
|
|
2042
|
-
|
|
2060
|
+
`INSERT INTO connection_configs (id, tenant_id, type, key, name, description, config, secret_fields, created_at, updated_at)
|
|
2061
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
2062
|
+
).run(
|
|
2063
|
+
id,
|
|
2064
|
+
entry.tenantId,
|
|
2065
|
+
entry.type,
|
|
2066
|
+
entry.key,
|
|
2067
|
+
entry.name,
|
|
2068
|
+
entry.description || null,
|
|
2069
|
+
JSON.stringify(encryptConfigFields(entry.config, secretFields)),
|
|
2070
|
+
secretFields ? JSON.stringify(secretFields) : null,
|
|
2071
|
+
now,
|
|
2072
|
+
now
|
|
2073
|
+
);
|
|
2074
|
+
return { id, ...entry, secretFields, createdAt: now, updatedAt: now };
|
|
2043
2075
|
}
|
|
2044
2076
|
async update(tenantId, type, key, updates) {
|
|
2045
2077
|
const existing = await this.getByKey(tenantId, type, key);
|
|
@@ -2055,8 +2087,11 @@ var LocalConnectionStore = class {
|
|
|
2055
2087
|
values.push(updates.description || null);
|
|
2056
2088
|
}
|
|
2057
2089
|
if (updates.config !== void 0) {
|
|
2090
|
+
const secretFields = updates.secretFields?.length ? updates.secretFields : existing.secretFields?.length ? existing.secretFields : void 0;
|
|
2058
2091
|
setClauses.push("config = ?");
|
|
2059
|
-
values.push(JSON.stringify(updates.config));
|
|
2092
|
+
values.push(JSON.stringify(encryptConfigFields(updates.config, secretFields)));
|
|
2093
|
+
setClauses.push("secret_fields = ?");
|
|
2094
|
+
values.push(secretFields ? JSON.stringify(secretFields) : null);
|
|
2060
2095
|
}
|
|
2061
2096
|
if (setClauses.length === 0) return existing;
|
|
2062
2097
|
const now = nowISO();
|
|
@@ -2075,6 +2110,8 @@ var LocalConnectionStore = class {
|
|
|
2075
2110
|
return result.changes > 0;
|
|
2076
2111
|
}
|
|
2077
2112
|
mapRow(row) {
|
|
2113
|
+
const secretFields = parseSecretFields(row.secret_fields);
|
|
2114
|
+
const storedConfig = JSON.parse(row.config);
|
|
2078
2115
|
return {
|
|
2079
2116
|
id: row.id,
|
|
2080
2117
|
tenantId: row.tenant_id,
|
|
@@ -2082,7 +2119,8 @@ var LocalConnectionStore = class {
|
|
|
2082
2119
|
key: row.key,
|
|
2083
2120
|
name: row.name,
|
|
2084
2121
|
description: row.description || void 0,
|
|
2085
|
-
config:
|
|
2122
|
+
config: decryptConfigFields(storedConfig, secretFields),
|
|
2123
|
+
secretFields,
|
|
2086
2124
|
createdAt: row.created_at,
|
|
2087
2125
|
updatedAt: row.updated_at
|
|
2088
2126
|
};
|