@adonis-agora/authkit-poppy 0.3.1-rc.1 → 0.3.1-rc.2
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/CHANGELOG.md +15 -0
- package/build/src/extension.js +9 -2
- package/build/src/replay.d.ts +3 -1
- package/build/src/replay.js +7 -5
- package/build/src/store.d.ts +5 -1
- package/build/src/store.js +23 -19
- package/build/src/tables.d.ts +5 -1
- package/build/src/tables.js +4 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @adonis-agora/authkit-poppy
|
|
2
2
|
|
|
3
|
+
## 0.3.1-rc.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#474](https://github.com/DavideCarvalho/adonis-agora-authkit/pull/474) [`df9e49d`](https://github.com/DavideCarvalho/adonis-agora-authkit/commit/df9e49d7817c03a7cce4cac1df709c7788d6307c) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - AuthKit's tables can live in their own database schema: `schema: { name: 'auth' }` in `defineConfig` puts every table AuthKit owns in `auth` (`"auth"."auth_settings"`) while the app stays in `public`. The schema is written into every statement, so it works on any connection and inside the app's own transaction, with no `searchPath` (which leaks across clients behind PgBouncer in transaction mode).
|
|
8
|
+
|
|
9
|
+
- The boot creates the schema (`CREATE SCHEMA IF NOT EXISTS`; MySQL: `CREATE DATABASE IF NOT EXISTS`) when `autoManage` is on, and fails with a message naming the schema and the grant when the role cannot create it. `ensureAuthkitSchema(db, { schema })` does the same from a migration.
|
|
10
|
+
- Covers the OIDC adapter table (`adapters.database({ schema })` overrides), the Lucid keystore (`jwks.store: { driver: 'lucid', schema }` overrides), the account store's tables (MFA, password history, organizations), runtime settings, session revocations, the personal-agent tables and agent extensions (`PersonalAgentHost.table(name)`, `AuthkitTable.create(table, { table })`, `ensureAuthkitTables(db, tables, { schema })`; Poppy uses them and `ensurePoppySchema(db, { schema })`).
|
|
11
|
+
- authkit-client: `lucidRevocationStore({ schema })`.
|
|
12
|
+
- SQLite with `schema.name` fails the boot instead of ignoring the option.
|
|
13
|
+
- `agora:doctor` gains `authkit.db-schema`: the schema exists, the tables are in it, the connection can write there. Silent without `schema.name`.
|
|
14
|
+
- The key-rotation lock key includes the schema, so two installs in two schemas of one database do not share it.
|
|
15
|
+
|
|
16
|
+
Without `schema.name` nothing changes.
|
|
17
|
+
|
|
3
18
|
## 0.3.1-rc.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/build/src/extension.js
CHANGED
|
@@ -81,11 +81,18 @@ function withRegistry(cfg, host) {
|
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* How the host names AuthKit's tables (with `schema.name`, `schema.table`). A host from before
|
|
86
|
+
* `table()` existed has no schema option, so the bare name is right there.
|
|
87
|
+
*/
|
|
88
|
+
function tableOf(host) {
|
|
89
|
+
return (name) => (typeof host.table === 'function' ? host.table(name) : name);
|
|
90
|
+
}
|
|
84
91
|
async function resolveReplay(replay, host) {
|
|
85
92
|
if (replay === 'memory')
|
|
86
93
|
return memoryReplayStore();
|
|
87
94
|
if (replay === 'database')
|
|
88
|
-
return databaseReplayStore(() => host.db());
|
|
95
|
+
return databaseReplayStore(() => host.db(), tableOf(host));
|
|
89
96
|
if (typeof replay.claim === 'function')
|
|
90
97
|
return replay;
|
|
91
98
|
const redis = await host.make('redis');
|
|
@@ -163,7 +170,7 @@ export function poppy(config, options = {}) {
|
|
|
163
170
|
return new PoppyService({
|
|
164
171
|
cfg,
|
|
165
172
|
urls: poppyUrls(host.issuer, cfg.prefix),
|
|
166
|
-
store: new PoppyStore(() => host.db()),
|
|
173
|
+
store: new PoppyStore(() => host.db(), tableOf(host)),
|
|
167
174
|
grants: host.grants,
|
|
168
175
|
registry: new PoppyClientRegistry(cfg, { fetchJson: options.fetchJson }),
|
|
169
176
|
replay: await resolveReplay(cfg.replay, host),
|
package/build/src/replay.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export declare function memoryReplayStore(options?: {
|
|
|
11
11
|
* Na tabela lib-owned `auth_poppy_jtis` (PK = chave): o INSERT de uma chave que
|
|
12
12
|
* já existe falha — atômico entre instâncias. Linhas vencidas saem aos poucos.
|
|
13
13
|
*/
|
|
14
|
-
export declare function databaseReplayStore(conn: () => any,
|
|
14
|
+
export declare function databaseReplayStore(conn: () => any,
|
|
15
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
16
|
+
table?: (name: string) => string, options?: {
|
|
15
17
|
now?: () => Date;
|
|
16
18
|
}): PoppyReplayStore;
|
|
17
19
|
/** Numa conexão Redis (`SET key 1 PX ttl NX`). */
|
package/build/src/replay.js
CHANGED
|
@@ -36,22 +36,24 @@ export function memoryReplayStore(options = {}) {
|
|
|
36
36
|
* Na tabela lib-owned `auth_poppy_jtis` (PK = chave): o INSERT de uma chave que
|
|
37
37
|
* já existe falha — atômico entre instâncias. Linhas vencidas saem aos poucos.
|
|
38
38
|
*/
|
|
39
|
-
export function databaseReplayStore(conn,
|
|
39
|
+
export function databaseReplayStore(conn,
|
|
40
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
41
|
+
table = (name) => name, options = {}) {
|
|
40
42
|
const now = options.now ?? (() => new Date());
|
|
41
43
|
let claims = 0;
|
|
42
44
|
return {
|
|
43
45
|
async claim(key, expiresAt) {
|
|
44
46
|
const t = now();
|
|
45
47
|
if (++claims % 200 === 1) {
|
|
46
|
-
await conn().from(JTI_TABLE).where('expires_at', '<', t).delete();
|
|
48
|
+
await conn().from(table(JTI_TABLE)).where('expires_at', '<', t).delete();
|
|
47
49
|
}
|
|
48
50
|
try {
|
|
49
|
-
await conn().table(JTI_TABLE).insert({ key, expires_at: expiresAt });
|
|
51
|
+
await conn().table(table(JTI_TABLE)).insert({ key, expires_at: expiresAt });
|
|
50
52
|
return true;
|
|
51
53
|
}
|
|
52
54
|
catch (error) {
|
|
53
55
|
// Chave já usada — a não ser que a linha vencida ainda não tenha saído.
|
|
54
|
-
const row = await conn().from(JTI_TABLE).where('key', key).first();
|
|
56
|
+
const row = await conn().from(table(JTI_TABLE)).where('key', key).first();
|
|
55
57
|
if (!row)
|
|
56
58
|
throw error;
|
|
57
59
|
const exp = row.expires_at instanceof Date
|
|
@@ -60,7 +62,7 @@ export function databaseReplayStore(conn, options = {}) {
|
|
|
60
62
|
if (exp.getTime() > t.getTime())
|
|
61
63
|
return false;
|
|
62
64
|
const updated = await conn()
|
|
63
|
-
.from(JTI_TABLE)
|
|
65
|
+
.from(table(JTI_TABLE))
|
|
64
66
|
.where('key', key)
|
|
65
67
|
.where('expires_at', '<=', t)
|
|
66
68
|
.update({ expires_at: expiresAt });
|
package/build/src/store.d.ts
CHANGED
|
@@ -64,7 +64,11 @@ export interface RequestRow {
|
|
|
64
64
|
}
|
|
65
65
|
export declare class PoppyStore {
|
|
66
66
|
private conn;
|
|
67
|
-
|
|
67
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
68
|
+
private t;
|
|
69
|
+
constructor(conn: () => any,
|
|
70
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
71
|
+
t?: (name: string) => string);
|
|
68
72
|
insertSession(row: Omit<SessionRow, 'endedAt'>): Promise<void>;
|
|
69
73
|
findSession(id: string): Promise<SessionRow | null>;
|
|
70
74
|
/** Estende a vida da Session (uso). */
|
package/build/src/store.js
CHANGED
|
@@ -92,12 +92,16 @@ function toRequest(row) {
|
|
|
92
92
|
}
|
|
93
93
|
export class PoppyStore {
|
|
94
94
|
conn;
|
|
95
|
-
|
|
95
|
+
t;
|
|
96
|
+
constructor(conn,
|
|
97
|
+
/** Nome da tabela como os statements o escrevem (`schema.tabela` quando o app usa um schema). */
|
|
98
|
+
t = (name) => name) {
|
|
96
99
|
this.conn = conn;
|
|
100
|
+
this.t = t;
|
|
97
101
|
}
|
|
98
102
|
// ─── sessions ─────────────────────────────────────────────────────────────
|
|
99
103
|
async insertSession(row) {
|
|
100
|
-
await this.conn().table(SESSION_TABLE).insert({
|
|
104
|
+
await this.conn().table(this.t(SESSION_TABLE)).insert({
|
|
101
105
|
id: row.id,
|
|
102
106
|
client_id: row.clientId,
|
|
103
107
|
user_id: row.userId,
|
|
@@ -113,13 +117,13 @@ export class PoppyStore {
|
|
|
113
117
|
async findSession(id) {
|
|
114
118
|
if (typeof id !== 'string' || !id)
|
|
115
119
|
return null;
|
|
116
|
-
const row = await this.conn().from(SESSION_TABLE).where('id', id).first();
|
|
120
|
+
const row = await this.conn().from(this.t(SESSION_TABLE)).where('id', id).first();
|
|
117
121
|
return row ? toSession(row) : null;
|
|
118
122
|
}
|
|
119
123
|
/** Estende a vida da Session (uso). */
|
|
120
124
|
async touchSession(id, expiresAt, at) {
|
|
121
125
|
await this.conn()
|
|
122
|
-
.from(SESSION_TABLE)
|
|
126
|
+
.from(this.t(SESSION_TABLE))
|
|
123
127
|
.where('id', id)
|
|
124
128
|
.whereNull('ended_at')
|
|
125
129
|
.update({ expires_at: expiresAt, updated_at: at });
|
|
@@ -130,7 +134,7 @@ export class PoppyStore {
|
|
|
130
134
|
*/
|
|
131
135
|
async bindSessionAccount(id, accountId, at) {
|
|
132
136
|
const result = await this.conn()
|
|
133
|
-
.from(SESSION_TABLE)
|
|
137
|
+
.from(this.t(SESSION_TABLE))
|
|
134
138
|
.where('id', id)
|
|
135
139
|
.where((q) => q.whereNull('account_id').orWhere('account_id', accountId))
|
|
136
140
|
.update({ account_id: accountId, updated_at: at });
|
|
@@ -139,7 +143,7 @@ export class PoppyStore {
|
|
|
139
143
|
/** Encerra todas as Sessions de um agente (bloqueio no console): param na hora. */
|
|
140
144
|
async endSessionsOfClient(clientId, at) {
|
|
141
145
|
const result = await this.conn()
|
|
142
|
-
.from(SESSION_TABLE)
|
|
146
|
+
.from(this.t(SESSION_TABLE))
|
|
143
147
|
.where('client_id', clientId)
|
|
144
148
|
.whereNull('ended_at')
|
|
145
149
|
.update({ ended_at: at, grant_id: null, scope: '', updated_at: at });
|
|
@@ -147,7 +151,7 @@ export class PoppyStore {
|
|
|
147
151
|
}
|
|
148
152
|
// ─── access tokens ────────────────────────────────────────────────────────
|
|
149
153
|
async insertToken(row) {
|
|
150
|
-
await this.conn().table(TOKEN_TABLE).insert({
|
|
154
|
+
await this.conn().table(this.t(TOKEN_TABLE)).insert({
|
|
151
155
|
token_hash: row.tokenHash,
|
|
152
156
|
// `session_id`/`user_id` são NOT NULL desde a Draft 0.1 e o schema só é aditivo; o sign-in
|
|
153
157
|
// não conhece a Session nem o User ID (§4.4).
|
|
@@ -164,19 +168,19 @@ export class PoppyStore {
|
|
|
164
168
|
});
|
|
165
169
|
}
|
|
166
170
|
async findToken(hash) {
|
|
167
|
-
const row = await this.conn().from(TOKEN_TABLE).where('token_hash', hash).first();
|
|
171
|
+
const row = await this.conn().from(this.t(TOKEN_TABLE)).where('token_hash', hash).first();
|
|
168
172
|
return row ? toToken(row) : null;
|
|
169
173
|
}
|
|
170
174
|
async deleteToken(hash) {
|
|
171
|
-
return affected(await this.conn().from(TOKEN_TABLE).where('token_hash', hash).delete()) > 0;
|
|
175
|
+
return (affected(await this.conn().from(this.t(TOKEN_TABLE)).where('token_hash', hash).delete()) > 0);
|
|
172
176
|
}
|
|
173
177
|
async deleteTokensExpiredBefore(before) {
|
|
174
|
-
await this.conn().from(TOKEN_TABLE).where('expires_at', '<', before).delete();
|
|
178
|
+
await this.conn().from(this.t(TOKEN_TABLE)).where('expires_at', '<', before).delete();
|
|
175
179
|
}
|
|
176
180
|
// ─── sign-in requests ─────────────────────────────────────────────────────
|
|
177
181
|
async insertRequest(row) {
|
|
178
182
|
await this.conn()
|
|
179
|
-
.table(REQUEST_TABLE)
|
|
183
|
+
.table(this.t(REQUEST_TABLE))
|
|
180
184
|
.insert({
|
|
181
185
|
id: row.id,
|
|
182
186
|
kind: row.kind,
|
|
@@ -200,15 +204,15 @@ export class PoppyStore {
|
|
|
200
204
|
async findRequest(id) {
|
|
201
205
|
if (typeof id !== 'string' || !id)
|
|
202
206
|
return null;
|
|
203
|
-
const row = await this.conn().from(REQUEST_TABLE).where('id', id).first();
|
|
207
|
+
const row = await this.conn().from(this.t(REQUEST_TABLE)).where('id', id).first();
|
|
204
208
|
return row ? toRequest(row) : null;
|
|
205
209
|
}
|
|
206
210
|
async findRequestByCodeHash(hash) {
|
|
207
|
-
const row = await this.conn().from(REQUEST_TABLE).where('code_hash', hash).first();
|
|
211
|
+
const row = await this.conn().from(this.t(REQUEST_TABLE)).where('code_hash', hash).first();
|
|
208
212
|
return row ? toRequest(row) : null;
|
|
209
213
|
}
|
|
210
214
|
async findRequestByUserCode(userCode) {
|
|
211
|
-
const row = await this.conn().from(REQUEST_TABLE).where('user_code', userCode).first();
|
|
215
|
+
const row = await this.conn().from(this.t(REQUEST_TABLE)).where('user_code', userCode).first();
|
|
212
216
|
return row ? toRequest(row) : null;
|
|
213
217
|
}
|
|
214
218
|
/** Transição atômica — só se o pedido ainda está em `from`. */
|
|
@@ -231,7 +235,7 @@ export class PoppyStore {
|
|
|
231
235
|
if (patch.data !== undefined)
|
|
232
236
|
update.data = JSON.stringify(patch.data);
|
|
233
237
|
const result = await this.conn()
|
|
234
|
-
.from(REQUEST_TABLE)
|
|
238
|
+
.from(this.t(REQUEST_TABLE))
|
|
235
239
|
.where('id', id)
|
|
236
240
|
.where('status', from)
|
|
237
241
|
.update(update);
|
|
@@ -240,7 +244,7 @@ export class PoppyStore {
|
|
|
240
244
|
/** Conta uma tentativa errada (atômico sobre o valor lido). */
|
|
241
245
|
async bumpAttempts(id, from) {
|
|
242
246
|
const result = await this.conn()
|
|
243
|
-
.from(REQUEST_TABLE)
|
|
247
|
+
.from(this.t(REQUEST_TABLE))
|
|
244
248
|
.where('id', id)
|
|
245
249
|
.where('attempts', from)
|
|
246
250
|
.update({ attempts: from + 1 });
|
|
@@ -248,14 +252,14 @@ export class PoppyStore {
|
|
|
248
252
|
}
|
|
249
253
|
async setRequestData(id, data) {
|
|
250
254
|
await this.conn()
|
|
251
|
-
.from(REQUEST_TABLE)
|
|
255
|
+
.from(this.t(REQUEST_TABLE))
|
|
252
256
|
.where('id', id)
|
|
253
257
|
.update({ data: JSON.stringify(data) });
|
|
254
258
|
}
|
|
255
259
|
async markPolled(id, at) {
|
|
256
|
-
await this.conn().from(REQUEST_TABLE).where('id', id).update({ last_polled_at: at });
|
|
260
|
+
await this.conn().from(this.t(REQUEST_TABLE)).where('id', id).update({ last_polled_at: at });
|
|
257
261
|
}
|
|
258
262
|
async deleteRequestsExpiredBefore(before) {
|
|
259
|
-
await this.conn().from(REQUEST_TABLE).where('expires_at', '<', before).delete();
|
|
263
|
+
await this.conn().from(this.t(REQUEST_TABLE)).where('expires_at', '<', before).delete();
|
|
260
264
|
}
|
|
261
265
|
}
|
package/build/src/tables.d.ts
CHANGED
|
@@ -18,10 +18,14 @@ export declare const POPPY_TABLES: readonly AuthkitTable[];
|
|
|
18
18
|
* async up() {
|
|
19
19
|
* await ensureAuthkitSchema(this.db)
|
|
20
20
|
* await ensurePoppySchema(this.db)
|
|
21
|
+
* // with `schema.name: 'auth'`: pass `{ schema: 'auth' }` to both
|
|
21
22
|
* }
|
|
22
23
|
* }
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
|
-
export declare function ensurePoppySchema(db: unknown,
|
|
26
|
+
export declare function ensurePoppySchema(db: unknown,
|
|
27
|
+
/** The same `connection` and `schema` (`schema.name`) as AuthKit's tables. */
|
|
28
|
+
options?: {
|
|
26
29
|
connection?: string;
|
|
30
|
+
schema?: string;
|
|
27
31
|
}): Promise<Pick<import("@adonis-agora/authkit-server").EnsureSchemaReport, "altered" | "created" | "indexed">>;
|
package/build/src/tables.js
CHANGED
|
@@ -147,10 +147,13 @@ export const POPPY_TABLES = [
|
|
|
147
147
|
* async up() {
|
|
148
148
|
* await ensureAuthkitSchema(this.db)
|
|
149
149
|
* await ensurePoppySchema(this.db)
|
|
150
|
+
* // with `schema.name: 'auth'`: pass `{ schema: 'auth' }` to both
|
|
150
151
|
* }
|
|
151
152
|
* }
|
|
152
153
|
* ```
|
|
153
154
|
*/
|
|
154
|
-
export function ensurePoppySchema(db,
|
|
155
|
+
export function ensurePoppySchema(db,
|
|
156
|
+
/** The same `connection` and `schema` (`schema.name`) as AuthKit's tables. */
|
|
157
|
+
options = {}) {
|
|
155
158
|
return ensureAuthkitTables(db, POPPY_TABLES, options);
|
|
156
159
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-poppy",
|
|
3
|
-
"version": "0.3.1-rc.
|
|
3
|
+
"version": "0.3.1-rc.2",
|
|
4
4
|
"description": "Personal Agent Protocol (\"Poppy\") for AuthKit: discovery, signed Poppy-Session agent sessions, Direct/Device/Mediated sign-in, MCP and browser sessions — an optional extension of @adonis-agora/authkit-server.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"node": ">=24"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@adonis-agora/authkit-server": "^1.0.0-rc.
|
|
43
|
+
"@adonis-agora/authkit-server": "^1.0.0-rc.12",
|
|
44
44
|
"@adonisjs/core": "^7.5.0",
|
|
45
45
|
"@adonisjs/session": "^8.1.0",
|
|
46
46
|
"@adonisjs/shield": "^9.0.0"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"jose": "6.2.16"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@adonis-agora/authkit-server": "1.0.0-rc.
|
|
52
|
+
"@adonis-agora/authkit-server": "1.0.0-rc.12",
|
|
53
53
|
"@adonisjs/core": "7.6.0",
|
|
54
54
|
"@adonisjs/lucid": "22.4.2",
|
|
55
55
|
"@adonisjs/session": "8.3.0",
|