@axiom-lattice/local-stores 5.0.3 → 5.1.1
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 +102 -0
- package/dist/index.d.mts +127 -2
- package/dist/index.d.ts +127 -2
- package/dist/index.js +947 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +931 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalInviteLinkStore.test.ts +48 -0
- package/src/__tests__/LocalOidcIdentityClaimStore.test.ts +114 -0
- package/src/__tests__/LocalOidcProviderConfigStore.test.ts +203 -0
- package/src/__tests__/LocalPlatformInvitationStore.test.ts +207 -0
- package/src/__tests__/LocalPlatformMemberStore.test.ts +123 -0
- package/src/__tests__/LocalPlatformSettingsStore.test.ts +120 -0
- package/src/__tests__/LocalUserExternalIdentityStore.test.ts +104 -0
- package/src/__tests__/LocalUserStore.test.ts +44 -0
- package/src/createLocalStoreConfig.ts +14 -0
- package/src/index.ts +7 -0
- package/src/stores/LocalInviteLinkStore.ts +162 -0
- package/src/stores/LocalOidcIdentityClaimStore.ts +316 -0
- package/src/stores/LocalOidcProviderConfigStore.ts +260 -0
- package/src/stores/LocalPlatformInvitationStore.ts +139 -0
- package/src/stores/LocalPlatformMemberStore.ts +108 -0
- package/src/stores/LocalPlatformSettingsStore.ts +115 -0
- package/src/stores/LocalUserExternalIdentityStore.ts +120 -0
- package/src/stores/LocalUserStore.ts +3 -2
package/dist/index.js
CHANGED
|
@@ -42,10 +42,16 @@ __export(index_exports, {
|
|
|
42
42
|
LocalConnectionStore: () => LocalConnectionStore,
|
|
43
43
|
LocalDatabaseConfigStore: () => LocalDatabaseConfigStore,
|
|
44
44
|
LocalEvalStore: () => LocalEvalStore,
|
|
45
|
+
LocalInviteLinkStore: () => LocalInviteLinkStore,
|
|
45
46
|
LocalMcpServerConfigStore: () => LocalMcpServerConfigStore,
|
|
46
47
|
LocalMetricsServerConfigStore: () => LocalMetricsServerConfigStore,
|
|
47
48
|
LocalModelProviderStore: () => LocalModelProviderStore,
|
|
49
|
+
LocalOidcIdentityClaimStore: () => LocalOidcIdentityClaimStore,
|
|
50
|
+
LocalOidcProviderConfigStore: () => LocalOidcProviderConfigStore,
|
|
48
51
|
LocalOpenAuditStore: () => LocalOpenAuditStore,
|
|
52
|
+
LocalPlatformInvitationStore: () => LocalPlatformInvitationStore,
|
|
53
|
+
LocalPlatformMemberStore: () => LocalPlatformMemberStore,
|
|
54
|
+
LocalPlatformSettingsStore: () => LocalPlatformSettingsStore,
|
|
49
55
|
LocalProjectBotMembershipStore: () => LocalProjectBotMembershipStore,
|
|
50
56
|
LocalProjectMembershipStore: () => LocalProjectMembershipStore,
|
|
51
57
|
LocalProjectRoomMessageStore: () => LocalProjectRoomMessageStore,
|
|
@@ -60,6 +66,7 @@ __export(index_exports, {
|
|
|
60
66
|
LocalTenantStore: () => LocalTenantStore,
|
|
61
67
|
LocalThreadMessageQueueStore: () => LocalThreadMessageQueueStore,
|
|
62
68
|
LocalThreadStore: () => LocalThreadStore,
|
|
69
|
+
LocalUserExternalIdentityStore: () => LocalUserExternalIdentityStore,
|
|
63
70
|
LocalUserStore: () => LocalUserStore,
|
|
64
71
|
LocalUserTenantLinkStore: () => LocalUserTenantLinkStore,
|
|
65
72
|
LocalWorkflowTrackingStore: () => LocalWorkflowTrackingStore,
|
|
@@ -1821,6 +1828,7 @@ CREATE TABLE IF NOT EXISTS lt_users (
|
|
|
1821
1828
|
updated_at TEXT NOT NULL
|
|
1822
1829
|
);
|
|
1823
1830
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_users_email ON lt_users(email);
|
|
1831
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_users_email_lower ON lt_users(lower(email));
|
|
1824
1832
|
`;
|
|
1825
1833
|
var LocalUserStore = class {
|
|
1826
1834
|
constructor(db) {
|
|
@@ -1841,8 +1849,8 @@ var LocalUserStore = class {
|
|
|
1841
1849
|
}
|
|
1842
1850
|
async getUserByEmail(email) {
|
|
1843
1851
|
const row = this.db.prepare(
|
|
1844
|
-
`SELECT * FROM lt_users WHERE email =
|
|
1845
|
-
).get(email);
|
|
1852
|
+
`SELECT * FROM lt_users WHERE lower(email) = lower(?)`
|
|
1853
|
+
).get(email.trim());
|
|
1846
1854
|
return row ? mapRowToUser(row) : null;
|
|
1847
1855
|
}
|
|
1848
1856
|
async createUser(id, data) {
|
|
@@ -2116,9 +2124,849 @@ function mapRowToLink(row) {
|
|
|
2116
2124
|
};
|
|
2117
2125
|
}
|
|
2118
2126
|
|
|
2119
|
-
// src/stores/
|
|
2120
|
-
var
|
|
2127
|
+
// src/stores/LocalUserExternalIdentityStore.ts
|
|
2128
|
+
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
2121
2129
|
var DDL9 = `
|
|
2130
|
+
CREATE TABLE IF NOT EXISTS lt_user_identities (
|
|
2131
|
+
user_id TEXT NOT NULL,
|
|
2132
|
+
provider_id TEXT NOT NULL,
|
|
2133
|
+
issuer TEXT NOT NULL,
|
|
2134
|
+
subject TEXT NOT NULL,
|
|
2135
|
+
email TEXT,
|
|
2136
|
+
linked_at TEXT NOT NULL,
|
|
2137
|
+
PRIMARY KEY (provider_id, issuer, subject)
|
|
2138
|
+
);
|
|
2139
|
+
CREATE INDEX IF NOT EXISTS idx_lt_user_identities_user
|
|
2140
|
+
ON lt_user_identities (user_id);
|
|
2141
|
+
`;
|
|
2142
|
+
function mapRow7(row) {
|
|
2143
|
+
return {
|
|
2144
|
+
userId: row.user_id,
|
|
2145
|
+
providerId: row.provider_id,
|
|
2146
|
+
issuer: row.issuer,
|
|
2147
|
+
subject: row.subject,
|
|
2148
|
+
...row.email === null ? {} : { email: row.email },
|
|
2149
|
+
linkedAt: parseISO(row.linked_at)
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
var LocalUserExternalIdentityStore = class {
|
|
2153
|
+
constructor(db) {
|
|
2154
|
+
this.db = db;
|
|
2155
|
+
ensureTable(db, DDL9);
|
|
2156
|
+
}
|
|
2157
|
+
async getByProviderSubject(providerId, issuer, subject) {
|
|
2158
|
+
const row = this.db.prepare(
|
|
2159
|
+
`SELECT * FROM lt_user_identities
|
|
2160
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?`
|
|
2161
|
+
).get(providerId, issuer, subject);
|
|
2162
|
+
return row ? mapRow7(row) : null;
|
|
2163
|
+
}
|
|
2164
|
+
async listByUser(userId) {
|
|
2165
|
+
const rows2 = this.db.prepare(`SELECT * FROM lt_user_identities WHERE user_id = ? ORDER BY linked_at ASC`).all(userId);
|
|
2166
|
+
return rows2.map(mapRow7);
|
|
2167
|
+
}
|
|
2168
|
+
async link(identity) {
|
|
2169
|
+
this.db.prepare(
|
|
2170
|
+
`INSERT INTO lt_user_identities (user_id, provider_id, issuer, subject, email, linked_at)
|
|
2171
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
2172
|
+
ON CONFLICT(provider_id, issuer, subject) DO NOTHING`
|
|
2173
|
+
).run(
|
|
2174
|
+
identity.userId,
|
|
2175
|
+
identity.providerId,
|
|
2176
|
+
identity.issuer,
|
|
2177
|
+
identity.subject,
|
|
2178
|
+
identity.email ?? null,
|
|
2179
|
+
identity.linkedAt.toISOString()
|
|
2180
|
+
);
|
|
2181
|
+
const existing = await this.getByProviderSubject(
|
|
2182
|
+
identity.providerId,
|
|
2183
|
+
identity.issuer,
|
|
2184
|
+
identity.subject
|
|
2185
|
+
);
|
|
2186
|
+
if (!existing) {
|
|
2187
|
+
throw new import_protocols3.ExternalIdentityPersistError(
|
|
2188
|
+
identity.providerId,
|
|
2189
|
+
identity.issuer,
|
|
2190
|
+
identity.subject
|
|
2191
|
+
);
|
|
2192
|
+
}
|
|
2193
|
+
if (existing.userId !== identity.userId) {
|
|
2194
|
+
throw new import_protocols3.ExternalIdentityConflictError(
|
|
2195
|
+
identity.providerId,
|
|
2196
|
+
identity.issuer,
|
|
2197
|
+
identity.subject
|
|
2198
|
+
);
|
|
2199
|
+
}
|
|
2200
|
+
if (identity.email !== void 0 && identity.email !== existing.email) {
|
|
2201
|
+
this.db.prepare(
|
|
2202
|
+
`UPDATE lt_user_identities SET email = ?
|
|
2203
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?`
|
|
2204
|
+
).run(identity.email, identity.providerId, identity.issuer, identity.subject);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
async unlink(providerId, issuer, subject) {
|
|
2208
|
+
this.db.prepare(
|
|
2209
|
+
`DELETE FROM lt_user_identities
|
|
2210
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?`
|
|
2211
|
+
).run(providerId, issuer, subject);
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
|
|
2215
|
+
// src/stores/LocalOidcProviderConfigStore.ts
|
|
2216
|
+
var import_core = require("@axiom-lattice/core");
|
|
2217
|
+
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
2218
|
+
var DDL10 = `
|
|
2219
|
+
CREATE TABLE IF NOT EXISTS lattice_oidc_provider_configs (
|
|
2220
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2221
|
+
display_name TEXT NOT NULL,
|
|
2222
|
+
issuer TEXT NOT NULL,
|
|
2223
|
+
client_id TEXT NOT NULL,
|
|
2224
|
+
client_secret TEXT NOT NULL,
|
|
2225
|
+
scopes TEXT NOT NULL,
|
|
2226
|
+
enabled INTEGER NOT NULL,
|
|
2227
|
+
jit_provisioning INTEGER NOT NULL,
|
|
2228
|
+
auto_link_email INTEGER NOT NULL,
|
|
2229
|
+
default_tenant_id TEXT,
|
|
2230
|
+
allowed_private_hosts TEXT,
|
|
2231
|
+
created_at TEXT NOT NULL,
|
|
2232
|
+
updated_at TEXT NOT NULL
|
|
2233
|
+
);
|
|
2234
|
+
`;
|
|
2235
|
+
function parseAllowedPrivateHosts(value) {
|
|
2236
|
+
if (value === null) return void 0;
|
|
2237
|
+
try {
|
|
2238
|
+
const parsed = JSON.parse(value);
|
|
2239
|
+
return Array.isArray(parsed) ? parsed.filter((entry) => typeof entry === "string") : void 0;
|
|
2240
|
+
} catch {
|
|
2241
|
+
return void 0;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function serializeAllowedPrivateHosts(value) {
|
|
2245
|
+
return value === void 0 ? null : JSON.stringify(value);
|
|
2246
|
+
}
|
|
2247
|
+
function normalizeTenantId(value) {
|
|
2248
|
+
if (typeof value !== "string") return void 0;
|
|
2249
|
+
const trimmed = value.trim();
|
|
2250
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2251
|
+
}
|
|
2252
|
+
function mapRow8(row) {
|
|
2253
|
+
const allowedPrivateHosts = parseAllowedPrivateHosts(
|
|
2254
|
+
row.allowed_private_hosts
|
|
2255
|
+
);
|
|
2256
|
+
return {
|
|
2257
|
+
id: row.id,
|
|
2258
|
+
displayName: row.display_name,
|
|
2259
|
+
issuer: row.issuer,
|
|
2260
|
+
clientId: row.client_id,
|
|
2261
|
+
clientSecret: (0, import_core.safeDecrypt)(
|
|
2262
|
+
row.client_secret,
|
|
2263
|
+
`OIDC provider config "${row.id}" client secret`
|
|
2264
|
+
),
|
|
2265
|
+
scopes: row.scopes,
|
|
2266
|
+
enabled: Number(row.enabled) === 1,
|
|
2267
|
+
jitProvisioning: Number(row.jit_provisioning) === 1,
|
|
2268
|
+
autoLinkEmail: Number(row.auto_link_email) === 1,
|
|
2269
|
+
...row.default_tenant_id !== null ? { defaultTenantId: row.default_tenant_id } : {},
|
|
2270
|
+
...allowedPrivateHosts !== void 0 ? { allowedPrivateHosts } : {},
|
|
2271
|
+
createdAt: parseISO(row.created_at),
|
|
2272
|
+
updatedAt: parseISO(row.updated_at)
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2275
|
+
var LocalOidcProviderConfigStore = class {
|
|
2276
|
+
constructor(db) {
|
|
2277
|
+
this.db = db;
|
|
2278
|
+
ensureTable(db, DDL10);
|
|
2279
|
+
this.ensureColumn(
|
|
2280
|
+
"lattice_oidc_provider_configs",
|
|
2281
|
+
"allowed_private_hosts",
|
|
2282
|
+
"allowed_private_hosts TEXT"
|
|
2283
|
+
);
|
|
2284
|
+
}
|
|
2285
|
+
ensureColumn(table, column, ddl2) {
|
|
2286
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
2287
|
+
if (!cols.some((entry) => entry.name === column)) {
|
|
2288
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl2}`);
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
async list() {
|
|
2292
|
+
const rows2 = this.db.prepare(
|
|
2293
|
+
`SELECT * FROM lattice_oidc_provider_configs ORDER BY created_at ASC, id ASC`
|
|
2294
|
+
).all();
|
|
2295
|
+
return rows2.map(mapRow8);
|
|
2296
|
+
}
|
|
2297
|
+
async get(id) {
|
|
2298
|
+
const row = this.db.prepare(`SELECT * FROM lattice_oidc_provider_configs WHERE id = ?`).get(id);
|
|
2299
|
+
return row ? mapRow8(row) : null;
|
|
2300
|
+
}
|
|
2301
|
+
async create(id, input) {
|
|
2302
|
+
if (this.db.prepare(`SELECT 1 FROM lattice_oidc_provider_configs WHERE id = ?`).get(id)) {
|
|
2303
|
+
throw new import_protocols4.OidcProviderConfigConflictError(id);
|
|
2304
|
+
}
|
|
2305
|
+
const now = nowISO();
|
|
2306
|
+
const tenantId = normalizeTenantId(input.defaultTenantId);
|
|
2307
|
+
try {
|
|
2308
|
+
this.db.prepare(
|
|
2309
|
+
`INSERT INTO lattice_oidc_provider_configs
|
|
2310
|
+
(id, display_name, issuer, client_id, client_secret, scopes,
|
|
2311
|
+
enabled, jit_provisioning, auto_link_email, default_tenant_id,
|
|
2312
|
+
allowed_private_hosts, created_at, updated_at)
|
|
2313
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
2314
|
+
).run(
|
|
2315
|
+
id,
|
|
2316
|
+
input.displayName,
|
|
2317
|
+
input.issuer,
|
|
2318
|
+
input.clientId,
|
|
2319
|
+
(0, import_core.encrypt)(input.clientSecret),
|
|
2320
|
+
input.scopes,
|
|
2321
|
+
input.enabled ? 1 : 0,
|
|
2322
|
+
input.jitProvisioning ? 1 : 0,
|
|
2323
|
+
input.autoLinkEmail ? 1 : 0,
|
|
2324
|
+
tenantId ?? null,
|
|
2325
|
+
serializeAllowedPrivateHosts(input.allowedPrivateHosts),
|
|
2326
|
+
now,
|
|
2327
|
+
now
|
|
2328
|
+
);
|
|
2329
|
+
} catch (error) {
|
|
2330
|
+
if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
|
|
2331
|
+
throw new import_protocols4.OidcProviderConfigConflictError(id);
|
|
2332
|
+
}
|
|
2333
|
+
throw error;
|
|
2334
|
+
}
|
|
2335
|
+
const created = await this.get(id);
|
|
2336
|
+
if (!created) {
|
|
2337
|
+
throw new Error(`OIDC provider config "${id}" was not persisted`);
|
|
2338
|
+
}
|
|
2339
|
+
return created;
|
|
2340
|
+
}
|
|
2341
|
+
async update(id, updates) {
|
|
2342
|
+
const existing = await this.get(id);
|
|
2343
|
+
if (!existing) return null;
|
|
2344
|
+
const setClauses = [];
|
|
2345
|
+
const values = [];
|
|
2346
|
+
if (updates.displayName !== void 0) {
|
|
2347
|
+
setClauses.push("display_name = ?");
|
|
2348
|
+
values.push(updates.displayName);
|
|
2349
|
+
}
|
|
2350
|
+
if (updates.issuer !== void 0) {
|
|
2351
|
+
setClauses.push("issuer = ?");
|
|
2352
|
+
values.push(updates.issuer);
|
|
2353
|
+
}
|
|
2354
|
+
if (updates.clientId !== void 0) {
|
|
2355
|
+
setClauses.push("client_id = ?");
|
|
2356
|
+
values.push(updates.clientId);
|
|
2357
|
+
}
|
|
2358
|
+
if (updates.clientSecret !== void 0 && updates.clientSecret !== "") {
|
|
2359
|
+
setClauses.push("client_secret = ?");
|
|
2360
|
+
values.push((0, import_core.encrypt)(updates.clientSecret));
|
|
2361
|
+
}
|
|
2362
|
+
if (updates.scopes !== void 0) {
|
|
2363
|
+
setClauses.push("scopes = ?");
|
|
2364
|
+
values.push(updates.scopes);
|
|
2365
|
+
}
|
|
2366
|
+
if (updates.enabled !== void 0) {
|
|
2367
|
+
setClauses.push("enabled = ?");
|
|
2368
|
+
values.push(updates.enabled ? 1 : 0);
|
|
2369
|
+
}
|
|
2370
|
+
if (updates.jitProvisioning !== void 0) {
|
|
2371
|
+
setClauses.push("jit_provisioning = ?");
|
|
2372
|
+
values.push(updates.jitProvisioning ? 1 : 0);
|
|
2373
|
+
}
|
|
2374
|
+
if (updates.autoLinkEmail !== void 0) {
|
|
2375
|
+
setClauses.push("auto_link_email = ?");
|
|
2376
|
+
values.push(updates.autoLinkEmail ? 1 : 0);
|
|
2377
|
+
}
|
|
2378
|
+
if (updates.defaultTenantId !== void 0) {
|
|
2379
|
+
setClauses.push("default_tenant_id = ?");
|
|
2380
|
+
values.push(normalizeTenantId(updates.defaultTenantId) ?? null);
|
|
2381
|
+
}
|
|
2382
|
+
if (updates.allowedPrivateHosts !== void 0) {
|
|
2383
|
+
setClauses.push("allowed_private_hosts = ?");
|
|
2384
|
+
values.push(serializeAllowedPrivateHosts(updates.allowedPrivateHosts));
|
|
2385
|
+
}
|
|
2386
|
+
if (setClauses.length === 0) return existing;
|
|
2387
|
+
setClauses.push("updated_at = ?");
|
|
2388
|
+
values.push(nowISO());
|
|
2389
|
+
values.push(id);
|
|
2390
|
+
this.db.prepare(
|
|
2391
|
+
`UPDATE lattice_oidc_provider_configs SET ${setClauses.join(", ")} WHERE id = ?`
|
|
2392
|
+
).run(...values);
|
|
2393
|
+
return this.get(id);
|
|
2394
|
+
}
|
|
2395
|
+
async delete(id) {
|
|
2396
|
+
const result = this.db.prepare(`DELETE FROM lattice_oidc_provider_configs WHERE id = ?`).run(id);
|
|
2397
|
+
return result.changes > 0;
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
|
|
2401
|
+
// src/stores/LocalPlatformMemberStore.ts
|
|
2402
|
+
var DDL11 = `
|
|
2403
|
+
CREATE TABLE IF NOT EXISTS lattice_platform_members (
|
|
2404
|
+
user_id TEXT NOT NULL PRIMARY KEY,
|
|
2405
|
+
role TEXT NOT NULL,
|
|
2406
|
+
granted_by TEXT,
|
|
2407
|
+
granted_at TEXT NOT NULL,
|
|
2408
|
+
updated_at TEXT NOT NULL
|
|
2409
|
+
);
|
|
2410
|
+
`;
|
|
2411
|
+
function mapRow9(row) {
|
|
2412
|
+
return {
|
|
2413
|
+
userId: row.user_id,
|
|
2414
|
+
role: row.role,
|
|
2415
|
+
...row.granted_by !== null ? { grantedBy: row.granted_by } : {},
|
|
2416
|
+
grantedAt: parseISO(row.granted_at),
|
|
2417
|
+
updatedAt: parseISO(row.updated_at)
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
var LocalPlatformMemberStore = class {
|
|
2421
|
+
constructor(db) {
|
|
2422
|
+
this.db = db;
|
|
2423
|
+
ensureTable(db, DDL11);
|
|
2424
|
+
}
|
|
2425
|
+
/** Lists every platform member ordered by user id. */
|
|
2426
|
+
async list() {
|
|
2427
|
+
const rows2 = this.db.prepare(
|
|
2428
|
+
`SELECT * FROM lattice_platform_members ORDER BY user_id ASC`
|
|
2429
|
+
).all();
|
|
2430
|
+
return rows2.map(mapRow9);
|
|
2431
|
+
}
|
|
2432
|
+
/** Returns the platform member for a user, or null. */
|
|
2433
|
+
async get(userId) {
|
|
2434
|
+
const row = this.db.prepare(`SELECT * FROM lattice_platform_members WHERE user_id = ?`).get(userId);
|
|
2435
|
+
return row ? mapRow9(row) : null;
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* Inserts or replaces a member keyed by user id.
|
|
2439
|
+
*
|
|
2440
|
+
* The supplied grant replaces any existing row in full (last write wins),
|
|
2441
|
+
* including `grantedAt` and `updatedAt`.
|
|
2442
|
+
*/
|
|
2443
|
+
async upsert(member) {
|
|
2444
|
+
this.db.prepare(
|
|
2445
|
+
`INSERT INTO lattice_platform_members
|
|
2446
|
+
(user_id, role, granted_by, granted_at, updated_at)
|
|
2447
|
+
VALUES (?, ?, ?, ?, ?)
|
|
2448
|
+
ON CONFLICT(user_id) DO UPDATE SET
|
|
2449
|
+
role = excluded.role,
|
|
2450
|
+
granted_by = excluded.granted_by,
|
|
2451
|
+
granted_at = excluded.granted_at,
|
|
2452
|
+
updated_at = excluded.updated_at`
|
|
2453
|
+
).run(
|
|
2454
|
+
member.userId,
|
|
2455
|
+
member.role,
|
|
2456
|
+
member.grantedBy ?? null,
|
|
2457
|
+
member.grantedAt.toISOString(),
|
|
2458
|
+
member.updatedAt.toISOString()
|
|
2459
|
+
);
|
|
2460
|
+
const stored = await this.get(member.userId);
|
|
2461
|
+
if (!stored) {
|
|
2462
|
+
throw new Error(`Platform member "${member.userId}" was not persisted`);
|
|
2463
|
+
}
|
|
2464
|
+
return stored;
|
|
2465
|
+
}
|
|
2466
|
+
/** Deletes a member. Returns whether a row was removed. */
|
|
2467
|
+
async delete(userId) {
|
|
2468
|
+
const result = this.db.prepare(`DELETE FROM lattice_platform_members WHERE user_id = ?`).run(userId);
|
|
2469
|
+
return result.changes > 0;
|
|
2470
|
+
}
|
|
2471
|
+
};
|
|
2472
|
+
|
|
2473
|
+
// src/stores/LocalPlatformInvitationStore.ts
|
|
2474
|
+
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
2475
|
+
var DDL12 = `
|
|
2476
|
+
CREATE TABLE IF NOT EXISTS lattice_platform_invitations (
|
|
2477
|
+
email TEXT NOT NULL PRIMARY KEY,
|
|
2478
|
+
role TEXT NOT NULL,
|
|
2479
|
+
invited_by TEXT,
|
|
2480
|
+
created_at TEXT NOT NULL,
|
|
2481
|
+
expires_at TEXT,
|
|
2482
|
+
consumed_at TEXT
|
|
2483
|
+
);
|
|
2484
|
+
`;
|
|
2485
|
+
function mapRow10(row) {
|
|
2486
|
+
return {
|
|
2487
|
+
email: row.email,
|
|
2488
|
+
role: row.role,
|
|
2489
|
+
...row.invited_by !== null ? { invitedBy: row.invited_by } : {},
|
|
2490
|
+
createdAt: parseISO(row.created_at),
|
|
2491
|
+
...row.expires_at !== null ? { expiresAt: parseISO(row.expires_at) } : {},
|
|
2492
|
+
...row.consumed_at !== null ? { consumedAt: parseISO(row.consumed_at) } : {}
|
|
2493
|
+
};
|
|
2494
|
+
}
|
|
2495
|
+
var LocalPlatformInvitationStore = class {
|
|
2496
|
+
constructor(db) {
|
|
2497
|
+
this.db = db;
|
|
2498
|
+
ensureTable(db, DDL12);
|
|
2499
|
+
}
|
|
2500
|
+
/** Lists every invitation ordered by normalized email. */
|
|
2501
|
+
async list() {
|
|
2502
|
+
const rows2 = this.db.prepare(`SELECT * FROM lattice_platform_invitations ORDER BY email ASC`).all();
|
|
2503
|
+
return rows2.map(mapRow10);
|
|
2504
|
+
}
|
|
2505
|
+
/** Returns the invitation for an email, or null. */
|
|
2506
|
+
async get(email) {
|
|
2507
|
+
const row = this.db.prepare(`SELECT * FROM lattice_platform_invitations WHERE email = ?`).get((0, import_protocols5.normalizePlatformInvitationEmail)(email));
|
|
2508
|
+
return row ? mapRow10(row) : null;
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Inserts or replaces an invitation keyed by normalized email.
|
|
2512
|
+
*
|
|
2513
|
+
* The supplied invitation replaces any existing row in full (last write wins),
|
|
2514
|
+
* including `expiresAt` and `consumedAt`.
|
|
2515
|
+
*/
|
|
2516
|
+
async upsert(invitation) {
|
|
2517
|
+
const email = (0, import_protocols5.normalizePlatformInvitationEmail)(invitation.email);
|
|
2518
|
+
this.db.prepare(
|
|
2519
|
+
`INSERT INTO lattice_platform_invitations
|
|
2520
|
+
(email, role, invited_by, created_at, expires_at, consumed_at)
|
|
2521
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
2522
|
+
ON CONFLICT(email) DO UPDATE SET
|
|
2523
|
+
role = excluded.role,
|
|
2524
|
+
invited_by = excluded.invited_by,
|
|
2525
|
+
created_at = excluded.created_at,
|
|
2526
|
+
expires_at = excluded.expires_at,
|
|
2527
|
+
consumed_at = excluded.consumed_at`
|
|
2528
|
+
).run(
|
|
2529
|
+
email,
|
|
2530
|
+
invitation.role,
|
|
2531
|
+
invitation.invitedBy ?? null,
|
|
2532
|
+
invitation.createdAt.toISOString(),
|
|
2533
|
+
invitation.expiresAt?.toISOString() ?? null,
|
|
2534
|
+
invitation.consumedAt?.toISOString() ?? null
|
|
2535
|
+
);
|
|
2536
|
+
const stored = await this.get(email);
|
|
2537
|
+
if (!stored) {
|
|
2538
|
+
throw new Error(`Platform invitation "${email}" was not persisted`);
|
|
2539
|
+
}
|
|
2540
|
+
return stored;
|
|
2541
|
+
}
|
|
2542
|
+
/** Deletes an invitation. Returns whether a row was removed. */
|
|
2543
|
+
async delete(email) {
|
|
2544
|
+
const result = this.db.prepare(`DELETE FROM lattice_platform_invitations WHERE email = ?`).run((0, import_protocols5.normalizePlatformInvitationEmail)(email));
|
|
2545
|
+
return result.changes > 0;
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* Atomically consumes a pending, unexpired invitation.
|
|
2549
|
+
*
|
|
2550
|
+
* Returns the consumed invitation, or null when the row is missing, already
|
|
2551
|
+
* consumed, or expired.
|
|
2552
|
+
*/
|
|
2553
|
+
async consume(email, at) {
|
|
2554
|
+
const normalized = (0, import_protocols5.normalizePlatformInvitationEmail)(email);
|
|
2555
|
+
const timestamp2 = at.toISOString();
|
|
2556
|
+
const result = this.db.prepare(
|
|
2557
|
+
`UPDATE lattice_platform_invitations
|
|
2558
|
+
SET consumed_at = ?
|
|
2559
|
+
WHERE email = ?
|
|
2560
|
+
AND consumed_at IS NULL
|
|
2561
|
+
AND (expires_at IS NULL OR expires_at > ?)`
|
|
2562
|
+
).run(timestamp2, normalized, timestamp2);
|
|
2563
|
+
if (result.changes === 0) return null;
|
|
2564
|
+
return this.get(normalized);
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
|
|
2568
|
+
// src/stores/LocalOidcIdentityClaimStore.ts
|
|
2569
|
+
var import_protocols6 = require("@axiom-lattice/protocols");
|
|
2570
|
+
var DDL13 = `
|
|
2571
|
+
CREATE TABLE IF NOT EXISTS lattice_oidc_identity_claims (
|
|
2572
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2573
|
+
provider_id TEXT NOT NULL,
|
|
2574
|
+
issuer TEXT NOT NULL,
|
|
2575
|
+
subject TEXT NOT NULL,
|
|
2576
|
+
email TEXT NOT NULL,
|
|
2577
|
+
name TEXT,
|
|
2578
|
+
picture TEXT,
|
|
2579
|
+
status TEXT NOT NULL,
|
|
2580
|
+
created_at TEXT NOT NULL,
|
|
2581
|
+
updated_at TEXT NOT NULL,
|
|
2582
|
+
expires_at TEXT NOT NULL,
|
|
2583
|
+
reviewed_by TEXT,
|
|
2584
|
+
reviewed_at TEXT,
|
|
2585
|
+
linked_user_id TEXT,
|
|
2586
|
+
source TEXT,
|
|
2587
|
+
invite_link_id TEXT,
|
|
2588
|
+
requested_user_id TEXT,
|
|
2589
|
+
requested_platform_role TEXT,
|
|
2590
|
+
requested_tenant_id TEXT,
|
|
2591
|
+
requested_tenant_role TEXT
|
|
2592
|
+
);
|
|
2593
|
+
CREATE UNIQUE INDEX IF NOT EXISTS lattice_oidc_identity_claims_pending_subject
|
|
2594
|
+
ON lattice_oidc_identity_claims (provider_id, issuer, subject)
|
|
2595
|
+
WHERE status = 'pending';
|
|
2596
|
+
`;
|
|
2597
|
+
function mapRow11(row) {
|
|
2598
|
+
return {
|
|
2599
|
+
id: row.id,
|
|
2600
|
+
providerId: row.provider_id,
|
|
2601
|
+
issuer: row.issuer,
|
|
2602
|
+
subject: row.subject,
|
|
2603
|
+
email: row.email,
|
|
2604
|
+
...row.name !== null ? { name: row.name } : {},
|
|
2605
|
+
...row.picture !== null ? { picture: row.picture } : {},
|
|
2606
|
+
status: row.status,
|
|
2607
|
+
createdAt: parseISO(row.created_at),
|
|
2608
|
+
updatedAt: parseISO(row.updated_at),
|
|
2609
|
+
expiresAt: parseISO(row.expires_at),
|
|
2610
|
+
...row.reviewed_by !== null ? { reviewedBy: row.reviewed_by } : {},
|
|
2611
|
+
...row.reviewed_at !== null ? { reviewedAt: parseISO(row.reviewed_at) } : {},
|
|
2612
|
+
...row.linked_user_id !== null ? { linkedUserId: row.linked_user_id } : {},
|
|
2613
|
+
...row.source !== null ? { source: row.source } : {},
|
|
2614
|
+
...row.invite_link_id !== null ? { inviteLinkId: row.invite_link_id } : {},
|
|
2615
|
+
...row.requested_user_id !== null ? { requestedUserId: row.requested_user_id } : {},
|
|
2616
|
+
...row.requested_platform_role !== null ? { requestedPlatformRole: row.requested_platform_role } : {},
|
|
2617
|
+
...row.requested_tenant_id !== null ? { requestedTenantId: row.requested_tenant_id } : {},
|
|
2618
|
+
...row.requested_tenant_role !== null ? { requestedTenantRole: row.requested_tenant_role } : {}
|
|
2619
|
+
};
|
|
2620
|
+
}
|
|
2621
|
+
var LocalOidcIdentityClaimStore = class {
|
|
2622
|
+
constructor(db) {
|
|
2623
|
+
this.db = db;
|
|
2624
|
+
ensureTable(db, DDL13);
|
|
2625
|
+
this.ensureColumn("lattice_oidc_identity_claims", "source", "source TEXT");
|
|
2626
|
+
this.ensureColumn("lattice_oidc_identity_claims", "invite_link_id", "invite_link_id TEXT");
|
|
2627
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_user_id", "requested_user_id TEXT");
|
|
2628
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_platform_role", "requested_platform_role TEXT");
|
|
2629
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_tenant_id", "requested_tenant_id TEXT");
|
|
2630
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_tenant_role", "requested_tenant_role TEXT");
|
|
2631
|
+
}
|
|
2632
|
+
ensureColumn(table, column, ddl2) {
|
|
2633
|
+
const columns6 = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
2634
|
+
if (!columns6.some((entry) => entry.name === column)) {
|
|
2635
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl2}`);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
async list(status) {
|
|
2639
|
+
const rows2 = status ? this.db.prepare(
|
|
2640
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2641
|
+
WHERE status = ? ORDER BY created_at ASC, id ASC`
|
|
2642
|
+
).all(status) : this.db.prepare(
|
|
2643
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2644
|
+
ORDER BY created_at ASC, id ASC`
|
|
2645
|
+
).all();
|
|
2646
|
+
return rows2.map(mapRow11);
|
|
2647
|
+
}
|
|
2648
|
+
async get(id) {
|
|
2649
|
+
const row = this.db.prepare(`SELECT * FROM lattice_oidc_identity_claims WHERE id = ?`).get(id);
|
|
2650
|
+
return row ? mapRow11(row) : null;
|
|
2651
|
+
}
|
|
2652
|
+
async getPendingBySubject(providerId, issuer, subject, now) {
|
|
2653
|
+
const row = this.db.prepare(
|
|
2654
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2655
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?
|
|
2656
|
+
AND status = 'pending' AND expires_at > ?`
|
|
2657
|
+
).get(providerId, issuer, subject, now.toISOString());
|
|
2658
|
+
return row ? mapRow11(row) : null;
|
|
2659
|
+
}
|
|
2660
|
+
async create(input) {
|
|
2661
|
+
const now = /* @__PURE__ */ new Date();
|
|
2662
|
+
const existing = this.db.prepare(
|
|
2663
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2664
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?
|
|
2665
|
+
AND status = 'pending'`
|
|
2666
|
+
).get(input.providerId, input.issuer, input.subject);
|
|
2667
|
+
if (existing) {
|
|
2668
|
+
if (parseISO(existing.expires_at).getTime() > now.getTime()) {
|
|
2669
|
+
throw new import_protocols6.OidcIdentityClaimConflictError(
|
|
2670
|
+
input.providerId,
|
|
2671
|
+
input.issuer,
|
|
2672
|
+
input.subject
|
|
2673
|
+
);
|
|
2674
|
+
}
|
|
2675
|
+
this.db.prepare(
|
|
2676
|
+
`UPDATE lattice_oidc_identity_claims
|
|
2677
|
+
SET status = 'expired', updated_at = ?
|
|
2678
|
+
WHERE id = ?`
|
|
2679
|
+
).run(nowISO(), existing.id);
|
|
2680
|
+
}
|
|
2681
|
+
const timestamp2 = now.toISOString();
|
|
2682
|
+
try {
|
|
2683
|
+
this.db.prepare(
|
|
2684
|
+
`INSERT INTO lattice_oidc_identity_claims
|
|
2685
|
+
(id, provider_id, issuer, subject, email, name, picture, status,
|
|
2686
|
+
created_at, updated_at, expires_at, reviewed_by, reviewed_at,
|
|
2687
|
+
linked_user_id, source, invite_link_id, requested_user_id,
|
|
2688
|
+
requested_platform_role, requested_tenant_id, requested_tenant_role)
|
|
2689
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, NULL, NULL, NULL,
|
|
2690
|
+
?, ?, ?, ?, ?, ?)`
|
|
2691
|
+
).run(
|
|
2692
|
+
input.id,
|
|
2693
|
+
input.providerId,
|
|
2694
|
+
input.issuer,
|
|
2695
|
+
input.subject,
|
|
2696
|
+
(0, import_protocols6.normalizeOidcIdentityEmail)(input.email),
|
|
2697
|
+
input.name ?? null,
|
|
2698
|
+
input.picture ?? null,
|
|
2699
|
+
timestamp2,
|
|
2700
|
+
timestamp2,
|
|
2701
|
+
input.expiresAt.toISOString(),
|
|
2702
|
+
input.source ?? null,
|
|
2703
|
+
input.inviteLinkId ?? null,
|
|
2704
|
+
input.requestedUserId ?? null,
|
|
2705
|
+
input.requestedPlatformRole ?? null,
|
|
2706
|
+
input.requestedTenantId ?? null,
|
|
2707
|
+
input.requestedTenantRole ?? null
|
|
2708
|
+
);
|
|
2709
|
+
} catch (error) {
|
|
2710
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2711
|
+
if (message.toLowerCase().includes("unique")) {
|
|
2712
|
+
throw new import_protocols6.OidcIdentityClaimConflictError(
|
|
2713
|
+
input.providerId,
|
|
2714
|
+
input.issuer,
|
|
2715
|
+
input.subject
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
throw error;
|
|
2719
|
+
}
|
|
2720
|
+
const stored = await this.get(input.id);
|
|
2721
|
+
if (!stored) throw new Error("OIDC identity claim was not persisted");
|
|
2722
|
+
return stored;
|
|
2723
|
+
}
|
|
2724
|
+
async updatePending(id, updates, now) {
|
|
2725
|
+
const sets = [];
|
|
2726
|
+
const params = [];
|
|
2727
|
+
if (updates.email !== void 0) {
|
|
2728
|
+
sets.push("email = ?");
|
|
2729
|
+
params.push((0, import_protocols6.normalizeOidcIdentityEmail)(updates.email));
|
|
2730
|
+
}
|
|
2731
|
+
if (updates.name !== void 0) {
|
|
2732
|
+
sets.push("name = ?");
|
|
2733
|
+
params.push(updates.name);
|
|
2734
|
+
}
|
|
2735
|
+
if (updates.picture !== void 0) {
|
|
2736
|
+
sets.push("picture = ?");
|
|
2737
|
+
params.push(updates.picture);
|
|
2738
|
+
}
|
|
2739
|
+
if (sets.length === 0) return this.get(id);
|
|
2740
|
+
sets.push("updated_at = ?");
|
|
2741
|
+
params.push(now.toISOString(), id);
|
|
2742
|
+
const result = this.db.prepare(
|
|
2743
|
+
`UPDATE lattice_oidc_identity_claims SET ${sets.join(", ")}
|
|
2744
|
+
WHERE id = ? AND status = 'pending'`
|
|
2745
|
+
).run(...params);
|
|
2746
|
+
return result.changes > 0 ? this.get(id) : null;
|
|
2747
|
+
}
|
|
2748
|
+
async approve(id, approval, now) {
|
|
2749
|
+
const result = this.db.prepare(
|
|
2750
|
+
`UPDATE lattice_oidc_identity_claims
|
|
2751
|
+
SET status = 'approved', reviewed_by = ?, reviewed_at = ?,
|
|
2752
|
+
linked_user_id = ?, updated_at = ?
|
|
2753
|
+
WHERE id = ? AND status = 'pending'`
|
|
2754
|
+
).run(
|
|
2755
|
+
approval.reviewedBy,
|
|
2756
|
+
now.toISOString(),
|
|
2757
|
+
approval.linkedUserId,
|
|
2758
|
+
now.toISOString(),
|
|
2759
|
+
id
|
|
2760
|
+
);
|
|
2761
|
+
return result.changes > 0 ? this.get(id) : null;
|
|
2762
|
+
}
|
|
2763
|
+
async reject(id, reviewedBy, now) {
|
|
2764
|
+
const result = this.db.prepare(
|
|
2765
|
+
`UPDATE lattice_oidc_identity_claims
|
|
2766
|
+
SET status = 'rejected', reviewed_by = ?, reviewed_at = ?, updated_at = ?
|
|
2767
|
+
WHERE id = ? AND status = 'pending'`
|
|
2768
|
+
).run(reviewedBy, now.toISOString(), now.toISOString(), id);
|
|
2769
|
+
return result.changes > 0 ? this.get(id) : null;
|
|
2770
|
+
}
|
|
2771
|
+
async delete(id) {
|
|
2772
|
+
const result = this.db.prepare(`DELETE FROM lattice_oidc_identity_claims WHERE id = ?`).run(id);
|
|
2773
|
+
return result.changes > 0;
|
|
2774
|
+
}
|
|
2775
|
+
};
|
|
2776
|
+
|
|
2777
|
+
// src/stores/LocalInviteLinkStore.ts
|
|
2778
|
+
var import_core2 = require("@axiom-lattice/core");
|
|
2779
|
+
var import_protocols7 = require("@axiom-lattice/protocols");
|
|
2780
|
+
var DDL14 = `
|
|
2781
|
+
CREATE TABLE IF NOT EXISTS lattice_invite_links (
|
|
2782
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2783
|
+
scope TEXT NOT NULL,
|
|
2784
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
2785
|
+
token_encrypted TEXT NOT NULL,
|
|
2786
|
+
email TEXT,
|
|
2787
|
+
platform_role TEXT,
|
|
2788
|
+
tenant_id TEXT,
|
|
2789
|
+
tenant_role TEXT,
|
|
2790
|
+
created_by TEXT,
|
|
2791
|
+
created_at TEXT NOT NULL,
|
|
2792
|
+
updated_at TEXT NOT NULL,
|
|
2793
|
+
expires_at TEXT NOT NULL,
|
|
2794
|
+
max_uses INTEGER NOT NULL,
|
|
2795
|
+
used_count INTEGER NOT NULL,
|
|
2796
|
+
revoked_at TEXT
|
|
2797
|
+
);
|
|
2798
|
+
CREATE UNIQUE INDEX IF NOT EXISTS lattice_invite_links_token_hash
|
|
2799
|
+
ON lattice_invite_links (token_hash);
|
|
2800
|
+
`;
|
|
2801
|
+
function mapRow12(row) {
|
|
2802
|
+
return {
|
|
2803
|
+
id: row.id,
|
|
2804
|
+
scope: row.scope,
|
|
2805
|
+
token: (0, import_core2.safeDecrypt)(
|
|
2806
|
+
row.token_encrypted,
|
|
2807
|
+
`Invite link "${row.id}" token`
|
|
2808
|
+
),
|
|
2809
|
+
tokenHash: row.token_hash,
|
|
2810
|
+
...row.email !== null ? { email: row.email } : {},
|
|
2811
|
+
...row.platform_role !== null ? { platformRole: row.platform_role } : {},
|
|
2812
|
+
...row.tenant_id !== null ? { tenantId: row.tenant_id } : {},
|
|
2813
|
+
...row.tenant_role !== null ? { tenantRole: row.tenant_role } : {},
|
|
2814
|
+
...row.created_by !== null ? { createdBy: row.created_by } : {},
|
|
2815
|
+
createdAt: parseISO(row.created_at),
|
|
2816
|
+
updatedAt: parseISO(row.updated_at),
|
|
2817
|
+
expiresAt: parseISO(row.expires_at),
|
|
2818
|
+
maxUses: Number(row.max_uses),
|
|
2819
|
+
usedCount: Number(row.used_count),
|
|
2820
|
+
...row.revoked_at !== null ? { revokedAt: parseISO(row.revoked_at) } : {}
|
|
2821
|
+
};
|
|
2822
|
+
}
|
|
2823
|
+
var LocalInviteLinkStore = class {
|
|
2824
|
+
constructor(db) {
|
|
2825
|
+
this.db = db;
|
|
2826
|
+
ensureTable(db, DDL14);
|
|
2827
|
+
}
|
|
2828
|
+
async list() {
|
|
2829
|
+
const rows2 = this.db.prepare(
|
|
2830
|
+
`SELECT * FROM lattice_invite_links
|
|
2831
|
+
ORDER BY created_at DESC, id DESC`
|
|
2832
|
+
).all();
|
|
2833
|
+
return rows2.map(mapRow12);
|
|
2834
|
+
}
|
|
2835
|
+
async get(id) {
|
|
2836
|
+
const row = this.db.prepare(`SELECT * FROM lattice_invite_links WHERE id = ?`).get(id);
|
|
2837
|
+
return row ? mapRow12(row) : null;
|
|
2838
|
+
}
|
|
2839
|
+
async getByTokenHash(tokenHash) {
|
|
2840
|
+
const row = this.db.prepare(`SELECT * FROM lattice_invite_links WHERE token_hash = ?`).get(tokenHash);
|
|
2841
|
+
return row ? mapRow12(row) : null;
|
|
2842
|
+
}
|
|
2843
|
+
async create(input) {
|
|
2844
|
+
const now = nowISO();
|
|
2845
|
+
this.db.prepare(
|
|
2846
|
+
`INSERT INTO lattice_invite_links
|
|
2847
|
+
(id, scope, token_hash, token_encrypted, email, platform_role,
|
|
2848
|
+
tenant_id, tenant_role, created_by, created_at, updated_at,
|
|
2849
|
+
expires_at, max_uses, used_count, revoked_at)
|
|
2850
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, NULL)`
|
|
2851
|
+
).run(
|
|
2852
|
+
input.id,
|
|
2853
|
+
input.scope,
|
|
2854
|
+
input.tokenHash,
|
|
2855
|
+
(0, import_core2.encrypt)(input.token),
|
|
2856
|
+
input.email ? (0, import_protocols7.normalizeInviteLinkEmail)(input.email) : null,
|
|
2857
|
+
input.platformRole ?? null,
|
|
2858
|
+
input.tenantId ?? null,
|
|
2859
|
+
input.tenantRole ?? null,
|
|
2860
|
+
input.createdBy ?? null,
|
|
2861
|
+
now,
|
|
2862
|
+
now,
|
|
2863
|
+
input.expiresAt.toISOString(),
|
|
2864
|
+
input.maxUses
|
|
2865
|
+
);
|
|
2866
|
+
const stored = await this.get(input.id);
|
|
2867
|
+
if (!stored) throw new Error("Invite link was not persisted");
|
|
2868
|
+
return stored;
|
|
2869
|
+
}
|
|
2870
|
+
async consume(tokenHash, now) {
|
|
2871
|
+
const result = this.db.prepare(
|
|
2872
|
+
`UPDATE lattice_invite_links
|
|
2873
|
+
SET used_count = used_count + 1, updated_at = ?
|
|
2874
|
+
WHERE token_hash = ?
|
|
2875
|
+
AND revoked_at IS NULL
|
|
2876
|
+
AND expires_at > ?
|
|
2877
|
+
AND used_count < max_uses`
|
|
2878
|
+
).run(now.toISOString(), tokenHash, now.toISOString());
|
|
2879
|
+
return result.changes > 0 ? this.getByTokenHash(tokenHash) : null;
|
|
2880
|
+
}
|
|
2881
|
+
async revoke(id, now) {
|
|
2882
|
+
const result = this.db.prepare(
|
|
2883
|
+
`UPDATE lattice_invite_links
|
|
2884
|
+
SET revoked_at = ?, updated_at = ?
|
|
2885
|
+
WHERE id = ? AND revoked_at IS NULL`
|
|
2886
|
+
).run(now.toISOString(), now.toISOString(), id);
|
|
2887
|
+
return result.changes > 0 ? this.get(id) : this.get(id);
|
|
2888
|
+
}
|
|
2889
|
+
};
|
|
2890
|
+
|
|
2891
|
+
// src/stores/LocalPlatformSettingsStore.ts
|
|
2892
|
+
var import_protocols8 = require("@axiom-lattice/protocols");
|
|
2893
|
+
var SETTINGS_ID = "default";
|
|
2894
|
+
var COLUMNS = "id, document, version, updated_by, updated_at";
|
|
2895
|
+
function normalizeUpdatedBy(updatedBy) {
|
|
2896
|
+
const trimmed = updatedBy?.trim();
|
|
2897
|
+
return trimmed ? trimmed : null;
|
|
2898
|
+
}
|
|
2899
|
+
var DDL15 = `
|
|
2900
|
+
CREATE TABLE IF NOT EXISTS lattice_platform_settings (
|
|
2901
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2902
|
+
document TEXT NOT NULL,
|
|
2903
|
+
version INTEGER NOT NULL,
|
|
2904
|
+
updated_by TEXT,
|
|
2905
|
+
updated_at TEXT NOT NULL
|
|
2906
|
+
);
|
|
2907
|
+
`;
|
|
2908
|
+
function mapRow13(row) {
|
|
2909
|
+
const document = JSON.parse(row.document);
|
|
2910
|
+
return {
|
|
2911
|
+
...document,
|
|
2912
|
+
version: Number(row.version),
|
|
2913
|
+
...row.updated_by !== null ? { updatedBy: row.updated_by } : {},
|
|
2914
|
+
updatedAt: parseISO(row.updated_at)
|
|
2915
|
+
};
|
|
2916
|
+
}
|
|
2917
|
+
var LocalPlatformSettingsStore = class {
|
|
2918
|
+
constructor(db) {
|
|
2919
|
+
this.db = db;
|
|
2920
|
+
ensureTable(db, DDL15);
|
|
2921
|
+
}
|
|
2922
|
+
async get() {
|
|
2923
|
+
const row = this.db.prepare(
|
|
2924
|
+
`SELECT ${COLUMNS} FROM lattice_platform_settings WHERE id = ?`
|
|
2925
|
+
).get(SETTINGS_ID);
|
|
2926
|
+
return row ? mapRow13(row) : null;
|
|
2927
|
+
}
|
|
2928
|
+
async save(document, expectedVersion, updatedBy) {
|
|
2929
|
+
const version = expectedVersion + 1;
|
|
2930
|
+
const updatedAt = nowISO();
|
|
2931
|
+
const result = expectedVersion === 0 ? this.db.prepare(
|
|
2932
|
+
`INSERT INTO lattice_platform_settings
|
|
2933
|
+
(id, document, version, updated_by, updated_at)
|
|
2934
|
+
VALUES (?, ?, ?, ?, ?)
|
|
2935
|
+
ON CONFLICT (id) DO NOTHING`
|
|
2936
|
+
).run(
|
|
2937
|
+
SETTINGS_ID,
|
|
2938
|
+
JSON.stringify(document),
|
|
2939
|
+
version,
|
|
2940
|
+
normalizeUpdatedBy(updatedBy),
|
|
2941
|
+
updatedAt
|
|
2942
|
+
) : this.db.prepare(
|
|
2943
|
+
`UPDATE lattice_platform_settings
|
|
2944
|
+
SET document = ?, version = ?, updated_by = ?, updated_at = ?
|
|
2945
|
+
WHERE id = ? AND version = ?`
|
|
2946
|
+
).run(
|
|
2947
|
+
JSON.stringify(document),
|
|
2948
|
+
version,
|
|
2949
|
+
normalizeUpdatedBy(updatedBy),
|
|
2950
|
+
updatedAt,
|
|
2951
|
+
SETTINGS_ID,
|
|
2952
|
+
expectedVersion
|
|
2953
|
+
);
|
|
2954
|
+
if (result.changes === 0) {
|
|
2955
|
+
const actual = this.db.prepare(`SELECT version FROM lattice_platform_settings WHERE id = ?`).get(SETTINGS_ID);
|
|
2956
|
+
throw new import_protocols8.PlatformSettingsVersionConflictError(
|
|
2957
|
+
expectedVersion,
|
|
2958
|
+
actual ? Number(actual.version) : 0
|
|
2959
|
+
);
|
|
2960
|
+
}
|
|
2961
|
+
const stored = await this.get();
|
|
2962
|
+
if (!stored) throw new Error("Platform settings were not persisted");
|
|
2963
|
+
return stored;
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
|
|
2967
|
+
// src/stores/LocalDatabaseConfigStore.ts
|
|
2968
|
+
var import_core3 = require("@axiom-lattice/core");
|
|
2969
|
+
var DDL16 = `
|
|
2122
2970
|
CREATE TABLE IF NOT EXISTS lt_database_configs (
|
|
2123
2971
|
id TEXT NOT NULL,
|
|
2124
2972
|
tenant_id TEXT NOT NULL,
|
|
@@ -2135,7 +2983,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_dbconfig_key ON lt_database_configs(ten
|
|
|
2135
2983
|
var LocalDatabaseConfigStore = class {
|
|
2136
2984
|
constructor(db) {
|
|
2137
2985
|
this.db = db;
|
|
2138
|
-
ensureTable(db,
|
|
2986
|
+
ensureTable(db, DDL16);
|
|
2139
2987
|
}
|
|
2140
2988
|
async getAllConfigs(tenantId) {
|
|
2141
2989
|
const rows2 = this.db.prepare(
|
|
@@ -2233,7 +3081,7 @@ function mapRowToEntry(row) {
|
|
|
2233
3081
|
const config = JSON.parse(row.config);
|
|
2234
3082
|
if (config.password) {
|
|
2235
3083
|
try {
|
|
2236
|
-
config.password = (0,
|
|
3084
|
+
config.password = (0, import_core3.decrypt)(config.password);
|
|
2237
3085
|
} catch {
|
|
2238
3086
|
}
|
|
2239
3087
|
}
|
|
@@ -2250,15 +3098,15 @@ function mapRowToEntry(row) {
|
|
|
2250
3098
|
}
|
|
2251
3099
|
function encryptPasswordInConfig(config) {
|
|
2252
3100
|
if (config.password) {
|
|
2253
|
-
return { ...config, password: (0,
|
|
3101
|
+
return { ...config, password: (0, import_core3.encrypt)(config.password) };
|
|
2254
3102
|
}
|
|
2255
3103
|
return config;
|
|
2256
3104
|
}
|
|
2257
3105
|
|
|
2258
3106
|
// src/stores/LocalConnectionStore.ts
|
|
2259
3107
|
var import_uuid = require("uuid");
|
|
2260
|
-
var
|
|
2261
|
-
var
|
|
3108
|
+
var import_core4 = require("@axiom-lattice/core");
|
|
3109
|
+
var DDL17 = `
|
|
2262
3110
|
CREATE TABLE IF NOT EXISTS connection_configs (
|
|
2263
3111
|
id TEXT NOT NULL,
|
|
2264
3112
|
tenant_id TEXT NOT NULL,
|
|
@@ -2289,7 +3137,7 @@ function parseSecretFields(raw) {
|
|
|
2289
3137
|
var LocalConnectionStore = class {
|
|
2290
3138
|
constructor(db) {
|
|
2291
3139
|
this.db = db;
|
|
2292
|
-
ensureTable(db,
|
|
3140
|
+
ensureTable(db, DDL17);
|
|
2293
3141
|
this.ensureColumn("connection_configs", "secret_fields", "secret_fields TEXT");
|
|
2294
3142
|
this.reencryptLegacySecrets();
|
|
2295
3143
|
}
|
|
@@ -2325,8 +3173,8 @@ var LocalConnectionStore = class {
|
|
|
2325
3173
|
let changed = false;
|
|
2326
3174
|
for (const field of secretFields) {
|
|
2327
3175
|
const value = config[field];
|
|
2328
|
-
if (typeof value === "string" && value.length > 0 && !(0,
|
|
2329
|
-
config[field] = (0,
|
|
3176
|
+
if (typeof value === "string" && value.length > 0 && !(0, import_core4.isEncryptedValue)(value)) {
|
|
3177
|
+
config[field] = (0, import_core4.encrypt)(value);
|
|
2330
3178
|
changed = true;
|
|
2331
3179
|
}
|
|
2332
3180
|
}
|
|
@@ -2369,7 +3217,7 @@ var LocalConnectionStore = class {
|
|
|
2369
3217
|
entry.key,
|
|
2370
3218
|
entry.name,
|
|
2371
3219
|
entry.description || null,
|
|
2372
|
-
JSON.stringify((0,
|
|
3220
|
+
JSON.stringify((0, import_core4.encryptConfigFields)(entry.config, secretFields)),
|
|
2373
3221
|
secretFields ? JSON.stringify(secretFields) : null,
|
|
2374
3222
|
now,
|
|
2375
3223
|
now
|
|
@@ -2392,7 +3240,7 @@ var LocalConnectionStore = class {
|
|
|
2392
3240
|
if (updates.config !== void 0) {
|
|
2393
3241
|
const secretFields = updates.secretFields?.length ? updates.secretFields : existing.secretFields?.length ? existing.secretFields : void 0;
|
|
2394
3242
|
setClauses.push("config = ?");
|
|
2395
|
-
values.push(JSON.stringify((0,
|
|
3243
|
+
values.push(JSON.stringify((0, import_core4.encryptConfigFields)(updates.config, secretFields)));
|
|
2396
3244
|
setClauses.push("secret_fields = ?");
|
|
2397
3245
|
values.push(secretFields ? JSON.stringify(secretFields) : null);
|
|
2398
3246
|
}
|
|
@@ -2422,7 +3270,7 @@ var LocalConnectionStore = class {
|
|
|
2422
3270
|
key: row.key,
|
|
2423
3271
|
name: row.name,
|
|
2424
3272
|
description: row.description || void 0,
|
|
2425
|
-
config: (0,
|
|
3273
|
+
config: (0, import_core4.decryptConfigFields)(storedConfig, secretFields),
|
|
2426
3274
|
secretFields,
|
|
2427
3275
|
createdAt: row.created_at,
|
|
2428
3276
|
updatedAt: row.updated_at
|
|
@@ -2431,8 +3279,8 @@ var LocalConnectionStore = class {
|
|
|
2431
3279
|
};
|
|
2432
3280
|
|
|
2433
3281
|
// src/stores/LocalMetricsServerConfigStore.ts
|
|
2434
|
-
var
|
|
2435
|
-
var
|
|
3282
|
+
var import_core5 = require("@axiom-lattice/core");
|
|
3283
|
+
var DDL18 = `
|
|
2436
3284
|
CREATE TABLE IF NOT EXISTS lt_metrics_configs (
|
|
2437
3285
|
id TEXT NOT NULL,
|
|
2438
3286
|
tenant_id TEXT NOT NULL,
|
|
@@ -2449,7 +3297,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_metrics_key ON lt_metrics_configs(tenan
|
|
|
2449
3297
|
var LocalMetricsServerConfigStore = class {
|
|
2450
3298
|
constructor(db) {
|
|
2451
3299
|
this.db = db;
|
|
2452
|
-
ensureTable(db,
|
|
3300
|
+
ensureTable(db, DDL18);
|
|
2453
3301
|
}
|
|
2454
3302
|
async getAllConfigs(tenantId) {
|
|
2455
3303
|
const rows2 = this.db.prepare(
|
|
@@ -2556,23 +3404,23 @@ function mapRowToEntry2(row) {
|
|
|
2556
3404
|
}
|
|
2557
3405
|
function encryptSecretsInConfig(config) {
|
|
2558
3406
|
const configCopy = { ...config };
|
|
2559
|
-
if (configCopy.apiKey) configCopy.apiKey = (0,
|
|
2560
|
-
if (configCopy.password) configCopy.password = (0,
|
|
3407
|
+
if (configCopy.apiKey) configCopy.apiKey = (0, import_core5.encrypt)(configCopy.apiKey);
|
|
3408
|
+
if (configCopy.password) configCopy.password = (0, import_core5.encrypt)(configCopy.password);
|
|
2561
3409
|
return configCopy;
|
|
2562
3410
|
}
|
|
2563
3411
|
function decryptSecretsInConfig(config) {
|
|
2564
|
-
if (config.apiKey && (0,
|
|
2565
|
-
config.apiKey = (0,
|
|
3412
|
+
if (config.apiKey && (0, import_core5.isEncryptedValue)(config.apiKey)) {
|
|
3413
|
+
config.apiKey = (0, import_core5.safeDecrypt)(config.apiKey);
|
|
2566
3414
|
}
|
|
2567
|
-
if (config.password && (0,
|
|
2568
|
-
config.password = (0,
|
|
3415
|
+
if (config.password && (0, import_core5.isEncryptedValue)(config.password)) {
|
|
3416
|
+
config.password = (0, import_core5.safeDecrypt)(config.password);
|
|
2569
3417
|
}
|
|
2570
3418
|
return config;
|
|
2571
3419
|
}
|
|
2572
3420
|
|
|
2573
3421
|
// src/stores/LocalMcpServerConfigStore.ts
|
|
2574
|
-
var
|
|
2575
|
-
var
|
|
3422
|
+
var import_core6 = require("@axiom-lattice/core");
|
|
3423
|
+
var DDL19 = `
|
|
2576
3424
|
CREATE TABLE IF NOT EXISTS lt_mcp_configs (
|
|
2577
3425
|
id TEXT NOT NULL,
|
|
2578
3426
|
tenant_id TEXT NOT NULL,
|
|
@@ -2592,7 +3440,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_mcp_key ON lt_mcp_configs(tenant_id, ke
|
|
|
2592
3440
|
var LocalMcpServerConfigStore = class {
|
|
2593
3441
|
constructor(db) {
|
|
2594
3442
|
this.db = db;
|
|
2595
|
-
ensureTable(db,
|
|
3443
|
+
ensureTable(db, DDL19);
|
|
2596
3444
|
}
|
|
2597
3445
|
async getAllConfigs(tenantId) {
|
|
2598
3446
|
const rows2 = this.db.prepare(
|
|
@@ -2720,14 +3568,14 @@ function mapRowToEntry3(row) {
|
|
|
2720
3568
|
if (config.env && row.is_env_encrypted) {
|
|
2721
3569
|
const decryptedEnv = {};
|
|
2722
3570
|
for (const [key, value] of Object.entries(config.env)) {
|
|
2723
|
-
decryptedEnv[key] = (0,
|
|
3571
|
+
decryptedEnv[key] = (0, import_core6.safeDecrypt)(value);
|
|
2724
3572
|
}
|
|
2725
3573
|
config.env = decryptedEnv;
|
|
2726
3574
|
}
|
|
2727
3575
|
if (config.headers && row.is_env_encrypted) {
|
|
2728
3576
|
const decryptedHeaders = {};
|
|
2729
3577
|
for (const [key, value] of Object.entries(config.headers)) {
|
|
2730
|
-
decryptedHeaders[key] = (0,
|
|
3578
|
+
decryptedHeaders[key] = (0, import_core6.safeDecrypt)(value);
|
|
2731
3579
|
}
|
|
2732
3580
|
config.headers = decryptedHeaders;
|
|
2733
3581
|
}
|
|
@@ -2751,7 +3599,7 @@ function encryptEnvInConfig(config) {
|
|
|
2751
3599
|
if (configCopy.env && Object.keys(configCopy.env).length > 0) {
|
|
2752
3600
|
const encryptedEnv = {};
|
|
2753
3601
|
for (const [key, value] of Object.entries(configCopy.env)) {
|
|
2754
|
-
encryptedEnv[key] = (0,
|
|
3602
|
+
encryptedEnv[key] = (0, import_core6.encrypt)(value);
|
|
2755
3603
|
}
|
|
2756
3604
|
configCopy.env = encryptedEnv;
|
|
2757
3605
|
isEnvEncrypted = true;
|
|
@@ -2759,7 +3607,7 @@ function encryptEnvInConfig(config) {
|
|
|
2759
3607
|
if (configCopy.headers && Object.keys(configCopy.headers).length > 0) {
|
|
2760
3608
|
const encryptedHeaders = {};
|
|
2761
3609
|
for (const [key, value] of Object.entries(configCopy.headers)) {
|
|
2762
|
-
encryptedHeaders[key] = (0,
|
|
3610
|
+
encryptedHeaders[key] = (0, import_core6.encrypt)(value);
|
|
2763
3611
|
}
|
|
2764
3612
|
configCopy.headers = encryptedHeaders;
|
|
2765
3613
|
isEnvEncrypted = true;
|
|
@@ -2768,8 +3616,8 @@ function encryptEnvInConfig(config) {
|
|
|
2768
3616
|
}
|
|
2769
3617
|
|
|
2770
3618
|
// src/stores/LocalModelProviderStore.ts
|
|
2771
|
-
var
|
|
2772
|
-
var
|
|
3619
|
+
var import_core7 = require("@axiom-lattice/core");
|
|
3620
|
+
var DDL20 = `
|
|
2773
3621
|
CREATE TABLE IF NOT EXISTS lt_model_providers (
|
|
2774
3622
|
id TEXT NOT NULL,
|
|
2775
3623
|
tenant_id TEXT NOT NULL,
|
|
@@ -2814,7 +3662,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
|
|
|
2814
3662
|
var LocalModelProviderStore = class {
|
|
2815
3663
|
constructor(db) {
|
|
2816
3664
|
this.db = db;
|
|
2817
|
-
ensureTable(db,
|
|
3665
|
+
ensureTable(db, DDL20);
|
|
2818
3666
|
this.ensureColumn(
|
|
2819
3667
|
"lt_model_providers",
|
|
2820
3668
|
"api_style",
|
|
@@ -2884,7 +3732,7 @@ var LocalModelProviderStore = class {
|
|
|
2884
3732
|
// Phase 1 pins the LLM provider (ADR-138 decision 7b)
|
|
2885
3733
|
"openai",
|
|
2886
3734
|
data.baseURL,
|
|
2887
|
-
data.apiKey ? (0,
|
|
3735
|
+
data.apiKey ? (0, import_core7.encrypt)(data.apiKey) : null,
|
|
2888
3736
|
data.apiKey ? data.apiKey.slice(-4) : null,
|
|
2889
3737
|
data.enabled === false ? 0 : 1,
|
|
2890
3738
|
now,
|
|
@@ -2919,7 +3767,7 @@ var LocalModelProviderStore = class {
|
|
|
2919
3767
|
set("api_key_enc", null);
|
|
2920
3768
|
set("api_key_hint", null);
|
|
2921
3769
|
} else if (updates.apiKey) {
|
|
2922
|
-
set("api_key_enc", (0,
|
|
3770
|
+
set("api_key_enc", (0, import_core7.encrypt)(updates.apiKey));
|
|
2923
3771
|
set("api_key_hint", updates.apiKey.slice(-4));
|
|
2924
3772
|
}
|
|
2925
3773
|
if (fields.length === 0) {
|
|
@@ -3054,7 +3902,7 @@ var LocalModelProviderStore = class {
|
|
|
3054
3902
|
function mapRowToEntry4(row) {
|
|
3055
3903
|
let apiKey;
|
|
3056
3904
|
if (row.api_key_enc) {
|
|
3057
|
-
apiKey = (0,
|
|
3905
|
+
apiKey = (0, import_core7.safeDecrypt)(row.api_key_enc);
|
|
3058
3906
|
}
|
|
3059
3907
|
return {
|
|
3060
3908
|
id: row.id,
|
|
@@ -3094,7 +3942,7 @@ function mapRowToModel(row) {
|
|
|
3094
3942
|
|
|
3095
3943
|
// src/stores/LocalWorkflowTrackingStore.ts
|
|
3096
3944
|
var import_node_crypto = require("crypto");
|
|
3097
|
-
var
|
|
3945
|
+
var DDL21 = `
|
|
3098
3946
|
CREATE TABLE IF NOT EXISTS lt_workflow_runs (
|
|
3099
3947
|
id TEXT PRIMARY KEY,
|
|
3100
3948
|
tenant_id TEXT NOT NULL,
|
|
@@ -3141,7 +3989,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_ws_type ON lt_workflow_steps(run_id, step_type
|
|
|
3141
3989
|
var LocalWorkflowTrackingStore = class {
|
|
3142
3990
|
constructor(db) {
|
|
3143
3991
|
this.db = db;
|
|
3144
|
-
ensureTable(db,
|
|
3992
|
+
ensureTable(db, DDL21);
|
|
3145
3993
|
this.ensureColumn("lt_workflow_steps", "thread_id", "thread_id TEXT");
|
|
3146
3994
|
}
|
|
3147
3995
|
/** Add a column if it does not exist (SQLite version compatible). */
|
|
@@ -3440,7 +4288,7 @@ function mapRowToStep(row) {
|
|
|
3440
4288
|
|
|
3441
4289
|
// src/stores/LocalEvalStore.ts
|
|
3442
4290
|
var import_crypto = require("crypto");
|
|
3443
|
-
var
|
|
4291
|
+
var DDL22 = `
|
|
3444
4292
|
CREATE TABLE IF NOT EXISTS lt_eval_projects (
|
|
3445
4293
|
id TEXT NOT NULL,
|
|
3446
4294
|
tenant_id TEXT NOT NULL,
|
|
@@ -3551,7 +4399,7 @@ function parseOptionalJson(val) {
|
|
|
3551
4399
|
var LocalEvalStore = class {
|
|
3552
4400
|
constructor(db) {
|
|
3553
4401
|
this.db = db;
|
|
3554
|
-
ensureTable(db,
|
|
4402
|
+
ensureTable(db, DDL22);
|
|
3555
4403
|
this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
|
|
3556
4404
|
this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
|
|
3557
4405
|
this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
|
|
@@ -4144,11 +4992,11 @@ var LocalEvalStore = class {
|
|
|
4144
4992
|
};
|
|
4145
4993
|
|
|
4146
4994
|
// src/stores/LocalChannelBindingStore.ts
|
|
4147
|
-
var
|
|
4995
|
+
var import_protocols10 = require("@axiom-lattice/protocols");
|
|
4148
4996
|
var import_crypto2 = require("crypto");
|
|
4149
4997
|
|
|
4150
4998
|
// src/stores/room-channel-binding-index.ts
|
|
4151
|
-
var
|
|
4999
|
+
var import_protocols9 = require("@axiom-lattice/protocols");
|
|
4152
5000
|
var UNIQUE_INDEX_SQL = `CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_cb_subject_unique
|
|
4153
5001
|
ON lt_channel_bindings(channel, channel_installation_id, tenant_id, sender_id)`;
|
|
4154
5002
|
var LOOKUP_INDEX_SQL = `CREATE INDEX IF NOT EXISTS idx_lt_cb_resolve
|
|
@@ -4162,7 +5010,7 @@ function ensureChannelBindingSubjectIndex(db) {
|
|
|
4162
5010
|
HAVING COUNT(*) > 1
|
|
4163
5011
|
ORDER BY tenant_id, channel, channel_installation_id, sender_id`).all();
|
|
4164
5012
|
if (conflicts.length > 0) {
|
|
4165
|
-
throw new
|
|
5013
|
+
throw new import_protocols9.ChannelBindingMigrationConflictError(conflicts.map(mapConflict));
|
|
4166
5014
|
}
|
|
4167
5015
|
db.exec("DROP INDEX IF EXISTS idx_lt_cb_room_subject");
|
|
4168
5016
|
db.exec(UNIQUE_INDEX_SQL);
|
|
@@ -4188,7 +5036,7 @@ function mapConflict(row) {
|
|
|
4188
5036
|
}
|
|
4189
5037
|
|
|
4190
5038
|
// src/stores/LocalChannelBindingStore.ts
|
|
4191
|
-
var
|
|
5039
|
+
var DDL23 = `
|
|
4192
5040
|
CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
4193
5041
|
id TEXT PRIMARY KEY,
|
|
4194
5042
|
channel TEXT NOT NULL,
|
|
@@ -4210,7 +5058,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
|
4210
5058
|
var LocalChannelBindingStore = class {
|
|
4211
5059
|
constructor(db) {
|
|
4212
5060
|
this.db = db;
|
|
4213
|
-
ensureTable(db,
|
|
5061
|
+
ensureTable(db, DDL23);
|
|
4214
5062
|
ensureChannelBindingSubjectIndex(db);
|
|
4215
5063
|
}
|
|
4216
5064
|
async findById(tenantId, id) {
|
|
@@ -4260,7 +5108,7 @@ var LocalChannelBindingStore = class {
|
|
|
4260
5108
|
);
|
|
4261
5109
|
} catch (error) {
|
|
4262
5110
|
if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
|
|
4263
|
-
throw new
|
|
5111
|
+
throw new import_protocols10.DuplicateChannelBindingSubjectError();
|
|
4264
5112
|
}
|
|
4265
5113
|
throw error;
|
|
4266
5114
|
}
|
|
@@ -4390,7 +5238,7 @@ function mapRowToBinding(row) {
|
|
|
4390
5238
|
}
|
|
4391
5239
|
|
|
4392
5240
|
// src/stores/LocalChannelInstallationStore.ts
|
|
4393
|
-
var
|
|
5241
|
+
var DDL24 = `
|
|
4394
5242
|
CREATE TABLE IF NOT EXISTS lt_channel_installations (
|
|
4395
5243
|
id TEXT PRIMARY KEY,
|
|
4396
5244
|
tenant_id TEXT NOT NULL,
|
|
@@ -4408,13 +5256,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
|
|
|
4408
5256
|
var LocalChannelInstallationStore = class {
|
|
4409
5257
|
constructor(db) {
|
|
4410
5258
|
this.db = db;
|
|
4411
|
-
ensureTable(db,
|
|
5259
|
+
ensureTable(db, DDL24);
|
|
4412
5260
|
}
|
|
4413
5261
|
async getInstallationById(installationId) {
|
|
4414
5262
|
const row = this.db.prepare(
|
|
4415
5263
|
`SELECT * FROM lt_channel_installations WHERE id = ?`
|
|
4416
5264
|
).get(installationId);
|
|
4417
|
-
return row ?
|
|
5265
|
+
return row ? mapRow14(row) : null;
|
|
4418
5266
|
}
|
|
4419
5267
|
async getInstallationsByTenant(tenantId, channel) {
|
|
4420
5268
|
let rows2;
|
|
@@ -4427,7 +5275,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4427
5275
|
`SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
|
|
4428
5276
|
).all(tenantId);
|
|
4429
5277
|
}
|
|
4430
|
-
return rows2.map(
|
|
5278
|
+
return rows2.map(mapRow14);
|
|
4431
5279
|
}
|
|
4432
5280
|
async getAllInstallations(channel) {
|
|
4433
5281
|
let rows2;
|
|
@@ -4440,7 +5288,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4440
5288
|
`SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
|
|
4441
5289
|
).all();
|
|
4442
5290
|
}
|
|
4443
|
-
return rows2.map(
|
|
5291
|
+
return rows2.map(mapRow14);
|
|
4444
5292
|
}
|
|
4445
5293
|
async createInstallation(tenantId, installationId, data) {
|
|
4446
5294
|
const now = nowISO();
|
|
@@ -4516,7 +5364,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4516
5364
|
return result.changes > 0;
|
|
4517
5365
|
}
|
|
4518
5366
|
};
|
|
4519
|
-
function
|
|
5367
|
+
function mapRow14(row) {
|
|
4520
5368
|
return {
|
|
4521
5369
|
id: row.id,
|
|
4522
5370
|
tenantId: row.tenant_id,
|
|
@@ -4532,9 +5380,9 @@ function mapRow7(row) {
|
|
|
4532
5380
|
}
|
|
4533
5381
|
|
|
4534
5382
|
// src/stores/LocalA2AApiKeyStore.ts
|
|
4535
|
-
var
|
|
5383
|
+
var import_core8 = require("@axiom-lattice/core");
|
|
4536
5384
|
var import_crypto3 = require("crypto");
|
|
4537
|
-
var
|
|
5385
|
+
var DDL25 = `
|
|
4538
5386
|
CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
|
|
4539
5387
|
id TEXT PRIMARY KEY,
|
|
4540
5388
|
key_value TEXT NOT NULL,
|
|
@@ -4572,7 +5420,7 @@ function parseAssistantIds(raw) {
|
|
|
4572
5420
|
var LocalA2AApiKeyStore = class {
|
|
4573
5421
|
constructor(db) {
|
|
4574
5422
|
this.db = db;
|
|
4575
|
-
ensureTable(db,
|
|
5423
|
+
ensureTable(db, DDL25);
|
|
4576
5424
|
this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
|
|
4577
5425
|
this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
|
|
4578
5426
|
this.repairManagementIds();
|
|
@@ -4603,7 +5451,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4603
5451
|
).all();
|
|
4604
5452
|
for (const row of rows2) {
|
|
4605
5453
|
try {
|
|
4606
|
-
if ((0,
|
|
5454
|
+
if ((0, import_core8.decrypt)(row.key_value) === key) return mapRowToRecord(row);
|
|
4607
5455
|
} catch {
|
|
4608
5456
|
}
|
|
4609
5457
|
}
|
|
@@ -4637,7 +5485,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4637
5485
|
this.db.prepare(
|
|
4638
5486
|
`INSERT INTO lt_a2a_api_keys (id, key_value, tenant_id, project_id, assistant_ids, grants, label, created_at, updated_at)
|
|
4639
5487
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
4640
|
-
).run(id, (0,
|
|
5488
|
+
).run(id, (0, import_core8.encrypt)(key), input.tenantId, input.projectId, input.assistantIds ? JSON.stringify(input.assistantIds) : null, input.grants ? JSON.stringify(input.grants) : null, input.label || null, now, now);
|
|
4641
5489
|
const record2 = {
|
|
4642
5490
|
id,
|
|
4643
5491
|
key,
|
|
@@ -4706,7 +5554,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4706
5554
|
const now = nowISO();
|
|
4707
5555
|
this.db.prepare(
|
|
4708
5556
|
`UPDATE lt_a2a_api_keys SET key_value = ?, updated_at = ? WHERE id = ?`
|
|
4709
|
-
).run((0,
|
|
5557
|
+
).run((0, import_core8.encrypt)(key), now, id);
|
|
4710
5558
|
const row = this.db.prepare(`SELECT * FROM lt_a2a_api_keys WHERE id = ?`).get(id);
|
|
4711
5559
|
if (!row) throw new Error(`A2A API key not found: ${id}`);
|
|
4712
5560
|
const record2 = mapRowToRecord(row);
|
|
@@ -4723,7 +5571,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4723
5571
|
const map2 = /* @__PURE__ */ new Map();
|
|
4724
5572
|
for (const row of rows2) {
|
|
4725
5573
|
try {
|
|
4726
|
-
const key = (0,
|
|
5574
|
+
const key = (0, import_core8.decrypt)(row.key_value);
|
|
4727
5575
|
map2.set(key, {
|
|
4728
5576
|
key,
|
|
4729
5577
|
tenantId: row.tenant_id,
|
|
@@ -4739,7 +5587,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4739
5587
|
function mapRowToRecord(row) {
|
|
4740
5588
|
return {
|
|
4741
5589
|
id: row.id,
|
|
4742
|
-
key: (0,
|
|
5590
|
+
key: (0, import_core8.safeDecrypt)(row.key_value),
|
|
4743
5591
|
tenantId: row.tenant_id,
|
|
4744
5592
|
projectId: row.project_id,
|
|
4745
5593
|
assistantIds: parseAssistantIds(row.assistant_ids),
|
|
@@ -4753,7 +5601,7 @@ function mapRowToRecord(row) {
|
|
|
4753
5601
|
|
|
4754
5602
|
// src/stores/LocalOpenAuditStore.ts
|
|
4755
5603
|
var import_crypto4 = require("crypto");
|
|
4756
|
-
var
|
|
5604
|
+
var DDL26 = `
|
|
4757
5605
|
CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
4758
5606
|
id TEXT PRIMARY KEY,
|
|
4759
5607
|
tenant_id TEXT NOT NULL,
|
|
@@ -4772,7 +5620,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
|
4772
5620
|
var LocalOpenAuditStore = class {
|
|
4773
5621
|
constructor(db) {
|
|
4774
5622
|
this.db = db;
|
|
4775
|
-
ensureTable(db,
|
|
5623
|
+
ensureTable(db, DDL26);
|
|
4776
5624
|
}
|
|
4777
5625
|
async query(params) {
|
|
4778
5626
|
const clauses = ["tenant_id = ?"];
|
|
@@ -4842,9 +5690,9 @@ var LocalOpenAuditStore = class {
|
|
|
4842
5690
|
};
|
|
4843
5691
|
|
|
4844
5692
|
// src/stores/LocalThreadMessageQueueStore.ts
|
|
4845
|
-
var
|
|
5693
|
+
var import_protocols11 = require("@axiom-lattice/protocols");
|
|
4846
5694
|
var import_crypto5 = require("crypto");
|
|
4847
|
-
var
|
|
5695
|
+
var DDL27 = `
|
|
4848
5696
|
CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
|
|
4849
5697
|
id TEXT PRIMARY KEY,
|
|
4850
5698
|
thread_id TEXT NOT NULL,
|
|
@@ -4873,7 +5721,7 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4873
5721
|
constructor(db) {
|
|
4874
5722
|
this.capacityTail = Promise.resolve();
|
|
4875
5723
|
this.db = db;
|
|
4876
|
-
ensureTable(db,
|
|
5724
|
+
ensureTable(db, DDL27);
|
|
4877
5725
|
const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
|
|
4878
5726
|
const names = new Set(columns6.map(({ name }) => name));
|
|
4879
5727
|
if (!names.has("trusted_run_context")) {
|
|
@@ -5105,8 +5953,8 @@ var LocalThreadMessageQueueStore = class {
|
|
|
5105
5953
|
};
|
|
5106
5954
|
function validateQueueTrust(params) {
|
|
5107
5955
|
return {
|
|
5108
|
-
trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0,
|
|
5109
|
-
executionMode: params.execution_mode === void 0 ? void 0 : (0,
|
|
5956
|
+
trustedRunContext: params.trusted_run_context === void 0 ? void 0 : (0, import_protocols11.parseTrustedRunContext)(params.trusted_run_context),
|
|
5957
|
+
executionMode: params.execution_mode === void 0 ? void 0 : (0, import_protocols11.parseQueuedExecutionMode)(params.execution_mode)
|
|
5110
5958
|
};
|
|
5111
5959
|
}
|
|
5112
5960
|
function scopeClause(scope) {
|
|
@@ -5127,13 +5975,13 @@ function rowToMessage(row) {
|
|
|
5127
5975
|
priority: row.priority || 0,
|
|
5128
5976
|
command: row.command ? JSON.parse(row.command) : void 0,
|
|
5129
5977
|
custom_run_config: row.custom_run_config ? JSON.parse(row.custom_run_config) : void 0,
|
|
5130
|
-
trusted_run_context: row.trusted_run_context ? (0,
|
|
5131
|
-
execution_mode: row.execution_mode == null ? void 0 : (0,
|
|
5978
|
+
trusted_run_context: row.trusted_run_context ? (0, import_protocols11.parseTrustedRunContext)(JSON.parse(row.trusted_run_context)) : void 0,
|
|
5979
|
+
execution_mode: row.execution_mode == null ? void 0 : (0, import_protocols11.parseQueuedExecutionMode)(row.execution_mode)
|
|
5132
5980
|
};
|
|
5133
5981
|
}
|
|
5134
5982
|
|
|
5135
5983
|
// src/stores/LocalSkillStore.ts
|
|
5136
|
-
var
|
|
5984
|
+
var DDL28 = `
|
|
5137
5985
|
CREATE TABLE IF NOT EXISTS lt_skills (
|
|
5138
5986
|
id TEXT NOT NULL,
|
|
5139
5987
|
tenant_id TEXT NOT NULL,
|
|
@@ -5152,7 +6000,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
|
|
|
5152
6000
|
var LocalSkillStore = class {
|
|
5153
6001
|
constructor(db) {
|
|
5154
6002
|
this.db = db;
|
|
5155
|
-
ensureTable(db,
|
|
6003
|
+
ensureTable(db, DDL28);
|
|
5156
6004
|
}
|
|
5157
6005
|
async getAllSkills(tenantId, _context) {
|
|
5158
6006
|
const rows2 = this.db.prepare(
|
|
@@ -5302,7 +6150,7 @@ function mapRowToSkill(row) {
|
|
|
5302
6150
|
}
|
|
5303
6151
|
|
|
5304
6152
|
// src/stores/LocalScheduleStorage.ts
|
|
5305
|
-
var
|
|
6153
|
+
var DDL29 = `
|
|
5306
6154
|
CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
|
|
5307
6155
|
task_id TEXT PRIMARY KEY,
|
|
5308
6156
|
task_type TEXT NOT NULL,
|
|
@@ -5335,7 +6183,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
|
|
|
5335
6183
|
var LocalScheduleStorage = class {
|
|
5336
6184
|
constructor(db) {
|
|
5337
6185
|
this.db = db;
|
|
5338
|
-
ensureTable(db,
|
|
6186
|
+
ensureTable(db, DDL29);
|
|
5339
6187
|
}
|
|
5340
6188
|
async save(task) {
|
|
5341
6189
|
this.db.prepare(
|
|
@@ -5652,7 +6500,7 @@ function mapRowToTask(row) {
|
|
|
5652
6500
|
}
|
|
5653
6501
|
|
|
5654
6502
|
// src/stores/LocalTaskStore.ts
|
|
5655
|
-
var
|
|
6503
|
+
var import_protocols12 = require("@axiom-lattice/protocols");
|
|
5656
6504
|
var import_crypto6 = require("crypto");
|
|
5657
6505
|
var MAX_CANONICAL_TASK_TIME = "9999-12-31T23:59:59.999Z";
|
|
5658
6506
|
var TASK_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -5669,7 +6517,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
|
|
|
5669
6517
|
THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
|
|
5670
6518
|
ELSE ?
|
|
5671
6519
|
END`;
|
|
5672
|
-
var
|
|
6520
|
+
var DDL30 = `
|
|
5673
6521
|
CREATE TABLE IF NOT EXISTS lt_tasks (
|
|
5674
6522
|
id TEXT NOT NULL,
|
|
5675
6523
|
tenant_id TEXT NOT NULL,
|
|
@@ -5742,7 +6590,7 @@ function assertPage(limit, offset = 0) {
|
|
|
5742
6590
|
var LocalTaskStore = class {
|
|
5743
6591
|
constructor(db) {
|
|
5744
6592
|
this.db = db;
|
|
5745
|
-
ensureTable(db,
|
|
6593
|
+
ensureTable(db, DDL30);
|
|
5746
6594
|
this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
|
|
5747
6595
|
this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
|
|
5748
6596
|
this.ensureColumn("lt_tasks", "result", "result TEXT");
|
|
@@ -5841,7 +6689,7 @@ var LocalTaskStore = class {
|
|
|
5841
6689
|
if (filter.metadata) {
|
|
5842
6690
|
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
5843
6691
|
const safeKey = key.replace(/[^a-zA-Z0-9_]/g, "");
|
|
5844
|
-
const expected = (0,
|
|
6692
|
+
const expected = (0, import_protocols12.normalizeTaskMetadataScalar)(value);
|
|
5845
6693
|
if (!safeKey || expected === void 0) continue;
|
|
5846
6694
|
if (expected === "true" || expected === "false") {
|
|
5847
6695
|
conditions.push(
|
|
@@ -6416,7 +7264,7 @@ var LocalTaskStore = class {
|
|
|
6416
7264
|
};
|
|
6417
7265
|
|
|
6418
7266
|
// src/stores/LocalTaskWorkItemStore.ts
|
|
6419
|
-
var
|
|
7267
|
+
var import_protocols13 = require("@axiom-lattice/protocols");
|
|
6420
7268
|
var import_uuid2 = require("uuid");
|
|
6421
7269
|
var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
6422
7270
|
"in_progress",
|
|
@@ -6426,7 +7274,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
6426
7274
|
"cancelled",
|
|
6427
7275
|
"reassigned"
|
|
6428
7276
|
]);
|
|
6429
|
-
var
|
|
7277
|
+
var DDL31 = `
|
|
6430
7278
|
CREATE TABLE IF NOT EXISTS lt_task_work_items (
|
|
6431
7279
|
id TEXT NOT NULL,
|
|
6432
7280
|
tenant_id TEXT NOT NULL,
|
|
@@ -6500,7 +7348,7 @@ function assertLifecyclePage(query) {
|
|
|
6500
7348
|
var LocalTaskWorkItemStore = class {
|
|
6501
7349
|
constructor(db) {
|
|
6502
7350
|
this.db = db;
|
|
6503
|
-
ensureTable(db,
|
|
7351
|
+
ensureTable(db, DDL31);
|
|
6504
7352
|
this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
|
|
6505
7353
|
this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
|
|
6506
7354
|
this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
|
|
@@ -6641,8 +7489,8 @@ var LocalTaskWorkItemStore = class {
|
|
|
6641
7489
|
}
|
|
6642
7490
|
/** List pending execution results using one bounded SQLite anti-join query. */
|
|
6643
7491
|
async listPendingExecutionResults(params) {
|
|
6644
|
-
if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit >
|
|
6645
|
-
const error = new RangeError(`limit must be a safe integer between 0 and ${
|
|
7492
|
+
if (!Number.isSafeInteger(params.limit) || params.limit < 0 || params.limit > import_protocols13.MAX_PENDING_EXECUTION_RESULTS_LIMIT) {
|
|
7493
|
+
const error = new RangeError(`limit must be a safe integer between 0 and ${import_protocols13.MAX_PENDING_EXECUTION_RESULTS_LIMIT}`);
|
|
6646
7494
|
error.code = "INVALID_LIMIT";
|
|
6647
7495
|
throw error;
|
|
6648
7496
|
}
|
|
@@ -6697,7 +7545,7 @@ var LocalTaskWorkItemStore = class {
|
|
|
6697
7545
|
|
|
6698
7546
|
// src/stores/LocalCapabilityBundleStore.ts
|
|
6699
7547
|
var import_crypto7 = require("crypto");
|
|
6700
|
-
var
|
|
7548
|
+
var DDL32 = `CREATE TABLE IF NOT EXISTS lt_capability_bundles (id TEXT NOT NULL, tenant_id TEXT NOT NULL, bundle_key TEXT NOT NULL, name TEXT NOT NULL, description TEXT, capabilities TEXT NOT NULL DEFAULT '[]', created_at TEXT NOT NULL, updated_at TEXT NOT NULL, PRIMARY KEY (tenant_id, id), UNIQUE (tenant_id, bundle_key)); CREATE INDEX IF NOT EXISTS idx_lt_capability_bundles_tenant ON lt_capability_bundles(tenant_id);`;
|
|
6701
7549
|
var duplicateMessage = "Capability bundle key already exists for tenant";
|
|
6702
7550
|
function map(row) {
|
|
6703
7551
|
return { id: row.id, tenantId: row.tenant_id, key: row.bundle_key, name: row.name, description: row.description ?? void 0, capabilities: JSON.parse(row.capabilities), createdAt: parseISO(row.created_at).toISOString(), updatedAt: parseISO(row.updated_at).toISOString() };
|
|
@@ -6718,7 +7566,7 @@ var LocalCapabilityBundleStore = class {
|
|
|
6718
7566
|
*/
|
|
6719
7567
|
constructor(db) {
|
|
6720
7568
|
this.db = db;
|
|
6721
|
-
ensureTable(db,
|
|
7569
|
+
ensureTable(db, DDL32);
|
|
6722
7570
|
}
|
|
6723
7571
|
async listByTenant(tenantId) {
|
|
6724
7572
|
return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
|
|
@@ -6805,6 +7653,13 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
6805
7653
|
user: new LocalUserStore(db),
|
|
6806
7654
|
tenant: new LocalTenantStore(db),
|
|
6807
7655
|
userTenantLink: new LocalUserTenantLinkStore(db),
|
|
7656
|
+
userExternalIdentity: new LocalUserExternalIdentityStore(db),
|
|
7657
|
+
oidcProviderConfig: new LocalOidcProviderConfigStore(db),
|
|
7658
|
+
platformMember: new LocalPlatformMemberStore(db),
|
|
7659
|
+
platformInvitation: new LocalPlatformInvitationStore(db),
|
|
7660
|
+
oidcIdentityClaim: new LocalOidcIdentityClaimStore(db),
|
|
7661
|
+
inviteLink: new LocalInviteLinkStore(db),
|
|
7662
|
+
platformSettings: new LocalPlatformSettingsStore(db),
|
|
6808
7663
|
database: new LocalDatabaseConfigStore(db),
|
|
6809
7664
|
connection: new LocalConnectionStore(db),
|
|
6810
7665
|
metrics: new LocalMetricsServerConfigStore(db),
|
|
@@ -6876,10 +7731,16 @@ var InMemoryConversationStore = class {
|
|
|
6876
7731
|
LocalConnectionStore,
|
|
6877
7732
|
LocalDatabaseConfigStore,
|
|
6878
7733
|
LocalEvalStore,
|
|
7734
|
+
LocalInviteLinkStore,
|
|
6879
7735
|
LocalMcpServerConfigStore,
|
|
6880
7736
|
LocalMetricsServerConfigStore,
|
|
6881
7737
|
LocalModelProviderStore,
|
|
7738
|
+
LocalOidcIdentityClaimStore,
|
|
7739
|
+
LocalOidcProviderConfigStore,
|
|
6882
7740
|
LocalOpenAuditStore,
|
|
7741
|
+
LocalPlatformInvitationStore,
|
|
7742
|
+
LocalPlatformMemberStore,
|
|
7743
|
+
LocalPlatformSettingsStore,
|
|
6883
7744
|
LocalProjectBotMembershipStore,
|
|
6884
7745
|
LocalProjectMembershipStore,
|
|
6885
7746
|
LocalProjectRoomMessageStore,
|
|
@@ -6894,6 +7755,7 @@ var InMemoryConversationStore = class {
|
|
|
6894
7755
|
LocalTenantStore,
|
|
6895
7756
|
LocalThreadMessageQueueStore,
|
|
6896
7757
|
LocalThreadStore,
|
|
7758
|
+
LocalUserExternalIdentityStore,
|
|
6897
7759
|
LocalUserStore,
|
|
6898
7760
|
LocalUserTenantLinkStore,
|
|
6899
7761
|
LocalWorkflowTrackingStore,
|