@axiom-lattice/local-stores 5.3.0 → 5.4.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 +36 -0
- package/dist/index.d.mts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +140 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/LocalSessionStore.test.ts +53 -0
- package/src/index.ts +1 -0
- package/src/stores/LocalAssistantStore.ts +1 -1
- package/src/stores/LocalSessionStore.ts +169 -0
- package/src/stores/LocalUserStore.ts +10 -0
package/dist/index.mjs
CHANGED
|
@@ -691,7 +691,7 @@ var LocalAssistantStore = class {
|
|
|
691
691
|
}
|
|
692
692
|
async getByOwner(tenantId, userId) {
|
|
693
693
|
const row = this.db.prepare(
|
|
694
|
-
`SELECT * FROM lt_assistants WHERE tenant_id = ? AND owner_user_id = ? LIMIT 1`
|
|
694
|
+
`SELECT * FROM lt_assistants WHERE tenant_id = ? AND owner_user_id = ? ORDER BY created_at ASC LIMIT 1`
|
|
695
695
|
).get(tenantId, userId);
|
|
696
696
|
return row ? mapRowToAssistant(row) : null;
|
|
697
697
|
}
|
|
@@ -1768,6 +1768,7 @@ CREATE TABLE IF NOT EXISTS lt_users (
|
|
|
1768
1768
|
email TEXT NOT NULL,
|
|
1769
1769
|
name TEXT NOT NULL,
|
|
1770
1770
|
status TEXT NOT NULL DEFAULT 'pending',
|
|
1771
|
+
auth_epoch TEXT,
|
|
1771
1772
|
metadata TEXT DEFAULT '{}',
|
|
1772
1773
|
created_at TEXT NOT NULL,
|
|
1773
1774
|
updated_at TEXT NOT NULL
|
|
@@ -1779,6 +1780,10 @@ var LocalUserStore = class {
|
|
|
1779
1780
|
constructor(db) {
|
|
1780
1781
|
this.db = db;
|
|
1781
1782
|
ensureTable(db, DDL6);
|
|
1783
|
+
const columns6 = db.prepare(`PRAGMA table_info(lt_users)`).all();
|
|
1784
|
+
if (!columns6.some((column) => column.name === "auth_epoch")) {
|
|
1785
|
+
db.exec(`ALTER TABLE lt_users ADD COLUMN auth_epoch TEXT`);
|
|
1786
|
+
}
|
|
1782
1787
|
}
|
|
1783
1788
|
async getAllUsers() {
|
|
1784
1789
|
const rows2 = this.db.prepare(
|
|
@@ -1839,6 +1844,10 @@ var LocalUserStore = class {
|
|
|
1839
1844
|
setClauses.push("status = ?");
|
|
1840
1845
|
values.push(updates.status);
|
|
1841
1846
|
}
|
|
1847
|
+
if (updates.authEpoch !== void 0) {
|
|
1848
|
+
setClauses.push("auth_epoch = ?");
|
|
1849
|
+
values.push(updates.authEpoch);
|
|
1850
|
+
}
|
|
1842
1851
|
if (updates.metadata !== void 0) {
|
|
1843
1852
|
setClauses.push("metadata = ?");
|
|
1844
1853
|
values.push(JSON.stringify(updates.metadata));
|
|
@@ -1864,6 +1873,7 @@ function mapRowToUser(row) {
|
|
|
1864
1873
|
email: row.email,
|
|
1865
1874
|
name: row.name,
|
|
1866
1875
|
status: row.status,
|
|
1876
|
+
...row.auth_epoch ? { authEpoch: row.auth_epoch } : {},
|
|
1867
1877
|
metadata: JSON.parse(row.metadata || "{}"),
|
|
1868
1878
|
createdAt: parseISO(row.created_at),
|
|
1869
1879
|
updatedAt: parseISO(row.updated_at)
|
|
@@ -8003,6 +8013,133 @@ async function createLocalStoreConfig(options = {}) {
|
|
|
8003
8013
|
};
|
|
8004
8014
|
}
|
|
8005
8015
|
|
|
8016
|
+
// src/stores/LocalSessionStore.ts
|
|
8017
|
+
var DDL34 = `
|
|
8018
|
+
CREATE TABLE IF NOT EXISTS lt_sessions (
|
|
8019
|
+
id TEXT PRIMARY KEY,
|
|
8020
|
+
family_id TEXT NOT NULL,
|
|
8021
|
+
user_id TEXT NOT NULL,
|
|
8022
|
+
tenant_id TEXT,
|
|
8023
|
+
auth_epoch TEXT NOT NULL DEFAULT '',
|
|
8024
|
+
refresh_token_hash TEXT NOT NULL UNIQUE,
|
|
8025
|
+
created_at TEXT NOT NULL,
|
|
8026
|
+
last_used_at TEXT NOT NULL,
|
|
8027
|
+
idle_expires_at TEXT NOT NULL,
|
|
8028
|
+
absolute_expires_at TEXT NOT NULL,
|
|
8029
|
+
revoked_at TEXT,
|
|
8030
|
+
replaced_by TEXT,
|
|
8031
|
+
ip TEXT,
|
|
8032
|
+
user_agent TEXT,
|
|
8033
|
+
provider_id TEXT NOT NULL,
|
|
8034
|
+
idp_refresh_token_enc TEXT,
|
|
8035
|
+
idp_refresh_expires_at TEXT
|
|
8036
|
+
);
|
|
8037
|
+
CREATE INDEX IF NOT EXISTS idx_lt_sessions_family ON lt_sessions(family_id);
|
|
8038
|
+
CREATE INDEX IF NOT EXISTS idx_lt_sessions_user ON lt_sessions(user_id);
|
|
8039
|
+
`;
|
|
8040
|
+
function mapRow16(row) {
|
|
8041
|
+
return {
|
|
8042
|
+
id: row.id,
|
|
8043
|
+
familyId: row.family_id,
|
|
8044
|
+
userId: row.user_id,
|
|
8045
|
+
...row.tenant_id ? { tenantId: row.tenant_id } : {},
|
|
8046
|
+
authEpoch: row.auth_epoch,
|
|
8047
|
+
refreshTokenHash: row.refresh_token_hash,
|
|
8048
|
+
createdAt: parseISO(row.created_at),
|
|
8049
|
+
lastUsedAt: parseISO(row.last_used_at),
|
|
8050
|
+
idleExpiresAt: parseISO(row.idle_expires_at),
|
|
8051
|
+
absoluteExpiresAt: parseISO(row.absolute_expires_at),
|
|
8052
|
+
...row.revoked_at ? { revokedAt: parseISO(row.revoked_at) } : {},
|
|
8053
|
+
...row.replaced_by ? { replacedBy: row.replaced_by } : {},
|
|
8054
|
+
...row.ip ? { ip: row.ip } : {},
|
|
8055
|
+
...row.user_agent ? { userAgent: row.user_agent } : {},
|
|
8056
|
+
providerId: row.provider_id,
|
|
8057
|
+
...row.idp_refresh_token_enc ? { idpRefreshTokenEnc: row.idp_refresh_token_enc } : {},
|
|
8058
|
+
...row.idp_refresh_expires_at ? { idpRefreshExpiresAt: parseISO(row.idp_refresh_expires_at) } : {}
|
|
8059
|
+
};
|
|
8060
|
+
}
|
|
8061
|
+
var LocalSessionStore = class {
|
|
8062
|
+
constructor(db) {
|
|
8063
|
+
this.db = db;
|
|
8064
|
+
ensureTable(db, DDL34);
|
|
8065
|
+
}
|
|
8066
|
+
async create(record2) {
|
|
8067
|
+
this.db.prepare(
|
|
8068
|
+
`INSERT INTO lt_sessions (
|
|
8069
|
+
id, family_id, user_id, tenant_id, auth_epoch, refresh_token_hash,
|
|
8070
|
+
created_at, last_used_at, idle_expires_at, absolute_expires_at,
|
|
8071
|
+
revoked_at, replaced_by, ip, user_agent, provider_id,
|
|
8072
|
+
idp_refresh_token_enc, idp_refresh_expires_at
|
|
8073
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
8074
|
+
).run(
|
|
8075
|
+
record2.id,
|
|
8076
|
+
record2.familyId,
|
|
8077
|
+
record2.userId,
|
|
8078
|
+
record2.tenantId ?? null,
|
|
8079
|
+
record2.authEpoch,
|
|
8080
|
+
record2.refreshTokenHash,
|
|
8081
|
+
record2.createdAt.toISOString(),
|
|
8082
|
+
record2.lastUsedAt.toISOString(),
|
|
8083
|
+
record2.idleExpiresAt.toISOString(),
|
|
8084
|
+
record2.absoluteExpiresAt.toISOString(),
|
|
8085
|
+
record2.revokedAt ? record2.revokedAt.toISOString() : null,
|
|
8086
|
+
record2.replacedBy ?? null,
|
|
8087
|
+
record2.ip ?? null,
|
|
8088
|
+
record2.userAgent ?? null,
|
|
8089
|
+
record2.providerId,
|
|
8090
|
+
record2.idpRefreshTokenEnc ?? null,
|
|
8091
|
+
record2.idpRefreshExpiresAt ? record2.idpRefreshExpiresAt.toISOString() : null
|
|
8092
|
+
);
|
|
8093
|
+
}
|
|
8094
|
+
async findByRefreshTokenHash(hash) {
|
|
8095
|
+
const row = this.db.prepare(
|
|
8096
|
+
`SELECT * FROM lt_sessions WHERE refresh_token_hash = ?`
|
|
8097
|
+
).get(hash);
|
|
8098
|
+
return row ? mapRow16(row) : null;
|
|
8099
|
+
}
|
|
8100
|
+
async findByFamilyId(familyId) {
|
|
8101
|
+
const active = this.db.prepare(
|
|
8102
|
+
`SELECT * FROM lt_sessions
|
|
8103
|
+
WHERE family_id = ? AND replaced_by IS NULL AND revoked_at IS NULL
|
|
8104
|
+
ORDER BY created_at DESC LIMIT 1`
|
|
8105
|
+
).get(familyId);
|
|
8106
|
+
if (active) return mapRow16(active);
|
|
8107
|
+
const fallback = this.db.prepare(
|
|
8108
|
+
`SELECT * FROM lt_sessions WHERE family_id = ? ORDER BY created_at DESC LIMIT 1`
|
|
8109
|
+
).get(familyId);
|
|
8110
|
+
return fallback ? mapRow16(fallback) : null;
|
|
8111
|
+
}
|
|
8112
|
+
async rotate(oldId, next) {
|
|
8113
|
+
this.db.prepare(
|
|
8114
|
+
`UPDATE lt_sessions SET replaced_by = ?, last_used_at = ? WHERE id = ?`
|
|
8115
|
+
).run(next.id, next.createdAt.toISOString(), oldId);
|
|
8116
|
+
await this.create(next);
|
|
8117
|
+
}
|
|
8118
|
+
async revokeFamily(familyId, _reason) {
|
|
8119
|
+
const now = nowISO();
|
|
8120
|
+
this.db.prepare(
|
|
8121
|
+
`UPDATE lt_sessions SET revoked_at = ? WHERE family_id = ? AND revoked_at IS NULL`
|
|
8122
|
+
).run(now, familyId);
|
|
8123
|
+
}
|
|
8124
|
+
async revokeAllForUser(userId, _reason) {
|
|
8125
|
+
const now = nowISO();
|
|
8126
|
+
this.db.prepare(
|
|
8127
|
+
`UPDATE lt_sessions SET revoked_at = ? WHERE user_id = ? AND revoked_at IS NULL`
|
|
8128
|
+
).run(now, userId);
|
|
8129
|
+
}
|
|
8130
|
+
async touch(id, lastUsedAt) {
|
|
8131
|
+
this.db.prepare(
|
|
8132
|
+
`UPDATE lt_sessions SET last_used_at = ? WHERE id = ?`
|
|
8133
|
+
).run(lastUsedAt.toISOString(), id);
|
|
8134
|
+
}
|
|
8135
|
+
async listForUser(userId) {
|
|
8136
|
+
const rows2 = this.db.prepare(
|
|
8137
|
+
`SELECT * FROM lt_sessions WHERE user_id = ? ORDER BY created_at DESC`
|
|
8138
|
+
).all(userId);
|
|
8139
|
+
return rows2.map(mapRow16);
|
|
8140
|
+
}
|
|
8141
|
+
};
|
|
8142
|
+
|
|
8006
8143
|
// src/stores/InMemoryConversationStore.ts
|
|
8007
8144
|
var isoNow = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
8008
8145
|
var InMemoryConversationStore = class {
|
|
@@ -8070,6 +8207,7 @@ export {
|
|
|
8070
8207
|
LocalProjectRoomStore,
|
|
8071
8208
|
LocalProjectStore,
|
|
8072
8209
|
LocalScheduleStorage,
|
|
8210
|
+
LocalSessionStore,
|
|
8073
8211
|
LocalSkillStore,
|
|
8074
8212
|
LocalStore,
|
|
8075
8213
|
LocalTaskStore,
|