@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.mjs
CHANGED
|
@@ -1745,6 +1745,7 @@ CREATE TABLE IF NOT EXISTS lt_users (
|
|
|
1745
1745
|
updated_at TEXT NOT NULL
|
|
1746
1746
|
);
|
|
1747
1747
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_users_email ON lt_users(email);
|
|
1748
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_users_email_lower ON lt_users(lower(email));
|
|
1748
1749
|
`;
|
|
1749
1750
|
var LocalUserStore = class {
|
|
1750
1751
|
constructor(db) {
|
|
@@ -1765,8 +1766,8 @@ var LocalUserStore = class {
|
|
|
1765
1766
|
}
|
|
1766
1767
|
async getUserByEmail(email) {
|
|
1767
1768
|
const row = this.db.prepare(
|
|
1768
|
-
`SELECT * FROM lt_users WHERE email =
|
|
1769
|
-
).get(email);
|
|
1769
|
+
`SELECT * FROM lt_users WHERE lower(email) = lower(?)`
|
|
1770
|
+
).get(email.trim());
|
|
1770
1771
|
return row ? mapRowToUser(row) : null;
|
|
1771
1772
|
}
|
|
1772
1773
|
async createUser(id, data) {
|
|
@@ -2040,9 +2041,863 @@ function mapRowToLink(row) {
|
|
|
2040
2041
|
};
|
|
2041
2042
|
}
|
|
2042
2043
|
|
|
2043
|
-
// src/stores/
|
|
2044
|
-
import {
|
|
2044
|
+
// src/stores/LocalUserExternalIdentityStore.ts
|
|
2045
|
+
import {
|
|
2046
|
+
ExternalIdentityConflictError,
|
|
2047
|
+
ExternalIdentityPersistError
|
|
2048
|
+
} from "@axiom-lattice/protocols";
|
|
2045
2049
|
var DDL9 = `
|
|
2050
|
+
CREATE TABLE IF NOT EXISTS lt_user_identities (
|
|
2051
|
+
user_id TEXT NOT NULL,
|
|
2052
|
+
provider_id TEXT NOT NULL,
|
|
2053
|
+
issuer TEXT NOT NULL,
|
|
2054
|
+
subject TEXT NOT NULL,
|
|
2055
|
+
email TEXT,
|
|
2056
|
+
linked_at TEXT NOT NULL,
|
|
2057
|
+
PRIMARY KEY (provider_id, issuer, subject)
|
|
2058
|
+
);
|
|
2059
|
+
CREATE INDEX IF NOT EXISTS idx_lt_user_identities_user
|
|
2060
|
+
ON lt_user_identities (user_id);
|
|
2061
|
+
`;
|
|
2062
|
+
function mapRow7(row) {
|
|
2063
|
+
return {
|
|
2064
|
+
userId: row.user_id,
|
|
2065
|
+
providerId: row.provider_id,
|
|
2066
|
+
issuer: row.issuer,
|
|
2067
|
+
subject: row.subject,
|
|
2068
|
+
...row.email === null ? {} : { email: row.email },
|
|
2069
|
+
linkedAt: parseISO(row.linked_at)
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
var LocalUserExternalIdentityStore = class {
|
|
2073
|
+
constructor(db) {
|
|
2074
|
+
this.db = db;
|
|
2075
|
+
ensureTable(db, DDL9);
|
|
2076
|
+
}
|
|
2077
|
+
async getByProviderSubject(providerId, issuer, subject) {
|
|
2078
|
+
const row = this.db.prepare(
|
|
2079
|
+
`SELECT * FROM lt_user_identities
|
|
2080
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?`
|
|
2081
|
+
).get(providerId, issuer, subject);
|
|
2082
|
+
return row ? mapRow7(row) : null;
|
|
2083
|
+
}
|
|
2084
|
+
async listByUser(userId) {
|
|
2085
|
+
const rows2 = this.db.prepare(`SELECT * FROM lt_user_identities WHERE user_id = ? ORDER BY linked_at ASC`).all(userId);
|
|
2086
|
+
return rows2.map(mapRow7);
|
|
2087
|
+
}
|
|
2088
|
+
async link(identity) {
|
|
2089
|
+
this.db.prepare(
|
|
2090
|
+
`INSERT INTO lt_user_identities (user_id, provider_id, issuer, subject, email, linked_at)
|
|
2091
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
2092
|
+
ON CONFLICT(provider_id, issuer, subject) DO NOTHING`
|
|
2093
|
+
).run(
|
|
2094
|
+
identity.userId,
|
|
2095
|
+
identity.providerId,
|
|
2096
|
+
identity.issuer,
|
|
2097
|
+
identity.subject,
|
|
2098
|
+
identity.email ?? null,
|
|
2099
|
+
identity.linkedAt.toISOString()
|
|
2100
|
+
);
|
|
2101
|
+
const existing = await this.getByProviderSubject(
|
|
2102
|
+
identity.providerId,
|
|
2103
|
+
identity.issuer,
|
|
2104
|
+
identity.subject
|
|
2105
|
+
);
|
|
2106
|
+
if (!existing) {
|
|
2107
|
+
throw new ExternalIdentityPersistError(
|
|
2108
|
+
identity.providerId,
|
|
2109
|
+
identity.issuer,
|
|
2110
|
+
identity.subject
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
2113
|
+
if (existing.userId !== identity.userId) {
|
|
2114
|
+
throw new ExternalIdentityConflictError(
|
|
2115
|
+
identity.providerId,
|
|
2116
|
+
identity.issuer,
|
|
2117
|
+
identity.subject
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
if (identity.email !== void 0 && identity.email !== existing.email) {
|
|
2121
|
+
this.db.prepare(
|
|
2122
|
+
`UPDATE lt_user_identities SET email = ?
|
|
2123
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?`
|
|
2124
|
+
).run(identity.email, identity.providerId, identity.issuer, identity.subject);
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
async unlink(providerId, issuer, subject) {
|
|
2128
|
+
this.db.prepare(
|
|
2129
|
+
`DELETE FROM lt_user_identities
|
|
2130
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?`
|
|
2131
|
+
).run(providerId, issuer, subject);
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2135
|
+
// src/stores/LocalOidcProviderConfigStore.ts
|
|
2136
|
+
import { safeDecrypt, encrypt } from "@axiom-lattice/core";
|
|
2137
|
+
import {
|
|
2138
|
+
OidcProviderConfigConflictError
|
|
2139
|
+
} from "@axiom-lattice/protocols";
|
|
2140
|
+
var DDL10 = `
|
|
2141
|
+
CREATE TABLE IF NOT EXISTS lattice_oidc_provider_configs (
|
|
2142
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2143
|
+
display_name TEXT NOT NULL,
|
|
2144
|
+
issuer TEXT NOT NULL,
|
|
2145
|
+
client_id TEXT NOT NULL,
|
|
2146
|
+
client_secret TEXT NOT NULL,
|
|
2147
|
+
scopes TEXT NOT NULL,
|
|
2148
|
+
enabled INTEGER NOT NULL,
|
|
2149
|
+
jit_provisioning INTEGER NOT NULL,
|
|
2150
|
+
auto_link_email INTEGER NOT NULL,
|
|
2151
|
+
default_tenant_id TEXT,
|
|
2152
|
+
allowed_private_hosts TEXT,
|
|
2153
|
+
created_at TEXT NOT NULL,
|
|
2154
|
+
updated_at TEXT NOT NULL
|
|
2155
|
+
);
|
|
2156
|
+
`;
|
|
2157
|
+
function parseAllowedPrivateHosts(value) {
|
|
2158
|
+
if (value === null) return void 0;
|
|
2159
|
+
try {
|
|
2160
|
+
const parsed = JSON.parse(value);
|
|
2161
|
+
return Array.isArray(parsed) ? parsed.filter((entry) => typeof entry === "string") : void 0;
|
|
2162
|
+
} catch {
|
|
2163
|
+
return void 0;
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
function serializeAllowedPrivateHosts(value) {
|
|
2167
|
+
return value === void 0 ? null : JSON.stringify(value);
|
|
2168
|
+
}
|
|
2169
|
+
function normalizeTenantId(value) {
|
|
2170
|
+
if (typeof value !== "string") return void 0;
|
|
2171
|
+
const trimmed = value.trim();
|
|
2172
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2173
|
+
}
|
|
2174
|
+
function mapRow8(row) {
|
|
2175
|
+
const allowedPrivateHosts = parseAllowedPrivateHosts(
|
|
2176
|
+
row.allowed_private_hosts
|
|
2177
|
+
);
|
|
2178
|
+
return {
|
|
2179
|
+
id: row.id,
|
|
2180
|
+
displayName: row.display_name,
|
|
2181
|
+
issuer: row.issuer,
|
|
2182
|
+
clientId: row.client_id,
|
|
2183
|
+
clientSecret: safeDecrypt(
|
|
2184
|
+
row.client_secret,
|
|
2185
|
+
`OIDC provider config "${row.id}" client secret`
|
|
2186
|
+
),
|
|
2187
|
+
scopes: row.scopes,
|
|
2188
|
+
enabled: Number(row.enabled) === 1,
|
|
2189
|
+
jitProvisioning: Number(row.jit_provisioning) === 1,
|
|
2190
|
+
autoLinkEmail: Number(row.auto_link_email) === 1,
|
|
2191
|
+
...row.default_tenant_id !== null ? { defaultTenantId: row.default_tenant_id } : {},
|
|
2192
|
+
...allowedPrivateHosts !== void 0 ? { allowedPrivateHosts } : {},
|
|
2193
|
+
createdAt: parseISO(row.created_at),
|
|
2194
|
+
updatedAt: parseISO(row.updated_at)
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
var LocalOidcProviderConfigStore = class {
|
|
2198
|
+
constructor(db) {
|
|
2199
|
+
this.db = db;
|
|
2200
|
+
ensureTable(db, DDL10);
|
|
2201
|
+
this.ensureColumn(
|
|
2202
|
+
"lattice_oidc_provider_configs",
|
|
2203
|
+
"allowed_private_hosts",
|
|
2204
|
+
"allowed_private_hosts TEXT"
|
|
2205
|
+
);
|
|
2206
|
+
}
|
|
2207
|
+
ensureColumn(table, column, ddl2) {
|
|
2208
|
+
const cols = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
2209
|
+
if (!cols.some((entry) => entry.name === column)) {
|
|
2210
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl2}`);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
async list() {
|
|
2214
|
+
const rows2 = this.db.prepare(
|
|
2215
|
+
`SELECT * FROM lattice_oidc_provider_configs ORDER BY created_at ASC, id ASC`
|
|
2216
|
+
).all();
|
|
2217
|
+
return rows2.map(mapRow8);
|
|
2218
|
+
}
|
|
2219
|
+
async get(id) {
|
|
2220
|
+
const row = this.db.prepare(`SELECT * FROM lattice_oidc_provider_configs WHERE id = ?`).get(id);
|
|
2221
|
+
return row ? mapRow8(row) : null;
|
|
2222
|
+
}
|
|
2223
|
+
async create(id, input) {
|
|
2224
|
+
if (this.db.prepare(`SELECT 1 FROM lattice_oidc_provider_configs WHERE id = ?`).get(id)) {
|
|
2225
|
+
throw new OidcProviderConfigConflictError(id);
|
|
2226
|
+
}
|
|
2227
|
+
const now = nowISO();
|
|
2228
|
+
const tenantId = normalizeTenantId(input.defaultTenantId);
|
|
2229
|
+
try {
|
|
2230
|
+
this.db.prepare(
|
|
2231
|
+
`INSERT INTO lattice_oidc_provider_configs
|
|
2232
|
+
(id, display_name, issuer, client_id, client_secret, scopes,
|
|
2233
|
+
enabled, jit_provisioning, auto_link_email, default_tenant_id,
|
|
2234
|
+
allowed_private_hosts, created_at, updated_at)
|
|
2235
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
2236
|
+
).run(
|
|
2237
|
+
id,
|
|
2238
|
+
input.displayName,
|
|
2239
|
+
input.issuer,
|
|
2240
|
+
input.clientId,
|
|
2241
|
+
encrypt(input.clientSecret),
|
|
2242
|
+
input.scopes,
|
|
2243
|
+
input.enabled ? 1 : 0,
|
|
2244
|
+
input.jitProvisioning ? 1 : 0,
|
|
2245
|
+
input.autoLinkEmail ? 1 : 0,
|
|
2246
|
+
tenantId ?? null,
|
|
2247
|
+
serializeAllowedPrivateHosts(input.allowedPrivateHosts),
|
|
2248
|
+
now,
|
|
2249
|
+
now
|
|
2250
|
+
);
|
|
2251
|
+
} catch (error) {
|
|
2252
|
+
if (error instanceof Error && /UNIQUE constraint failed/.test(error.message)) {
|
|
2253
|
+
throw new OidcProviderConfigConflictError(id);
|
|
2254
|
+
}
|
|
2255
|
+
throw error;
|
|
2256
|
+
}
|
|
2257
|
+
const created = await this.get(id);
|
|
2258
|
+
if (!created) {
|
|
2259
|
+
throw new Error(`OIDC provider config "${id}" was not persisted`);
|
|
2260
|
+
}
|
|
2261
|
+
return created;
|
|
2262
|
+
}
|
|
2263
|
+
async update(id, updates) {
|
|
2264
|
+
const existing = await this.get(id);
|
|
2265
|
+
if (!existing) return null;
|
|
2266
|
+
const setClauses = [];
|
|
2267
|
+
const values = [];
|
|
2268
|
+
if (updates.displayName !== void 0) {
|
|
2269
|
+
setClauses.push("display_name = ?");
|
|
2270
|
+
values.push(updates.displayName);
|
|
2271
|
+
}
|
|
2272
|
+
if (updates.issuer !== void 0) {
|
|
2273
|
+
setClauses.push("issuer = ?");
|
|
2274
|
+
values.push(updates.issuer);
|
|
2275
|
+
}
|
|
2276
|
+
if (updates.clientId !== void 0) {
|
|
2277
|
+
setClauses.push("client_id = ?");
|
|
2278
|
+
values.push(updates.clientId);
|
|
2279
|
+
}
|
|
2280
|
+
if (updates.clientSecret !== void 0 && updates.clientSecret !== "") {
|
|
2281
|
+
setClauses.push("client_secret = ?");
|
|
2282
|
+
values.push(encrypt(updates.clientSecret));
|
|
2283
|
+
}
|
|
2284
|
+
if (updates.scopes !== void 0) {
|
|
2285
|
+
setClauses.push("scopes = ?");
|
|
2286
|
+
values.push(updates.scopes);
|
|
2287
|
+
}
|
|
2288
|
+
if (updates.enabled !== void 0) {
|
|
2289
|
+
setClauses.push("enabled = ?");
|
|
2290
|
+
values.push(updates.enabled ? 1 : 0);
|
|
2291
|
+
}
|
|
2292
|
+
if (updates.jitProvisioning !== void 0) {
|
|
2293
|
+
setClauses.push("jit_provisioning = ?");
|
|
2294
|
+
values.push(updates.jitProvisioning ? 1 : 0);
|
|
2295
|
+
}
|
|
2296
|
+
if (updates.autoLinkEmail !== void 0) {
|
|
2297
|
+
setClauses.push("auto_link_email = ?");
|
|
2298
|
+
values.push(updates.autoLinkEmail ? 1 : 0);
|
|
2299
|
+
}
|
|
2300
|
+
if (updates.defaultTenantId !== void 0) {
|
|
2301
|
+
setClauses.push("default_tenant_id = ?");
|
|
2302
|
+
values.push(normalizeTenantId(updates.defaultTenantId) ?? null);
|
|
2303
|
+
}
|
|
2304
|
+
if (updates.allowedPrivateHosts !== void 0) {
|
|
2305
|
+
setClauses.push("allowed_private_hosts = ?");
|
|
2306
|
+
values.push(serializeAllowedPrivateHosts(updates.allowedPrivateHosts));
|
|
2307
|
+
}
|
|
2308
|
+
if (setClauses.length === 0) return existing;
|
|
2309
|
+
setClauses.push("updated_at = ?");
|
|
2310
|
+
values.push(nowISO());
|
|
2311
|
+
values.push(id);
|
|
2312
|
+
this.db.prepare(
|
|
2313
|
+
`UPDATE lattice_oidc_provider_configs SET ${setClauses.join(", ")} WHERE id = ?`
|
|
2314
|
+
).run(...values);
|
|
2315
|
+
return this.get(id);
|
|
2316
|
+
}
|
|
2317
|
+
async delete(id) {
|
|
2318
|
+
const result = this.db.prepare(`DELETE FROM lattice_oidc_provider_configs WHERE id = ?`).run(id);
|
|
2319
|
+
return result.changes > 0;
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
|
|
2323
|
+
// src/stores/LocalPlatformMemberStore.ts
|
|
2324
|
+
var DDL11 = `
|
|
2325
|
+
CREATE TABLE IF NOT EXISTS lattice_platform_members (
|
|
2326
|
+
user_id TEXT NOT NULL PRIMARY KEY,
|
|
2327
|
+
role TEXT NOT NULL,
|
|
2328
|
+
granted_by TEXT,
|
|
2329
|
+
granted_at TEXT NOT NULL,
|
|
2330
|
+
updated_at TEXT NOT NULL
|
|
2331
|
+
);
|
|
2332
|
+
`;
|
|
2333
|
+
function mapRow9(row) {
|
|
2334
|
+
return {
|
|
2335
|
+
userId: row.user_id,
|
|
2336
|
+
role: row.role,
|
|
2337
|
+
...row.granted_by !== null ? { grantedBy: row.granted_by } : {},
|
|
2338
|
+
grantedAt: parseISO(row.granted_at),
|
|
2339
|
+
updatedAt: parseISO(row.updated_at)
|
|
2340
|
+
};
|
|
2341
|
+
}
|
|
2342
|
+
var LocalPlatformMemberStore = class {
|
|
2343
|
+
constructor(db) {
|
|
2344
|
+
this.db = db;
|
|
2345
|
+
ensureTable(db, DDL11);
|
|
2346
|
+
}
|
|
2347
|
+
/** Lists every platform member ordered by user id. */
|
|
2348
|
+
async list() {
|
|
2349
|
+
const rows2 = this.db.prepare(
|
|
2350
|
+
`SELECT * FROM lattice_platform_members ORDER BY user_id ASC`
|
|
2351
|
+
).all();
|
|
2352
|
+
return rows2.map(mapRow9);
|
|
2353
|
+
}
|
|
2354
|
+
/** Returns the platform member for a user, or null. */
|
|
2355
|
+
async get(userId) {
|
|
2356
|
+
const row = this.db.prepare(`SELECT * FROM lattice_platform_members WHERE user_id = ?`).get(userId);
|
|
2357
|
+
return row ? mapRow9(row) : null;
|
|
2358
|
+
}
|
|
2359
|
+
/**
|
|
2360
|
+
* Inserts or replaces a member keyed by user id.
|
|
2361
|
+
*
|
|
2362
|
+
* The supplied grant replaces any existing row in full (last write wins),
|
|
2363
|
+
* including `grantedAt` and `updatedAt`.
|
|
2364
|
+
*/
|
|
2365
|
+
async upsert(member) {
|
|
2366
|
+
this.db.prepare(
|
|
2367
|
+
`INSERT INTO lattice_platform_members
|
|
2368
|
+
(user_id, role, granted_by, granted_at, updated_at)
|
|
2369
|
+
VALUES (?, ?, ?, ?, ?)
|
|
2370
|
+
ON CONFLICT(user_id) DO UPDATE SET
|
|
2371
|
+
role = excluded.role,
|
|
2372
|
+
granted_by = excluded.granted_by,
|
|
2373
|
+
granted_at = excluded.granted_at,
|
|
2374
|
+
updated_at = excluded.updated_at`
|
|
2375
|
+
).run(
|
|
2376
|
+
member.userId,
|
|
2377
|
+
member.role,
|
|
2378
|
+
member.grantedBy ?? null,
|
|
2379
|
+
member.grantedAt.toISOString(),
|
|
2380
|
+
member.updatedAt.toISOString()
|
|
2381
|
+
);
|
|
2382
|
+
const stored = await this.get(member.userId);
|
|
2383
|
+
if (!stored) {
|
|
2384
|
+
throw new Error(`Platform member "${member.userId}" was not persisted`);
|
|
2385
|
+
}
|
|
2386
|
+
return stored;
|
|
2387
|
+
}
|
|
2388
|
+
/** Deletes a member. Returns whether a row was removed. */
|
|
2389
|
+
async delete(userId) {
|
|
2390
|
+
const result = this.db.prepare(`DELETE FROM lattice_platform_members WHERE user_id = ?`).run(userId);
|
|
2391
|
+
return result.changes > 0;
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
|
|
2395
|
+
// src/stores/LocalPlatformInvitationStore.ts
|
|
2396
|
+
import {
|
|
2397
|
+
normalizePlatformInvitationEmail
|
|
2398
|
+
} from "@axiom-lattice/protocols";
|
|
2399
|
+
var DDL12 = `
|
|
2400
|
+
CREATE TABLE IF NOT EXISTS lattice_platform_invitations (
|
|
2401
|
+
email TEXT NOT NULL PRIMARY KEY,
|
|
2402
|
+
role TEXT NOT NULL,
|
|
2403
|
+
invited_by TEXT,
|
|
2404
|
+
created_at TEXT NOT NULL,
|
|
2405
|
+
expires_at TEXT,
|
|
2406
|
+
consumed_at TEXT
|
|
2407
|
+
);
|
|
2408
|
+
`;
|
|
2409
|
+
function mapRow10(row) {
|
|
2410
|
+
return {
|
|
2411
|
+
email: row.email,
|
|
2412
|
+
role: row.role,
|
|
2413
|
+
...row.invited_by !== null ? { invitedBy: row.invited_by } : {},
|
|
2414
|
+
createdAt: parseISO(row.created_at),
|
|
2415
|
+
...row.expires_at !== null ? { expiresAt: parseISO(row.expires_at) } : {},
|
|
2416
|
+
...row.consumed_at !== null ? { consumedAt: parseISO(row.consumed_at) } : {}
|
|
2417
|
+
};
|
|
2418
|
+
}
|
|
2419
|
+
var LocalPlatformInvitationStore = class {
|
|
2420
|
+
constructor(db) {
|
|
2421
|
+
this.db = db;
|
|
2422
|
+
ensureTable(db, DDL12);
|
|
2423
|
+
}
|
|
2424
|
+
/** Lists every invitation ordered by normalized email. */
|
|
2425
|
+
async list() {
|
|
2426
|
+
const rows2 = this.db.prepare(`SELECT * FROM lattice_platform_invitations ORDER BY email ASC`).all();
|
|
2427
|
+
return rows2.map(mapRow10);
|
|
2428
|
+
}
|
|
2429
|
+
/** Returns the invitation for an email, or null. */
|
|
2430
|
+
async get(email) {
|
|
2431
|
+
const row = this.db.prepare(`SELECT * FROM lattice_platform_invitations WHERE email = ?`).get(normalizePlatformInvitationEmail(email));
|
|
2432
|
+
return row ? mapRow10(row) : null;
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Inserts or replaces an invitation keyed by normalized email.
|
|
2436
|
+
*
|
|
2437
|
+
* The supplied invitation replaces any existing row in full (last write wins),
|
|
2438
|
+
* including `expiresAt` and `consumedAt`.
|
|
2439
|
+
*/
|
|
2440
|
+
async upsert(invitation) {
|
|
2441
|
+
const email = normalizePlatformInvitationEmail(invitation.email);
|
|
2442
|
+
this.db.prepare(
|
|
2443
|
+
`INSERT INTO lattice_platform_invitations
|
|
2444
|
+
(email, role, invited_by, created_at, expires_at, consumed_at)
|
|
2445
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
2446
|
+
ON CONFLICT(email) DO UPDATE SET
|
|
2447
|
+
role = excluded.role,
|
|
2448
|
+
invited_by = excluded.invited_by,
|
|
2449
|
+
created_at = excluded.created_at,
|
|
2450
|
+
expires_at = excluded.expires_at,
|
|
2451
|
+
consumed_at = excluded.consumed_at`
|
|
2452
|
+
).run(
|
|
2453
|
+
email,
|
|
2454
|
+
invitation.role,
|
|
2455
|
+
invitation.invitedBy ?? null,
|
|
2456
|
+
invitation.createdAt.toISOString(),
|
|
2457
|
+
invitation.expiresAt?.toISOString() ?? null,
|
|
2458
|
+
invitation.consumedAt?.toISOString() ?? null
|
|
2459
|
+
);
|
|
2460
|
+
const stored = await this.get(email);
|
|
2461
|
+
if (!stored) {
|
|
2462
|
+
throw new Error(`Platform invitation "${email}" was not persisted`);
|
|
2463
|
+
}
|
|
2464
|
+
return stored;
|
|
2465
|
+
}
|
|
2466
|
+
/** Deletes an invitation. Returns whether a row was removed. */
|
|
2467
|
+
async delete(email) {
|
|
2468
|
+
const result = this.db.prepare(`DELETE FROM lattice_platform_invitations WHERE email = ?`).run(normalizePlatformInvitationEmail(email));
|
|
2469
|
+
return result.changes > 0;
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Atomically consumes a pending, unexpired invitation.
|
|
2473
|
+
*
|
|
2474
|
+
* Returns the consumed invitation, or null when the row is missing, already
|
|
2475
|
+
* consumed, or expired.
|
|
2476
|
+
*/
|
|
2477
|
+
async consume(email, at) {
|
|
2478
|
+
const normalized = normalizePlatformInvitationEmail(email);
|
|
2479
|
+
const timestamp2 = at.toISOString();
|
|
2480
|
+
const result = this.db.prepare(
|
|
2481
|
+
`UPDATE lattice_platform_invitations
|
|
2482
|
+
SET consumed_at = ?
|
|
2483
|
+
WHERE email = ?
|
|
2484
|
+
AND consumed_at IS NULL
|
|
2485
|
+
AND (expires_at IS NULL OR expires_at > ?)`
|
|
2486
|
+
).run(timestamp2, normalized, timestamp2);
|
|
2487
|
+
if (result.changes === 0) return null;
|
|
2488
|
+
return this.get(normalized);
|
|
2489
|
+
}
|
|
2490
|
+
};
|
|
2491
|
+
|
|
2492
|
+
// src/stores/LocalOidcIdentityClaimStore.ts
|
|
2493
|
+
import {
|
|
2494
|
+
normalizeOidcIdentityEmail,
|
|
2495
|
+
OidcIdentityClaimConflictError
|
|
2496
|
+
} from "@axiom-lattice/protocols";
|
|
2497
|
+
var DDL13 = `
|
|
2498
|
+
CREATE TABLE IF NOT EXISTS lattice_oidc_identity_claims (
|
|
2499
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2500
|
+
provider_id TEXT NOT NULL,
|
|
2501
|
+
issuer TEXT NOT NULL,
|
|
2502
|
+
subject TEXT NOT NULL,
|
|
2503
|
+
email TEXT NOT NULL,
|
|
2504
|
+
name TEXT,
|
|
2505
|
+
picture TEXT,
|
|
2506
|
+
status TEXT NOT NULL,
|
|
2507
|
+
created_at TEXT NOT NULL,
|
|
2508
|
+
updated_at TEXT NOT NULL,
|
|
2509
|
+
expires_at TEXT NOT NULL,
|
|
2510
|
+
reviewed_by TEXT,
|
|
2511
|
+
reviewed_at TEXT,
|
|
2512
|
+
linked_user_id TEXT,
|
|
2513
|
+
source TEXT,
|
|
2514
|
+
invite_link_id TEXT,
|
|
2515
|
+
requested_user_id TEXT,
|
|
2516
|
+
requested_platform_role TEXT,
|
|
2517
|
+
requested_tenant_id TEXT,
|
|
2518
|
+
requested_tenant_role TEXT
|
|
2519
|
+
);
|
|
2520
|
+
CREATE UNIQUE INDEX IF NOT EXISTS lattice_oidc_identity_claims_pending_subject
|
|
2521
|
+
ON lattice_oidc_identity_claims (provider_id, issuer, subject)
|
|
2522
|
+
WHERE status = 'pending';
|
|
2523
|
+
`;
|
|
2524
|
+
function mapRow11(row) {
|
|
2525
|
+
return {
|
|
2526
|
+
id: row.id,
|
|
2527
|
+
providerId: row.provider_id,
|
|
2528
|
+
issuer: row.issuer,
|
|
2529
|
+
subject: row.subject,
|
|
2530
|
+
email: row.email,
|
|
2531
|
+
...row.name !== null ? { name: row.name } : {},
|
|
2532
|
+
...row.picture !== null ? { picture: row.picture } : {},
|
|
2533
|
+
status: row.status,
|
|
2534
|
+
createdAt: parseISO(row.created_at),
|
|
2535
|
+
updatedAt: parseISO(row.updated_at),
|
|
2536
|
+
expiresAt: parseISO(row.expires_at),
|
|
2537
|
+
...row.reviewed_by !== null ? { reviewedBy: row.reviewed_by } : {},
|
|
2538
|
+
...row.reviewed_at !== null ? { reviewedAt: parseISO(row.reviewed_at) } : {},
|
|
2539
|
+
...row.linked_user_id !== null ? { linkedUserId: row.linked_user_id } : {},
|
|
2540
|
+
...row.source !== null ? { source: row.source } : {},
|
|
2541
|
+
...row.invite_link_id !== null ? { inviteLinkId: row.invite_link_id } : {},
|
|
2542
|
+
...row.requested_user_id !== null ? { requestedUserId: row.requested_user_id } : {},
|
|
2543
|
+
...row.requested_platform_role !== null ? { requestedPlatformRole: row.requested_platform_role } : {},
|
|
2544
|
+
...row.requested_tenant_id !== null ? { requestedTenantId: row.requested_tenant_id } : {},
|
|
2545
|
+
...row.requested_tenant_role !== null ? { requestedTenantRole: row.requested_tenant_role } : {}
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2548
|
+
var LocalOidcIdentityClaimStore = class {
|
|
2549
|
+
constructor(db) {
|
|
2550
|
+
this.db = db;
|
|
2551
|
+
ensureTable(db, DDL13);
|
|
2552
|
+
this.ensureColumn("lattice_oidc_identity_claims", "source", "source TEXT");
|
|
2553
|
+
this.ensureColumn("lattice_oidc_identity_claims", "invite_link_id", "invite_link_id TEXT");
|
|
2554
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_user_id", "requested_user_id TEXT");
|
|
2555
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_platform_role", "requested_platform_role TEXT");
|
|
2556
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_tenant_id", "requested_tenant_id TEXT");
|
|
2557
|
+
this.ensureColumn("lattice_oidc_identity_claims", "requested_tenant_role", "requested_tenant_role TEXT");
|
|
2558
|
+
}
|
|
2559
|
+
ensureColumn(table, column, ddl2) {
|
|
2560
|
+
const columns6 = this.db.prepare(`PRAGMA table_info(${table})`).all();
|
|
2561
|
+
if (!columns6.some((entry) => entry.name === column)) {
|
|
2562
|
+
this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${ddl2}`);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
async list(status) {
|
|
2566
|
+
const rows2 = status ? this.db.prepare(
|
|
2567
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2568
|
+
WHERE status = ? ORDER BY created_at ASC, id ASC`
|
|
2569
|
+
).all(status) : this.db.prepare(
|
|
2570
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2571
|
+
ORDER BY created_at ASC, id ASC`
|
|
2572
|
+
).all();
|
|
2573
|
+
return rows2.map(mapRow11);
|
|
2574
|
+
}
|
|
2575
|
+
async get(id) {
|
|
2576
|
+
const row = this.db.prepare(`SELECT * FROM lattice_oidc_identity_claims WHERE id = ?`).get(id);
|
|
2577
|
+
return row ? mapRow11(row) : null;
|
|
2578
|
+
}
|
|
2579
|
+
async getPendingBySubject(providerId, issuer, subject, now) {
|
|
2580
|
+
const row = this.db.prepare(
|
|
2581
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2582
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?
|
|
2583
|
+
AND status = 'pending' AND expires_at > ?`
|
|
2584
|
+
).get(providerId, issuer, subject, now.toISOString());
|
|
2585
|
+
return row ? mapRow11(row) : null;
|
|
2586
|
+
}
|
|
2587
|
+
async create(input) {
|
|
2588
|
+
const now = /* @__PURE__ */ new Date();
|
|
2589
|
+
const existing = this.db.prepare(
|
|
2590
|
+
`SELECT * FROM lattice_oidc_identity_claims
|
|
2591
|
+
WHERE provider_id = ? AND issuer = ? AND subject = ?
|
|
2592
|
+
AND status = 'pending'`
|
|
2593
|
+
).get(input.providerId, input.issuer, input.subject);
|
|
2594
|
+
if (existing) {
|
|
2595
|
+
if (parseISO(existing.expires_at).getTime() > now.getTime()) {
|
|
2596
|
+
throw new OidcIdentityClaimConflictError(
|
|
2597
|
+
input.providerId,
|
|
2598
|
+
input.issuer,
|
|
2599
|
+
input.subject
|
|
2600
|
+
);
|
|
2601
|
+
}
|
|
2602
|
+
this.db.prepare(
|
|
2603
|
+
`UPDATE lattice_oidc_identity_claims
|
|
2604
|
+
SET status = 'expired', updated_at = ?
|
|
2605
|
+
WHERE id = ?`
|
|
2606
|
+
).run(nowISO(), existing.id);
|
|
2607
|
+
}
|
|
2608
|
+
const timestamp2 = now.toISOString();
|
|
2609
|
+
try {
|
|
2610
|
+
this.db.prepare(
|
|
2611
|
+
`INSERT INTO lattice_oidc_identity_claims
|
|
2612
|
+
(id, provider_id, issuer, subject, email, name, picture, status,
|
|
2613
|
+
created_at, updated_at, expires_at, reviewed_by, reviewed_at,
|
|
2614
|
+
linked_user_id, source, invite_link_id, requested_user_id,
|
|
2615
|
+
requested_platform_role, requested_tenant_id, requested_tenant_role)
|
|
2616
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, NULL, NULL, NULL,
|
|
2617
|
+
?, ?, ?, ?, ?, ?)`
|
|
2618
|
+
).run(
|
|
2619
|
+
input.id,
|
|
2620
|
+
input.providerId,
|
|
2621
|
+
input.issuer,
|
|
2622
|
+
input.subject,
|
|
2623
|
+
normalizeOidcIdentityEmail(input.email),
|
|
2624
|
+
input.name ?? null,
|
|
2625
|
+
input.picture ?? null,
|
|
2626
|
+
timestamp2,
|
|
2627
|
+
timestamp2,
|
|
2628
|
+
input.expiresAt.toISOString(),
|
|
2629
|
+
input.source ?? null,
|
|
2630
|
+
input.inviteLinkId ?? null,
|
|
2631
|
+
input.requestedUserId ?? null,
|
|
2632
|
+
input.requestedPlatformRole ?? null,
|
|
2633
|
+
input.requestedTenantId ?? null,
|
|
2634
|
+
input.requestedTenantRole ?? null
|
|
2635
|
+
);
|
|
2636
|
+
} catch (error) {
|
|
2637
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2638
|
+
if (message.toLowerCase().includes("unique")) {
|
|
2639
|
+
throw new OidcIdentityClaimConflictError(
|
|
2640
|
+
input.providerId,
|
|
2641
|
+
input.issuer,
|
|
2642
|
+
input.subject
|
|
2643
|
+
);
|
|
2644
|
+
}
|
|
2645
|
+
throw error;
|
|
2646
|
+
}
|
|
2647
|
+
const stored = await this.get(input.id);
|
|
2648
|
+
if (!stored) throw new Error("OIDC identity claim was not persisted");
|
|
2649
|
+
return stored;
|
|
2650
|
+
}
|
|
2651
|
+
async updatePending(id, updates, now) {
|
|
2652
|
+
const sets = [];
|
|
2653
|
+
const params = [];
|
|
2654
|
+
if (updates.email !== void 0) {
|
|
2655
|
+
sets.push("email = ?");
|
|
2656
|
+
params.push(normalizeOidcIdentityEmail(updates.email));
|
|
2657
|
+
}
|
|
2658
|
+
if (updates.name !== void 0) {
|
|
2659
|
+
sets.push("name = ?");
|
|
2660
|
+
params.push(updates.name);
|
|
2661
|
+
}
|
|
2662
|
+
if (updates.picture !== void 0) {
|
|
2663
|
+
sets.push("picture = ?");
|
|
2664
|
+
params.push(updates.picture);
|
|
2665
|
+
}
|
|
2666
|
+
if (sets.length === 0) return this.get(id);
|
|
2667
|
+
sets.push("updated_at = ?");
|
|
2668
|
+
params.push(now.toISOString(), id);
|
|
2669
|
+
const result = this.db.prepare(
|
|
2670
|
+
`UPDATE lattice_oidc_identity_claims SET ${sets.join(", ")}
|
|
2671
|
+
WHERE id = ? AND status = 'pending'`
|
|
2672
|
+
).run(...params);
|
|
2673
|
+
return result.changes > 0 ? this.get(id) : null;
|
|
2674
|
+
}
|
|
2675
|
+
async approve(id, approval, now) {
|
|
2676
|
+
const result = this.db.prepare(
|
|
2677
|
+
`UPDATE lattice_oidc_identity_claims
|
|
2678
|
+
SET status = 'approved', reviewed_by = ?, reviewed_at = ?,
|
|
2679
|
+
linked_user_id = ?, updated_at = ?
|
|
2680
|
+
WHERE id = ? AND status = 'pending'`
|
|
2681
|
+
).run(
|
|
2682
|
+
approval.reviewedBy,
|
|
2683
|
+
now.toISOString(),
|
|
2684
|
+
approval.linkedUserId,
|
|
2685
|
+
now.toISOString(),
|
|
2686
|
+
id
|
|
2687
|
+
);
|
|
2688
|
+
return result.changes > 0 ? this.get(id) : null;
|
|
2689
|
+
}
|
|
2690
|
+
async reject(id, reviewedBy, now) {
|
|
2691
|
+
const result = this.db.prepare(
|
|
2692
|
+
`UPDATE lattice_oidc_identity_claims
|
|
2693
|
+
SET status = 'rejected', reviewed_by = ?, reviewed_at = ?, updated_at = ?
|
|
2694
|
+
WHERE id = ? AND status = 'pending'`
|
|
2695
|
+
).run(reviewedBy, now.toISOString(), now.toISOString(), id);
|
|
2696
|
+
return result.changes > 0 ? this.get(id) : null;
|
|
2697
|
+
}
|
|
2698
|
+
async delete(id) {
|
|
2699
|
+
const result = this.db.prepare(`DELETE FROM lattice_oidc_identity_claims WHERE id = ?`).run(id);
|
|
2700
|
+
return result.changes > 0;
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// src/stores/LocalInviteLinkStore.ts
|
|
2705
|
+
import { encrypt as encrypt2, safeDecrypt as safeDecrypt2 } from "@axiom-lattice/core";
|
|
2706
|
+
import {
|
|
2707
|
+
normalizeInviteLinkEmail
|
|
2708
|
+
} from "@axiom-lattice/protocols";
|
|
2709
|
+
var DDL14 = `
|
|
2710
|
+
CREATE TABLE IF NOT EXISTS lattice_invite_links (
|
|
2711
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2712
|
+
scope TEXT NOT NULL,
|
|
2713
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
2714
|
+
token_encrypted TEXT NOT NULL,
|
|
2715
|
+
email TEXT,
|
|
2716
|
+
platform_role TEXT,
|
|
2717
|
+
tenant_id TEXT,
|
|
2718
|
+
tenant_role TEXT,
|
|
2719
|
+
created_by TEXT,
|
|
2720
|
+
created_at TEXT NOT NULL,
|
|
2721
|
+
updated_at TEXT NOT NULL,
|
|
2722
|
+
expires_at TEXT NOT NULL,
|
|
2723
|
+
max_uses INTEGER NOT NULL,
|
|
2724
|
+
used_count INTEGER NOT NULL,
|
|
2725
|
+
revoked_at TEXT
|
|
2726
|
+
);
|
|
2727
|
+
CREATE UNIQUE INDEX IF NOT EXISTS lattice_invite_links_token_hash
|
|
2728
|
+
ON lattice_invite_links (token_hash);
|
|
2729
|
+
`;
|
|
2730
|
+
function mapRow12(row) {
|
|
2731
|
+
return {
|
|
2732
|
+
id: row.id,
|
|
2733
|
+
scope: row.scope,
|
|
2734
|
+
token: safeDecrypt2(
|
|
2735
|
+
row.token_encrypted,
|
|
2736
|
+
`Invite link "${row.id}" token`
|
|
2737
|
+
),
|
|
2738
|
+
tokenHash: row.token_hash,
|
|
2739
|
+
...row.email !== null ? { email: row.email } : {},
|
|
2740
|
+
...row.platform_role !== null ? { platformRole: row.platform_role } : {},
|
|
2741
|
+
...row.tenant_id !== null ? { tenantId: row.tenant_id } : {},
|
|
2742
|
+
...row.tenant_role !== null ? { tenantRole: row.tenant_role } : {},
|
|
2743
|
+
...row.created_by !== null ? { createdBy: row.created_by } : {},
|
|
2744
|
+
createdAt: parseISO(row.created_at),
|
|
2745
|
+
updatedAt: parseISO(row.updated_at),
|
|
2746
|
+
expiresAt: parseISO(row.expires_at),
|
|
2747
|
+
maxUses: Number(row.max_uses),
|
|
2748
|
+
usedCount: Number(row.used_count),
|
|
2749
|
+
...row.revoked_at !== null ? { revokedAt: parseISO(row.revoked_at) } : {}
|
|
2750
|
+
};
|
|
2751
|
+
}
|
|
2752
|
+
var LocalInviteLinkStore = class {
|
|
2753
|
+
constructor(db) {
|
|
2754
|
+
this.db = db;
|
|
2755
|
+
ensureTable(db, DDL14);
|
|
2756
|
+
}
|
|
2757
|
+
async list() {
|
|
2758
|
+
const rows2 = this.db.prepare(
|
|
2759
|
+
`SELECT * FROM lattice_invite_links
|
|
2760
|
+
ORDER BY created_at DESC, id DESC`
|
|
2761
|
+
).all();
|
|
2762
|
+
return rows2.map(mapRow12);
|
|
2763
|
+
}
|
|
2764
|
+
async get(id) {
|
|
2765
|
+
const row = this.db.prepare(`SELECT * FROM lattice_invite_links WHERE id = ?`).get(id);
|
|
2766
|
+
return row ? mapRow12(row) : null;
|
|
2767
|
+
}
|
|
2768
|
+
async getByTokenHash(tokenHash) {
|
|
2769
|
+
const row = this.db.prepare(`SELECT * FROM lattice_invite_links WHERE token_hash = ?`).get(tokenHash);
|
|
2770
|
+
return row ? mapRow12(row) : null;
|
|
2771
|
+
}
|
|
2772
|
+
async create(input) {
|
|
2773
|
+
const now = nowISO();
|
|
2774
|
+
this.db.prepare(
|
|
2775
|
+
`INSERT INTO lattice_invite_links
|
|
2776
|
+
(id, scope, token_hash, token_encrypted, email, platform_role,
|
|
2777
|
+
tenant_id, tenant_role, created_by, created_at, updated_at,
|
|
2778
|
+
expires_at, max_uses, used_count, revoked_at)
|
|
2779
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, NULL)`
|
|
2780
|
+
).run(
|
|
2781
|
+
input.id,
|
|
2782
|
+
input.scope,
|
|
2783
|
+
input.tokenHash,
|
|
2784
|
+
encrypt2(input.token),
|
|
2785
|
+
input.email ? normalizeInviteLinkEmail(input.email) : null,
|
|
2786
|
+
input.platformRole ?? null,
|
|
2787
|
+
input.tenantId ?? null,
|
|
2788
|
+
input.tenantRole ?? null,
|
|
2789
|
+
input.createdBy ?? null,
|
|
2790
|
+
now,
|
|
2791
|
+
now,
|
|
2792
|
+
input.expiresAt.toISOString(),
|
|
2793
|
+
input.maxUses
|
|
2794
|
+
);
|
|
2795
|
+
const stored = await this.get(input.id);
|
|
2796
|
+
if (!stored) throw new Error("Invite link was not persisted");
|
|
2797
|
+
return stored;
|
|
2798
|
+
}
|
|
2799
|
+
async consume(tokenHash, now) {
|
|
2800
|
+
const result = this.db.prepare(
|
|
2801
|
+
`UPDATE lattice_invite_links
|
|
2802
|
+
SET used_count = used_count + 1, updated_at = ?
|
|
2803
|
+
WHERE token_hash = ?
|
|
2804
|
+
AND revoked_at IS NULL
|
|
2805
|
+
AND expires_at > ?
|
|
2806
|
+
AND used_count < max_uses`
|
|
2807
|
+
).run(now.toISOString(), tokenHash, now.toISOString());
|
|
2808
|
+
return result.changes > 0 ? this.getByTokenHash(tokenHash) : null;
|
|
2809
|
+
}
|
|
2810
|
+
async revoke(id, now) {
|
|
2811
|
+
const result = this.db.prepare(
|
|
2812
|
+
`UPDATE lattice_invite_links
|
|
2813
|
+
SET revoked_at = ?, updated_at = ?
|
|
2814
|
+
WHERE id = ? AND revoked_at IS NULL`
|
|
2815
|
+
).run(now.toISOString(), now.toISOString(), id);
|
|
2816
|
+
return result.changes > 0 ? this.get(id) : this.get(id);
|
|
2817
|
+
}
|
|
2818
|
+
};
|
|
2819
|
+
|
|
2820
|
+
// src/stores/LocalPlatformSettingsStore.ts
|
|
2821
|
+
import {
|
|
2822
|
+
PlatformSettingsVersionConflictError
|
|
2823
|
+
} from "@axiom-lattice/protocols";
|
|
2824
|
+
var SETTINGS_ID = "default";
|
|
2825
|
+
var COLUMNS = "id, document, version, updated_by, updated_at";
|
|
2826
|
+
function normalizeUpdatedBy(updatedBy) {
|
|
2827
|
+
const trimmed = updatedBy?.trim();
|
|
2828
|
+
return trimmed ? trimmed : null;
|
|
2829
|
+
}
|
|
2830
|
+
var DDL15 = `
|
|
2831
|
+
CREATE TABLE IF NOT EXISTS lattice_platform_settings (
|
|
2832
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
2833
|
+
document TEXT NOT NULL,
|
|
2834
|
+
version INTEGER NOT NULL,
|
|
2835
|
+
updated_by TEXT,
|
|
2836
|
+
updated_at TEXT NOT NULL
|
|
2837
|
+
);
|
|
2838
|
+
`;
|
|
2839
|
+
function mapRow13(row) {
|
|
2840
|
+
const document = JSON.parse(row.document);
|
|
2841
|
+
return {
|
|
2842
|
+
...document,
|
|
2843
|
+
version: Number(row.version),
|
|
2844
|
+
...row.updated_by !== null ? { updatedBy: row.updated_by } : {},
|
|
2845
|
+
updatedAt: parseISO(row.updated_at)
|
|
2846
|
+
};
|
|
2847
|
+
}
|
|
2848
|
+
var LocalPlatformSettingsStore = class {
|
|
2849
|
+
constructor(db) {
|
|
2850
|
+
this.db = db;
|
|
2851
|
+
ensureTable(db, DDL15);
|
|
2852
|
+
}
|
|
2853
|
+
async get() {
|
|
2854
|
+
const row = this.db.prepare(
|
|
2855
|
+
`SELECT ${COLUMNS} FROM lattice_platform_settings WHERE id = ?`
|
|
2856
|
+
).get(SETTINGS_ID);
|
|
2857
|
+
return row ? mapRow13(row) : null;
|
|
2858
|
+
}
|
|
2859
|
+
async save(document, expectedVersion, updatedBy) {
|
|
2860
|
+
const version = expectedVersion + 1;
|
|
2861
|
+
const updatedAt = nowISO();
|
|
2862
|
+
const result = expectedVersion === 0 ? this.db.prepare(
|
|
2863
|
+
`INSERT INTO lattice_platform_settings
|
|
2864
|
+
(id, document, version, updated_by, updated_at)
|
|
2865
|
+
VALUES (?, ?, ?, ?, ?)
|
|
2866
|
+
ON CONFLICT (id) DO NOTHING`
|
|
2867
|
+
).run(
|
|
2868
|
+
SETTINGS_ID,
|
|
2869
|
+
JSON.stringify(document),
|
|
2870
|
+
version,
|
|
2871
|
+
normalizeUpdatedBy(updatedBy),
|
|
2872
|
+
updatedAt
|
|
2873
|
+
) : this.db.prepare(
|
|
2874
|
+
`UPDATE lattice_platform_settings
|
|
2875
|
+
SET document = ?, version = ?, updated_by = ?, updated_at = ?
|
|
2876
|
+
WHERE id = ? AND version = ?`
|
|
2877
|
+
).run(
|
|
2878
|
+
JSON.stringify(document),
|
|
2879
|
+
version,
|
|
2880
|
+
normalizeUpdatedBy(updatedBy),
|
|
2881
|
+
updatedAt,
|
|
2882
|
+
SETTINGS_ID,
|
|
2883
|
+
expectedVersion
|
|
2884
|
+
);
|
|
2885
|
+
if (result.changes === 0) {
|
|
2886
|
+
const actual = this.db.prepare(`SELECT version FROM lattice_platform_settings WHERE id = ?`).get(SETTINGS_ID);
|
|
2887
|
+
throw new PlatformSettingsVersionConflictError(
|
|
2888
|
+
expectedVersion,
|
|
2889
|
+
actual ? Number(actual.version) : 0
|
|
2890
|
+
);
|
|
2891
|
+
}
|
|
2892
|
+
const stored = await this.get();
|
|
2893
|
+
if (!stored) throw new Error("Platform settings were not persisted");
|
|
2894
|
+
return stored;
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
|
|
2898
|
+
// src/stores/LocalDatabaseConfigStore.ts
|
|
2899
|
+
import { encrypt as encrypt3, decrypt } from "@axiom-lattice/core";
|
|
2900
|
+
var DDL16 = `
|
|
2046
2901
|
CREATE TABLE IF NOT EXISTS lt_database_configs (
|
|
2047
2902
|
id TEXT NOT NULL,
|
|
2048
2903
|
tenant_id TEXT NOT NULL,
|
|
@@ -2059,7 +2914,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_dbconfig_key ON lt_database_configs(ten
|
|
|
2059
2914
|
var LocalDatabaseConfigStore = class {
|
|
2060
2915
|
constructor(db) {
|
|
2061
2916
|
this.db = db;
|
|
2062
|
-
ensureTable(db,
|
|
2917
|
+
ensureTable(db, DDL16);
|
|
2063
2918
|
}
|
|
2064
2919
|
async getAllConfigs(tenantId) {
|
|
2065
2920
|
const rows2 = this.db.prepare(
|
|
@@ -2174,15 +3029,15 @@ function mapRowToEntry(row) {
|
|
|
2174
3029
|
}
|
|
2175
3030
|
function encryptPasswordInConfig(config) {
|
|
2176
3031
|
if (config.password) {
|
|
2177
|
-
return { ...config, password:
|
|
3032
|
+
return { ...config, password: encrypt3(config.password) };
|
|
2178
3033
|
}
|
|
2179
3034
|
return config;
|
|
2180
3035
|
}
|
|
2181
3036
|
|
|
2182
3037
|
// src/stores/LocalConnectionStore.ts
|
|
2183
3038
|
import { v4 as uuid } from "uuid";
|
|
2184
|
-
import { encryptConfigFields, decryptConfigFields, encrypt as
|
|
2185
|
-
var
|
|
3039
|
+
import { encryptConfigFields, decryptConfigFields, encrypt as encrypt4, isEncryptedValue } from "@axiom-lattice/core";
|
|
3040
|
+
var DDL17 = `
|
|
2186
3041
|
CREATE TABLE IF NOT EXISTS connection_configs (
|
|
2187
3042
|
id TEXT NOT NULL,
|
|
2188
3043
|
tenant_id TEXT NOT NULL,
|
|
@@ -2213,7 +3068,7 @@ function parseSecretFields(raw) {
|
|
|
2213
3068
|
var LocalConnectionStore = class {
|
|
2214
3069
|
constructor(db) {
|
|
2215
3070
|
this.db = db;
|
|
2216
|
-
ensureTable(db,
|
|
3071
|
+
ensureTable(db, DDL17);
|
|
2217
3072
|
this.ensureColumn("connection_configs", "secret_fields", "secret_fields TEXT");
|
|
2218
3073
|
this.reencryptLegacySecrets();
|
|
2219
3074
|
}
|
|
@@ -2250,7 +3105,7 @@ var LocalConnectionStore = class {
|
|
|
2250
3105
|
for (const field of secretFields) {
|
|
2251
3106
|
const value = config[field];
|
|
2252
3107
|
if (typeof value === "string" && value.length > 0 && !isEncryptedValue(value)) {
|
|
2253
|
-
config[field] =
|
|
3108
|
+
config[field] = encrypt4(value);
|
|
2254
3109
|
changed = true;
|
|
2255
3110
|
}
|
|
2256
3111
|
}
|
|
@@ -2355,8 +3210,8 @@ var LocalConnectionStore = class {
|
|
|
2355
3210
|
};
|
|
2356
3211
|
|
|
2357
3212
|
// src/stores/LocalMetricsServerConfigStore.ts
|
|
2358
|
-
import { encrypt as
|
|
2359
|
-
var
|
|
3213
|
+
import { encrypt as encrypt5, isEncryptedValue as isEncryptedValue2, safeDecrypt as safeDecrypt3 } from "@axiom-lattice/core";
|
|
3214
|
+
var DDL18 = `
|
|
2360
3215
|
CREATE TABLE IF NOT EXISTS lt_metrics_configs (
|
|
2361
3216
|
id TEXT NOT NULL,
|
|
2362
3217
|
tenant_id TEXT NOT NULL,
|
|
@@ -2373,7 +3228,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_metrics_key ON lt_metrics_configs(tenan
|
|
|
2373
3228
|
var LocalMetricsServerConfigStore = class {
|
|
2374
3229
|
constructor(db) {
|
|
2375
3230
|
this.db = db;
|
|
2376
|
-
ensureTable(db,
|
|
3231
|
+
ensureTable(db, DDL18);
|
|
2377
3232
|
}
|
|
2378
3233
|
async getAllConfigs(tenantId) {
|
|
2379
3234
|
const rows2 = this.db.prepare(
|
|
@@ -2480,23 +3335,23 @@ function mapRowToEntry2(row) {
|
|
|
2480
3335
|
}
|
|
2481
3336
|
function encryptSecretsInConfig(config) {
|
|
2482
3337
|
const configCopy = { ...config };
|
|
2483
|
-
if (configCopy.apiKey) configCopy.apiKey =
|
|
2484
|
-
if (configCopy.password) configCopy.password =
|
|
3338
|
+
if (configCopy.apiKey) configCopy.apiKey = encrypt5(configCopy.apiKey);
|
|
3339
|
+
if (configCopy.password) configCopy.password = encrypt5(configCopy.password);
|
|
2485
3340
|
return configCopy;
|
|
2486
3341
|
}
|
|
2487
3342
|
function decryptSecretsInConfig(config) {
|
|
2488
3343
|
if (config.apiKey && isEncryptedValue2(config.apiKey)) {
|
|
2489
|
-
config.apiKey =
|
|
3344
|
+
config.apiKey = safeDecrypt3(config.apiKey);
|
|
2490
3345
|
}
|
|
2491
3346
|
if (config.password && isEncryptedValue2(config.password)) {
|
|
2492
|
-
config.password =
|
|
3347
|
+
config.password = safeDecrypt3(config.password);
|
|
2493
3348
|
}
|
|
2494
3349
|
return config;
|
|
2495
3350
|
}
|
|
2496
3351
|
|
|
2497
3352
|
// src/stores/LocalMcpServerConfigStore.ts
|
|
2498
|
-
import { encrypt as
|
|
2499
|
-
var
|
|
3353
|
+
import { encrypt as encrypt6, safeDecrypt as safeDecrypt4 } from "@axiom-lattice/core";
|
|
3354
|
+
var DDL19 = `
|
|
2500
3355
|
CREATE TABLE IF NOT EXISTS lt_mcp_configs (
|
|
2501
3356
|
id TEXT NOT NULL,
|
|
2502
3357
|
tenant_id TEXT NOT NULL,
|
|
@@ -2516,7 +3371,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_lt_mcp_key ON lt_mcp_configs(tenant_id, ke
|
|
|
2516
3371
|
var LocalMcpServerConfigStore = class {
|
|
2517
3372
|
constructor(db) {
|
|
2518
3373
|
this.db = db;
|
|
2519
|
-
ensureTable(db,
|
|
3374
|
+
ensureTable(db, DDL19);
|
|
2520
3375
|
}
|
|
2521
3376
|
async getAllConfigs(tenantId) {
|
|
2522
3377
|
const rows2 = this.db.prepare(
|
|
@@ -2644,14 +3499,14 @@ function mapRowToEntry3(row) {
|
|
|
2644
3499
|
if (config.env && row.is_env_encrypted) {
|
|
2645
3500
|
const decryptedEnv = {};
|
|
2646
3501
|
for (const [key, value] of Object.entries(config.env)) {
|
|
2647
|
-
decryptedEnv[key] =
|
|
3502
|
+
decryptedEnv[key] = safeDecrypt4(value);
|
|
2648
3503
|
}
|
|
2649
3504
|
config.env = decryptedEnv;
|
|
2650
3505
|
}
|
|
2651
3506
|
if (config.headers && row.is_env_encrypted) {
|
|
2652
3507
|
const decryptedHeaders = {};
|
|
2653
3508
|
for (const [key, value] of Object.entries(config.headers)) {
|
|
2654
|
-
decryptedHeaders[key] =
|
|
3509
|
+
decryptedHeaders[key] = safeDecrypt4(value);
|
|
2655
3510
|
}
|
|
2656
3511
|
config.headers = decryptedHeaders;
|
|
2657
3512
|
}
|
|
@@ -2675,7 +3530,7 @@ function encryptEnvInConfig(config) {
|
|
|
2675
3530
|
if (configCopy.env && Object.keys(configCopy.env).length > 0) {
|
|
2676
3531
|
const encryptedEnv = {};
|
|
2677
3532
|
for (const [key, value] of Object.entries(configCopy.env)) {
|
|
2678
|
-
encryptedEnv[key] =
|
|
3533
|
+
encryptedEnv[key] = encrypt6(value);
|
|
2679
3534
|
}
|
|
2680
3535
|
configCopy.env = encryptedEnv;
|
|
2681
3536
|
isEnvEncrypted = true;
|
|
@@ -2683,7 +3538,7 @@ function encryptEnvInConfig(config) {
|
|
|
2683
3538
|
if (configCopy.headers && Object.keys(configCopy.headers).length > 0) {
|
|
2684
3539
|
const encryptedHeaders = {};
|
|
2685
3540
|
for (const [key, value] of Object.entries(configCopy.headers)) {
|
|
2686
|
-
encryptedHeaders[key] =
|
|
3541
|
+
encryptedHeaders[key] = encrypt6(value);
|
|
2687
3542
|
}
|
|
2688
3543
|
configCopy.headers = encryptedHeaders;
|
|
2689
3544
|
isEnvEncrypted = true;
|
|
@@ -2692,8 +3547,8 @@ function encryptEnvInConfig(config) {
|
|
|
2692
3547
|
}
|
|
2693
3548
|
|
|
2694
3549
|
// src/stores/LocalModelProviderStore.ts
|
|
2695
|
-
import { encrypt as
|
|
2696
|
-
var
|
|
3550
|
+
import { encrypt as encrypt7, safeDecrypt as safeDecrypt5 } from "@axiom-lattice/core";
|
|
3551
|
+
var DDL20 = `
|
|
2697
3552
|
CREATE TABLE IF NOT EXISTS lt_model_providers (
|
|
2698
3553
|
id TEXT NOT NULL,
|
|
2699
3554
|
tenant_id TEXT NOT NULL,
|
|
@@ -2738,7 +3593,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_model_provider_models_tenant
|
|
|
2738
3593
|
var LocalModelProviderStore = class {
|
|
2739
3594
|
constructor(db) {
|
|
2740
3595
|
this.db = db;
|
|
2741
|
-
ensureTable(db,
|
|
3596
|
+
ensureTable(db, DDL20);
|
|
2742
3597
|
this.ensureColumn(
|
|
2743
3598
|
"lt_model_providers",
|
|
2744
3599
|
"api_style",
|
|
@@ -2808,7 +3663,7 @@ var LocalModelProviderStore = class {
|
|
|
2808
3663
|
// Phase 1 pins the LLM provider (ADR-138 decision 7b)
|
|
2809
3664
|
"openai",
|
|
2810
3665
|
data.baseURL,
|
|
2811
|
-
data.apiKey ?
|
|
3666
|
+
data.apiKey ? encrypt7(data.apiKey) : null,
|
|
2812
3667
|
data.apiKey ? data.apiKey.slice(-4) : null,
|
|
2813
3668
|
data.enabled === false ? 0 : 1,
|
|
2814
3669
|
now,
|
|
@@ -2843,7 +3698,7 @@ var LocalModelProviderStore = class {
|
|
|
2843
3698
|
set("api_key_enc", null);
|
|
2844
3699
|
set("api_key_hint", null);
|
|
2845
3700
|
} else if (updates.apiKey) {
|
|
2846
|
-
set("api_key_enc",
|
|
3701
|
+
set("api_key_enc", encrypt7(updates.apiKey));
|
|
2847
3702
|
set("api_key_hint", updates.apiKey.slice(-4));
|
|
2848
3703
|
}
|
|
2849
3704
|
if (fields.length === 0) {
|
|
@@ -2978,7 +3833,7 @@ var LocalModelProviderStore = class {
|
|
|
2978
3833
|
function mapRowToEntry4(row) {
|
|
2979
3834
|
let apiKey;
|
|
2980
3835
|
if (row.api_key_enc) {
|
|
2981
|
-
apiKey =
|
|
3836
|
+
apiKey = safeDecrypt5(row.api_key_enc);
|
|
2982
3837
|
}
|
|
2983
3838
|
return {
|
|
2984
3839
|
id: row.id,
|
|
@@ -3018,7 +3873,7 @@ function mapRowToModel(row) {
|
|
|
3018
3873
|
|
|
3019
3874
|
// src/stores/LocalWorkflowTrackingStore.ts
|
|
3020
3875
|
import { randomUUID } from "crypto";
|
|
3021
|
-
var
|
|
3876
|
+
var DDL21 = `
|
|
3022
3877
|
CREATE TABLE IF NOT EXISTS lt_workflow_runs (
|
|
3023
3878
|
id TEXT PRIMARY KEY,
|
|
3024
3879
|
tenant_id TEXT NOT NULL,
|
|
@@ -3065,7 +3920,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_ws_type ON lt_workflow_steps(run_id, step_type
|
|
|
3065
3920
|
var LocalWorkflowTrackingStore = class {
|
|
3066
3921
|
constructor(db) {
|
|
3067
3922
|
this.db = db;
|
|
3068
|
-
ensureTable(db,
|
|
3923
|
+
ensureTable(db, DDL21);
|
|
3069
3924
|
this.ensureColumn("lt_workflow_steps", "thread_id", "thread_id TEXT");
|
|
3070
3925
|
}
|
|
3071
3926
|
/** Add a column if it does not exist (SQLite version compatible). */
|
|
@@ -3364,7 +4219,7 @@ function mapRowToStep(row) {
|
|
|
3364
4219
|
|
|
3365
4220
|
// src/stores/LocalEvalStore.ts
|
|
3366
4221
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
3367
|
-
var
|
|
4222
|
+
var DDL22 = `
|
|
3368
4223
|
CREATE TABLE IF NOT EXISTS lt_eval_projects (
|
|
3369
4224
|
id TEXT NOT NULL,
|
|
3370
4225
|
tenant_id TEXT NOT NULL,
|
|
@@ -3475,7 +4330,7 @@ function parseOptionalJson(val) {
|
|
|
3475
4330
|
var LocalEvalStore = class {
|
|
3476
4331
|
constructor(db) {
|
|
3477
4332
|
this.db = db;
|
|
3478
|
-
ensureTable(db,
|
|
4333
|
+
ensureTable(db, DDL22);
|
|
3479
4334
|
this.ensureColumn("lt_eval_runs", "interrupted_cases", "interrupted_cases INTEGER NOT NULL DEFAULT 0");
|
|
3480
4335
|
this.ensureColumn("lt_eval_run_results", "interrupted", "interrupted INTEGER NOT NULL DEFAULT 0");
|
|
3481
4336
|
this.ensureColumn("lt_eval_cases", "interrupt_policy", "interrupt_policy TEXT");
|
|
@@ -4116,7 +4971,7 @@ function mapConflict(row) {
|
|
|
4116
4971
|
}
|
|
4117
4972
|
|
|
4118
4973
|
// src/stores/LocalChannelBindingStore.ts
|
|
4119
|
-
var
|
|
4974
|
+
var DDL23 = `
|
|
4120
4975
|
CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
4121
4976
|
id TEXT PRIMARY KEY,
|
|
4122
4977
|
channel TEXT NOT NULL,
|
|
@@ -4138,7 +4993,7 @@ CREATE TABLE IF NOT EXISTS lt_channel_bindings (
|
|
|
4138
4993
|
var LocalChannelBindingStore = class {
|
|
4139
4994
|
constructor(db) {
|
|
4140
4995
|
this.db = db;
|
|
4141
|
-
ensureTable(db,
|
|
4996
|
+
ensureTable(db, DDL23);
|
|
4142
4997
|
ensureChannelBindingSubjectIndex(db);
|
|
4143
4998
|
}
|
|
4144
4999
|
async findById(tenantId, id) {
|
|
@@ -4318,7 +5173,7 @@ function mapRowToBinding(row) {
|
|
|
4318
5173
|
}
|
|
4319
5174
|
|
|
4320
5175
|
// src/stores/LocalChannelInstallationStore.ts
|
|
4321
|
-
var
|
|
5176
|
+
var DDL24 = `
|
|
4322
5177
|
CREATE TABLE IF NOT EXISTS lt_channel_installations (
|
|
4323
5178
|
id TEXT PRIMARY KEY,
|
|
4324
5179
|
tenant_id TEXT NOT NULL,
|
|
@@ -4336,13 +5191,13 @@ CREATE INDEX IF NOT EXISTS idx_lt_ci_tenant ON lt_channel_installations(tenant_i
|
|
|
4336
5191
|
var LocalChannelInstallationStore = class {
|
|
4337
5192
|
constructor(db) {
|
|
4338
5193
|
this.db = db;
|
|
4339
|
-
ensureTable(db,
|
|
5194
|
+
ensureTable(db, DDL24);
|
|
4340
5195
|
}
|
|
4341
5196
|
async getInstallationById(installationId) {
|
|
4342
5197
|
const row = this.db.prepare(
|
|
4343
5198
|
`SELECT * FROM lt_channel_installations WHERE id = ?`
|
|
4344
5199
|
).get(installationId);
|
|
4345
|
-
return row ?
|
|
5200
|
+
return row ? mapRow14(row) : null;
|
|
4346
5201
|
}
|
|
4347
5202
|
async getInstallationsByTenant(tenantId, channel) {
|
|
4348
5203
|
let rows2;
|
|
@@ -4355,7 +5210,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4355
5210
|
`SELECT * FROM lt_channel_installations WHERE tenant_id = ? ORDER BY created_at DESC`
|
|
4356
5211
|
).all(tenantId);
|
|
4357
5212
|
}
|
|
4358
|
-
return rows2.map(
|
|
5213
|
+
return rows2.map(mapRow14);
|
|
4359
5214
|
}
|
|
4360
5215
|
async getAllInstallations(channel) {
|
|
4361
5216
|
let rows2;
|
|
@@ -4368,7 +5223,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4368
5223
|
`SELECT * FROM lt_channel_installations ORDER BY created_at DESC`
|
|
4369
5224
|
).all();
|
|
4370
5225
|
}
|
|
4371
|
-
return rows2.map(
|
|
5226
|
+
return rows2.map(mapRow14);
|
|
4372
5227
|
}
|
|
4373
5228
|
async createInstallation(tenantId, installationId, data) {
|
|
4374
5229
|
const now = nowISO();
|
|
@@ -4444,7 +5299,7 @@ var LocalChannelInstallationStore = class {
|
|
|
4444
5299
|
return result.changes > 0;
|
|
4445
5300
|
}
|
|
4446
5301
|
};
|
|
4447
|
-
function
|
|
5302
|
+
function mapRow14(row) {
|
|
4448
5303
|
return {
|
|
4449
5304
|
id: row.id,
|
|
4450
5305
|
tenantId: row.tenant_id,
|
|
@@ -4460,9 +5315,9 @@ function mapRow7(row) {
|
|
|
4460
5315
|
}
|
|
4461
5316
|
|
|
4462
5317
|
// src/stores/LocalA2AApiKeyStore.ts
|
|
4463
|
-
import { encrypt as
|
|
5318
|
+
import { encrypt as encrypt8, decrypt as decrypt2, safeDecrypt as safeDecrypt6 } from "@axiom-lattice/core";
|
|
4464
5319
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
4465
|
-
var
|
|
5320
|
+
var DDL25 = `
|
|
4466
5321
|
CREATE TABLE IF NOT EXISTS lt_a2a_api_keys (
|
|
4467
5322
|
id TEXT PRIMARY KEY,
|
|
4468
5323
|
key_value TEXT NOT NULL,
|
|
@@ -4500,7 +5355,7 @@ function parseAssistantIds(raw) {
|
|
|
4500
5355
|
var LocalA2AApiKeyStore = class {
|
|
4501
5356
|
constructor(db) {
|
|
4502
5357
|
this.db = db;
|
|
4503
|
-
ensureTable(db,
|
|
5358
|
+
ensureTable(db, DDL25);
|
|
4504
5359
|
this.ensureColumn("lt_a2a_api_keys", "assistant_ids", "assistant_ids TEXT");
|
|
4505
5360
|
this.ensureColumn("lt_a2a_api_keys", "grants", "grants TEXT");
|
|
4506
5361
|
this.repairManagementIds();
|
|
@@ -4565,7 +5420,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4565
5420
|
this.db.prepare(
|
|
4566
5421
|
`INSERT INTO lt_a2a_api_keys (id, key_value, tenant_id, project_id, assistant_ids, grants, label, created_at, updated_at)
|
|
4567
5422
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
4568
|
-
).run(id,
|
|
5423
|
+
).run(id, encrypt8(key), input.tenantId, input.projectId, input.assistantIds ? JSON.stringify(input.assistantIds) : null, input.grants ? JSON.stringify(input.grants) : null, input.label || null, now, now);
|
|
4569
5424
|
const record2 = {
|
|
4570
5425
|
id,
|
|
4571
5426
|
key,
|
|
@@ -4634,7 +5489,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4634
5489
|
const now = nowISO();
|
|
4635
5490
|
this.db.prepare(
|
|
4636
5491
|
`UPDATE lt_a2a_api_keys SET key_value = ?, updated_at = ? WHERE id = ?`
|
|
4637
|
-
).run(
|
|
5492
|
+
).run(encrypt8(key), now, id);
|
|
4638
5493
|
const row = this.db.prepare(`SELECT * FROM lt_a2a_api_keys WHERE id = ?`).get(id);
|
|
4639
5494
|
if (!row) throw new Error(`A2A API key not found: ${id}`);
|
|
4640
5495
|
const record2 = mapRowToRecord(row);
|
|
@@ -4667,7 +5522,7 @@ var LocalA2AApiKeyStore = class {
|
|
|
4667
5522
|
function mapRowToRecord(row) {
|
|
4668
5523
|
return {
|
|
4669
5524
|
id: row.id,
|
|
4670
|
-
key:
|
|
5525
|
+
key: safeDecrypt6(row.key_value),
|
|
4671
5526
|
tenantId: row.tenant_id,
|
|
4672
5527
|
projectId: row.project_id,
|
|
4673
5528
|
assistantIds: parseAssistantIds(row.assistant_ids),
|
|
@@ -4681,7 +5536,7 @@ function mapRowToRecord(row) {
|
|
|
4681
5536
|
|
|
4682
5537
|
// src/stores/LocalOpenAuditStore.ts
|
|
4683
5538
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
4684
|
-
var
|
|
5539
|
+
var DDL26 = `
|
|
4685
5540
|
CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
4686
5541
|
id TEXT PRIMARY KEY,
|
|
4687
5542
|
tenant_id TEXT NOT NULL,
|
|
@@ -4700,7 +5555,7 @@ CREATE TABLE IF NOT EXISTS lt_open_audit (
|
|
|
4700
5555
|
var LocalOpenAuditStore = class {
|
|
4701
5556
|
constructor(db) {
|
|
4702
5557
|
this.db = db;
|
|
4703
|
-
ensureTable(db,
|
|
5558
|
+
ensureTable(db, DDL26);
|
|
4704
5559
|
}
|
|
4705
5560
|
async query(params) {
|
|
4706
5561
|
const clauses = ["tenant_id = ?"];
|
|
@@ -4775,7 +5630,7 @@ import {
|
|
|
4775
5630
|
parseTrustedRunContext
|
|
4776
5631
|
} from "@axiom-lattice/protocols";
|
|
4777
5632
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
4778
|
-
var
|
|
5633
|
+
var DDL27 = `
|
|
4779
5634
|
CREATE TABLE IF NOT EXISTS lt_thread_message_queue (
|
|
4780
5635
|
id TEXT PRIMARY KEY,
|
|
4781
5636
|
thread_id TEXT NOT NULL,
|
|
@@ -4804,7 +5659,7 @@ var LocalThreadMessageQueueStore = class {
|
|
|
4804
5659
|
constructor(db) {
|
|
4805
5660
|
this.capacityTail = Promise.resolve();
|
|
4806
5661
|
this.db = db;
|
|
4807
|
-
ensureTable(db,
|
|
5662
|
+
ensureTable(db, DDL27);
|
|
4808
5663
|
const columns6 = db.prepare("PRAGMA table_info(lt_thread_message_queue)").all();
|
|
4809
5664
|
const names = new Set(columns6.map(({ name }) => name));
|
|
4810
5665
|
if (!names.has("trusted_run_context")) {
|
|
@@ -5064,7 +5919,7 @@ function rowToMessage(row) {
|
|
|
5064
5919
|
}
|
|
5065
5920
|
|
|
5066
5921
|
// src/stores/LocalSkillStore.ts
|
|
5067
|
-
var
|
|
5922
|
+
var DDL28 = `
|
|
5068
5923
|
CREATE TABLE IF NOT EXISTS lt_skills (
|
|
5069
5924
|
id TEXT NOT NULL,
|
|
5070
5925
|
tenant_id TEXT NOT NULL,
|
|
@@ -5083,7 +5938,7 @@ CREATE TABLE IF NOT EXISTS lt_skills (
|
|
|
5083
5938
|
var LocalSkillStore = class {
|
|
5084
5939
|
constructor(db) {
|
|
5085
5940
|
this.db = db;
|
|
5086
|
-
ensureTable(db,
|
|
5941
|
+
ensureTable(db, DDL28);
|
|
5087
5942
|
}
|
|
5088
5943
|
async getAllSkills(tenantId, _context) {
|
|
5089
5944
|
const rows2 = this.db.prepare(
|
|
@@ -5233,7 +6088,7 @@ function mapRowToSkill(row) {
|
|
|
5233
6088
|
}
|
|
5234
6089
|
|
|
5235
6090
|
// src/stores/LocalScheduleStorage.ts
|
|
5236
|
-
var
|
|
6091
|
+
var DDL29 = `
|
|
5237
6092
|
CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
|
|
5238
6093
|
task_id TEXT PRIMARY KEY,
|
|
5239
6094
|
task_type TEXT NOT NULL,
|
|
@@ -5266,7 +6121,7 @@ CREATE INDEX IF NOT EXISTS idx_lt_st_tenant ON lt_scheduled_tasks(tenant_id);
|
|
|
5266
6121
|
var LocalScheduleStorage = class {
|
|
5267
6122
|
constructor(db) {
|
|
5268
6123
|
this.db = db;
|
|
5269
|
-
ensureTable(db,
|
|
6124
|
+
ensureTable(db, DDL29);
|
|
5270
6125
|
}
|
|
5271
6126
|
async save(task) {
|
|
5272
6127
|
this.db.prepare(
|
|
@@ -5600,7 +6455,7 @@ var NEXT_UPDATED_AT_SQL = `updated_at = CASE
|
|
|
5600
6455
|
THEN strftime('%Y-%m-%dT%H:%M:%fZ', updated_at, '+0.001 seconds')
|
|
5601
6456
|
ELSE ?
|
|
5602
6457
|
END`;
|
|
5603
|
-
var
|
|
6458
|
+
var DDL30 = `
|
|
5604
6459
|
CREATE TABLE IF NOT EXISTS lt_tasks (
|
|
5605
6460
|
id TEXT NOT NULL,
|
|
5606
6461
|
tenant_id TEXT NOT NULL,
|
|
@@ -5673,7 +6528,7 @@ function assertPage(limit, offset = 0) {
|
|
|
5673
6528
|
var LocalTaskStore = class {
|
|
5674
6529
|
constructor(db) {
|
|
5675
6530
|
this.db = db;
|
|
5676
|
-
ensureTable(db,
|
|
6531
|
+
ensureTable(db, DDL30);
|
|
5677
6532
|
this.ensureColumn("lt_tasks", "require_review", "require_review INTEGER DEFAULT 0");
|
|
5678
6533
|
this.ensureColumn("lt_tasks", "dependencies", "dependencies TEXT");
|
|
5679
6534
|
this.ensureColumn("lt_tasks", "result", "result TEXT");
|
|
@@ -6357,7 +7212,7 @@ var PROJECT_LIFECYCLE_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
6357
7212
|
"cancelled",
|
|
6358
7213
|
"reassigned"
|
|
6359
7214
|
]);
|
|
6360
|
-
var
|
|
7215
|
+
var DDL31 = `
|
|
6361
7216
|
CREATE TABLE IF NOT EXISTS lt_task_work_items (
|
|
6362
7217
|
id TEXT NOT NULL,
|
|
6363
7218
|
tenant_id TEXT NOT NULL,
|
|
@@ -6431,7 +7286,7 @@ function assertLifecyclePage(query) {
|
|
|
6431
7286
|
var LocalTaskWorkItemStore = class {
|
|
6432
7287
|
constructor(db) {
|
|
6433
7288
|
this.db = db;
|
|
6434
|
-
ensureTable(db,
|
|
7289
|
+
ensureTable(db, DDL31);
|
|
6435
7290
|
this.ensureColumn("lt_task_work_items", "workspace_id", "workspace_id TEXT");
|
|
6436
7291
|
this.ensureColumn("lt_task_work_items", "project_id", "project_id TEXT");
|
|
6437
7292
|
this.ensureColumn("lt_task_work_items", "event_key", "event_key TEXT");
|
|
@@ -6628,7 +7483,7 @@ var LocalTaskWorkItemStore = class {
|
|
|
6628
7483
|
|
|
6629
7484
|
// src/stores/LocalCapabilityBundleStore.ts
|
|
6630
7485
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
6631
|
-
var
|
|
7486
|
+
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);`;
|
|
6632
7487
|
var duplicateMessage = "Capability bundle key already exists for tenant";
|
|
6633
7488
|
function map(row) {
|
|
6634
7489
|
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() };
|
|
@@ -6649,7 +7504,7 @@ var LocalCapabilityBundleStore = class {
|
|
|
6649
7504
|
*/
|
|
6650
7505
|
constructor(db) {
|
|
6651
7506
|
this.db = db;
|
|
6652
|
-
ensureTable(db,
|
|
7507
|
+
ensureTable(db, DDL32);
|
|
6653
7508
|
}
|
|
6654
7509
|
async listByTenant(tenantId) {
|
|
6655
7510
|
return this.db.prepare("SELECT * FROM lt_capability_bundles WHERE tenant_id = ? ORDER BY created_at").all(tenantId).map(map);
|
|
@@ -6736,6 +7591,13 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
6736
7591
|
user: new LocalUserStore(db),
|
|
6737
7592
|
tenant: new LocalTenantStore(db),
|
|
6738
7593
|
userTenantLink: new LocalUserTenantLinkStore(db),
|
|
7594
|
+
userExternalIdentity: new LocalUserExternalIdentityStore(db),
|
|
7595
|
+
oidcProviderConfig: new LocalOidcProviderConfigStore(db),
|
|
7596
|
+
platformMember: new LocalPlatformMemberStore(db),
|
|
7597
|
+
platformInvitation: new LocalPlatformInvitationStore(db),
|
|
7598
|
+
oidcIdentityClaim: new LocalOidcIdentityClaimStore(db),
|
|
7599
|
+
inviteLink: new LocalInviteLinkStore(db),
|
|
7600
|
+
platformSettings: new LocalPlatformSettingsStore(db),
|
|
6739
7601
|
database: new LocalDatabaseConfigStore(db),
|
|
6740
7602
|
connection: new LocalConnectionStore(db),
|
|
6741
7603
|
metrics: new LocalMetricsServerConfigStore(db),
|
|
@@ -6806,10 +7668,16 @@ export {
|
|
|
6806
7668
|
LocalConnectionStore,
|
|
6807
7669
|
LocalDatabaseConfigStore,
|
|
6808
7670
|
LocalEvalStore,
|
|
7671
|
+
LocalInviteLinkStore,
|
|
6809
7672
|
LocalMcpServerConfigStore,
|
|
6810
7673
|
LocalMetricsServerConfigStore,
|
|
6811
7674
|
LocalModelProviderStore,
|
|
7675
|
+
LocalOidcIdentityClaimStore,
|
|
7676
|
+
LocalOidcProviderConfigStore,
|
|
6812
7677
|
LocalOpenAuditStore,
|
|
7678
|
+
LocalPlatformInvitationStore,
|
|
7679
|
+
LocalPlatformMemberStore,
|
|
7680
|
+
LocalPlatformSettingsStore,
|
|
6813
7681
|
LocalProjectBotMembershipStore,
|
|
6814
7682
|
LocalProjectMembershipStore,
|
|
6815
7683
|
LocalProjectRoomMessageStore,
|
|
@@ -6824,6 +7692,7 @@ export {
|
|
|
6824
7692
|
LocalTenantStore,
|
|
6825
7693
|
LocalThreadMessageQueueStore,
|
|
6826
7694
|
LocalThreadStore,
|
|
7695
|
+
LocalUserExternalIdentityStore,
|
|
6827
7696
|
LocalUserStore,
|
|
6828
7697
|
LocalUserTenantLinkStore,
|
|
6829
7698
|
LocalWorkflowTrackingStore,
|