@itphx/synth-storage-postgres 0.0.0-stage → 0.12.4
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/LICENSE +18 -0
- package/LICENSE.ru.md +31 -0
- package/dist/errors.d.ts +71 -0
- package/dist/errors.js +126 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +56 -0
- package/dist/json-param.d.ts +14 -0
- package/dist/json-param.js +22 -0
- package/dist/locks.d.ts +104 -0
- package/dist/locks.js +201 -0
- package/dist/migrate.d.ts +58 -0
- package/dist/migrate.js +125 -0
- package/dist/migrations/001-init.d.ts +15 -0
- package/dist/migrations/001-init.js +457 -0
- package/dist/migrations/002-egress-audit.d.ts +12 -0
- package/dist/migrations/002-egress-audit.js +52 -0
- package/dist/migrations/003-analytics-rollups.d.ts +12 -0
- package/dist/migrations/003-analytics-rollups.js +21 -0
- package/dist/migrations/004-pipeline-engine.d.ts +19 -0
- package/dist/migrations/004-pipeline-engine.js +74 -0
- package/dist/migrations/005-pipeline-provenance.d.ts +12 -0
- package/dist/migrations/005-pipeline-provenance.js +15 -0
- package/dist/migrations/006-plugin-audit.d.ts +13 -0
- package/dist/migrations/006-plugin-audit.js +34 -0
- package/dist/migrations/007-plugin-lock.d.ts +10 -0
- package/dist/migrations/007-plugin-lock.js +25 -0
- package/dist/migrations/008-plugin-audit-scan.d.ts +11 -0
- package/dist/migrations/008-plugin-audit-scan.js +15 -0
- package/dist/migrations/009-plugin-lock-previous.d.ts +13 -0
- package/dist/migrations/009-plugin-lock-previous.js +16 -0
- package/dist/migrations/010-plugin-lock-mode.d.ts +16 -0
- package/dist/migrations/010-plugin-lock-mode.js +20 -0
- package/dist/migrations/011-session-steer-inbox.d.ts +11 -0
- package/dist/migrations/011-session-steer-inbox.js +14 -0
- package/dist/migrations/012-external-credentials.d.ts +15 -0
- package/dist/migrations/012-external-credentials.js +40 -0
- package/dist/migrations/013-service-key-plugin-id.d.ts +17 -0
- package/dist/migrations/013-service-key-plugin-id.js +20 -0
- package/dist/migrations/014-session-mode-by-principal.d.ts +12 -0
- package/dist/migrations/014-session-mode-by-principal.js +15 -0
- package/dist/migrations/015-authority.d.ts +17 -0
- package/dist/migrations/015-authority.js +43 -0
- package/dist/migrations/016-credential-audit.d.ts +17 -0
- package/dist/migrations/016-credential-audit.js +32 -0
- package/dist/migrations/017-memory.d.ts +29 -0
- package/dist/migrations/017-memory.js +95 -0
- package/dist/migrations/018-memory-index-scope.d.ts +14 -0
- package/dist/migrations/018-memory-index-scope.js +18 -0
- package/dist/migrations/019-memory-index-enabled.d.ts +11 -0
- package/dist/migrations/019-memory-index-enabled.js +14 -0
- package/dist/migrations/020-project-memory.d.ts +11 -0
- package/dist/migrations/020-project-memory.js +13 -0
- package/dist/migrations/021-background-runs.d.ts +17 -0
- package/dist/migrations/021-background-runs.js +67 -0
- package/dist/migrations/022-background-run-process-id.d.ts +14 -0
- package/dist/migrations/022-background-run-process-id.js +18 -0
- package/dist/migrations/023-session-worktree.d.ts +12 -0
- package/dist/migrations/023-session-worktree.js +16 -0
- package/dist/migrations/024-blob-refs.d.ts +15 -0
- package/dist/migrations/024-blob-refs.js +26 -0
- package/dist/migrations/025-packs-pipelines.d.ts +28 -0
- package/dist/migrations/025-packs-pipelines.js +82 -0
- package/dist/migrations/026-instance-skills.d.ts +17 -0
- package/dist/migrations/026-instance-skills.js +25 -0
- package/dist/migrations/027-context-files.d.ts +20 -0
- package/dist/migrations/027-context-files.js +30 -0
- package/dist/migrations/index.d.ts +23 -0
- package/dist/migrations/index.js +71 -0
- package/dist/pool.d.ts +178 -0
- package/dist/pool.js +382 -0
- package/dist/ports/analytics.d.ts +26 -0
- package/dist/ports/analytics.js +243 -0
- package/dist/ports/audit.d.ts +15 -0
- package/dist/ports/audit.js +192 -0
- package/dist/ports/authority.d.ts +27 -0
- package/dist/ports/authority.js +148 -0
- package/dist/ports/background-runs.d.ts +41 -0
- package/dist/ports/background-runs.js +179 -0
- package/dist/ports/blob-refs.d.ts +36 -0
- package/dist/ports/blob-refs.js +55 -0
- package/dist/ports/content.d.ts +41 -0
- package/dist/ports/content.js +1553 -0
- package/dist/ports/context-files.d.ts +145 -0
- package/dist/ports/context-files.js +279 -0
- package/dist/ports/core-sync.d.ts +31 -0
- package/dist/ports/core-sync.js +34 -0
- package/dist/ports/credential-audit.d.ts +19 -0
- package/dist/ports/credential-audit.js +96 -0
- package/dist/ports/deps.d.ts +63 -0
- package/dist/ports/deps.js +19 -0
- package/dist/ports/events-bindings.d.ts +77 -0
- package/dist/ports/events-bindings.js +356 -0
- package/dist/ports/events-core.d.ts +35 -0
- package/dist/ports/events-core.js +71 -0
- package/dist/ports/events-journal.d.ts +68 -0
- package/dist/ports/events-journal.js +211 -0
- package/dist/ports/events-scheduler.d.ts +49 -0
- package/dist/ports/events-scheduler.js +231 -0
- package/dist/ports/events-webhooks.d.ts +64 -0
- package/dist/ports/events-webhooks.js +268 -0
- package/dist/ports/events.d.ts +20 -0
- package/dist/ports/events.js +27 -0
- package/dist/ports/external-credentials.d.ts +6 -0
- package/dist/ports/external-credentials.js +363 -0
- package/dist/ports/legacy-pipelines.d.ts +50 -0
- package/dist/ports/legacy-pipelines.js +202 -0
- package/dist/ports/memory.d.ts +65 -0
- package/dist/ports/memory.js +471 -0
- package/dist/ports/packs.d.ts +32 -0
- package/dist/ports/packs.js +117 -0
- package/dist/ports/pipelines.d.ts +67 -0
- package/dist/ports/pipelines.js +297 -0
- package/dist/ports/plugin-audit.d.ts +14 -0
- package/dist/ports/plugin-audit.js +110 -0
- package/dist/ports/plugin-lock.d.ts +27 -0
- package/dist/ports/plugin-lock.js +145 -0
- package/dist/ports/principals-defaults.d.ts +21 -0
- package/dist/ports/principals-defaults.js +68 -0
- package/dist/ports/principals-documents.d.ts +23 -0
- package/dist/ports/principals-documents.js +38 -0
- package/dist/ports/principals-profiles.d.ts +21 -0
- package/dist/ports/principals-profiles.js +263 -0
- package/dist/ports/principals-projects.d.ts +19 -0
- package/dist/ports/principals-projects.js +161 -0
- package/dist/ports/principals-settings.d.ts +25 -0
- package/dist/ports/principals-settings.js +295 -0
- package/dist/ports/principals-shared.d.ts +33 -0
- package/dist/ports/principals-shared.js +44 -0
- package/dist/ports/principals.d.ts +27 -0
- package/dist/ports/principals.js +39 -0
- package/dist/ports/questions.d.ts +40 -0
- package/dist/ports/questions.js +135 -0
- package/dist/ports/sessions-mapping.d.ts +254 -0
- package/dist/ports/sessions-mapping.js +449 -0
- package/dist/ports/sessions.d.ts +143 -0
- package/dist/ports/sessions.js +517 -0
- package/dist/ports/skills.d.ts +59 -0
- package/dist/ports/skills.js +205 -0
- package/dist/ports/stub.d.ts +14 -0
- package/dist/ports/stub.js +32 -0
- package/dist/ports/worktrees.d.ts +41 -0
- package/dist/ports/worktrees.js +85 -0
- package/dist/postgres-storage.d.ts +58 -0
- package/dist/postgres-storage.js +110 -0
- package/dist/schema.d.ts +13 -0
- package/dist/schema.js +22 -0
- package/dist/storage-context.d.ts +80 -0
- package/dist/storage-context.js +238 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PG-реализация портов исходящих webhooks (ADR-097, волна 3b):
|
|
3
|
+
* `webhooks`/`webhookDeliveries`.
|
|
4
|
+
*
|
|
5
|
+
* Семантика повторяет файловые реализации core (`WebhookStore`,
|
|
6
|
+
* `WebhookDeliveryStore`): `label` уникальна глобально (регистронезависимо) →
|
|
7
|
+
* доменная `WebhookConflictError`; signing-секрет `whsec_…` хранится
|
|
8
|
+
* **зашифрованным** at-rest (`secret_enc bytea`, AES-256-GCM мастер-ключом,
|
|
9
|
+
* ADR-052/ADR-076) и отдаётся plaintext только при `create`/`regenerateSecret`
|
|
10
|
+
* (и расшифрованным — через `getSecret` для доставки); журнал доставок —
|
|
11
|
+
* append-only, `list(limit)` → последние N.
|
|
12
|
+
*/
|
|
13
|
+
import { randomBytes } from 'node:crypto';
|
|
14
|
+
import { WEBHOOK_SECRET_PREFIX, generateId, } from '@itphx/synth-shared';
|
|
15
|
+
import { jsonbParam } from '../json-param.js';
|
|
16
|
+
import { compact, isUniqueViolation, loadCore, SECRET_PREFIX_VISIBLE, toInt, toIso, toIsoRequired, } from './events-core.js';
|
|
17
|
+
function toPublicWebhook(row) {
|
|
18
|
+
return compact({
|
|
19
|
+
id: row.id,
|
|
20
|
+
label: row.label,
|
|
21
|
+
description: row.description ?? undefined,
|
|
22
|
+
url: row.url,
|
|
23
|
+
events: (row.events ?? []),
|
|
24
|
+
enabled: row.enabled,
|
|
25
|
+
secretPrefix: row.secret_prefix,
|
|
26
|
+
createdBy: row.created_by,
|
|
27
|
+
createdAt: toIsoRequired(row.created_at),
|
|
28
|
+
lastDeliveryAt: toIso(row.last_delivery_at),
|
|
29
|
+
lastStatus: (row.last_status ?? undefined),
|
|
30
|
+
disabledAt: toIso(row.disabled_at),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ADR-052 (этап II): реестр подписок на исходящие события поверх `webhooks`.
|
|
35
|
+
*
|
|
36
|
+
* Signing-секрет шифруется мастер-ключом (core `encryptSecret`; ключ резолвится
|
|
37
|
+
* лениво — `resolveMasterKey`), поэтому HMAC-подпись доставки возможна, но
|
|
38
|
+
* plaintext at-rest не хранится. Конфликт метки (`lower(label)`) → доменная
|
|
39
|
+
* `WebhookConflictError` (роуты маппят в 409).
|
|
40
|
+
*/
|
|
41
|
+
export class PgWebhookRepository {
|
|
42
|
+
_deps;
|
|
43
|
+
_masterKeyPromise;
|
|
44
|
+
constructor(_deps) {
|
|
45
|
+
this._deps = _deps;
|
|
46
|
+
}
|
|
47
|
+
async list() {
|
|
48
|
+
const rows = await this._deps.connection.query('SELECT * FROM webhooks ORDER BY created_at, id');
|
|
49
|
+
return rows.map(toPublicWebhook);
|
|
50
|
+
}
|
|
51
|
+
async get(id) {
|
|
52
|
+
const rows = await this._deps.connection.query('SELECT * FROM webhooks WHERE id = $1 LIMIT 1', [id]);
|
|
53
|
+
return rows[0] ? toPublicWebhook(rows[0]) : null;
|
|
54
|
+
}
|
|
55
|
+
async create(input, createdBy) {
|
|
56
|
+
const label = (input.label ?? '').trim();
|
|
57
|
+
if (!label)
|
|
58
|
+
throw new Error('label обязателен');
|
|
59
|
+
const { secret, enc } = await this._newSecret();
|
|
60
|
+
let rows;
|
|
61
|
+
try {
|
|
62
|
+
rows = await this._deps.connection.query(`INSERT INTO webhooks
|
|
63
|
+
(id, label, description, url, events, enabled, secret_enc, secret_prefix,
|
|
64
|
+
created_by, created_at)
|
|
65
|
+
VALUES ($1, $2, $3, $4, $5::jsonb, $6, $7, $8, $9, $10)
|
|
66
|
+
RETURNING *`, [
|
|
67
|
+
`whk_${generateId()}`,
|
|
68
|
+
label,
|
|
69
|
+
input.description ?? null,
|
|
70
|
+
input.url,
|
|
71
|
+
jsonbParam(input.events ?? []),
|
|
72
|
+
input.enabled ?? true,
|
|
73
|
+
enc,
|
|
74
|
+
`${secret.slice(0, SECRET_PREFIX_VISIBLE)}…`,
|
|
75
|
+
createdBy,
|
|
76
|
+
new Date().toISOString(),
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
if (isUniqueViolation(err))
|
|
81
|
+
await this._throwConflict(label);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
return { ...toPublicWebhook(rows[0]), secret };
|
|
85
|
+
}
|
|
86
|
+
/** Патч: `undefined` — не трогать, `null` — сбросить (`description`). */
|
|
87
|
+
async update(id, patch) {
|
|
88
|
+
const sets = [];
|
|
89
|
+
const params = [];
|
|
90
|
+
if (patch.label !== undefined) {
|
|
91
|
+
const label = patch.label.trim();
|
|
92
|
+
if (!label)
|
|
93
|
+
throw new Error('label обязателен');
|
|
94
|
+
params.push(label);
|
|
95
|
+
sets.push(`label = $${params.length}`);
|
|
96
|
+
}
|
|
97
|
+
if (patch.description !== undefined) {
|
|
98
|
+
params.push(patch.description);
|
|
99
|
+
sets.push(`description = $${params.length}`);
|
|
100
|
+
}
|
|
101
|
+
if (patch.url !== undefined) {
|
|
102
|
+
params.push(patch.url);
|
|
103
|
+
sets.push(`url = $${params.length}`);
|
|
104
|
+
}
|
|
105
|
+
if (patch.events !== undefined) {
|
|
106
|
+
params.push(jsonbParam(patch.events));
|
|
107
|
+
sets.push(`events = $${params.length}::jsonb`);
|
|
108
|
+
}
|
|
109
|
+
if (patch.enabled !== undefined) {
|
|
110
|
+
params.push(patch.enabled);
|
|
111
|
+
const idx = params.length;
|
|
112
|
+
sets.push(`enabled = $${idx}`);
|
|
113
|
+
sets.push(`disabled_at = CASE WHEN $${idx} THEN NULL ELSE now() END`);
|
|
114
|
+
}
|
|
115
|
+
if (sets.length === 0)
|
|
116
|
+
return this.get(id);
|
|
117
|
+
params.push(id);
|
|
118
|
+
try {
|
|
119
|
+
const rows = await this._deps.connection.query(`UPDATE webhooks SET ${sets.join(', ')} WHERE id = $${params.length} RETURNING *`, params);
|
|
120
|
+
return rows[0] ? toPublicWebhook(rows[0]) : null;
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
if (isUniqueViolation(err))
|
|
124
|
+
await this._throwConflict(patch.label ?? id);
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Мягкое включение/отключение (`disabledAt`). */
|
|
129
|
+
async setEnabled(id, enabled) {
|
|
130
|
+
const rows = await this._deps.connection.query(`UPDATE webhooks
|
|
131
|
+
SET enabled = $2,
|
|
132
|
+
disabled_at = CASE WHEN $2 THEN NULL ELSE now() END
|
|
133
|
+
WHERE id = $1
|
|
134
|
+
RETURNING *`, [id, enabled]);
|
|
135
|
+
return rows[0] ? toPublicWebhook(rows[0]) : null;
|
|
136
|
+
}
|
|
137
|
+
async remove(id) {
|
|
138
|
+
// FK на `webhooks` нет — каскад чистим явно (паритет с файловой реализацией,
|
|
139
|
+
// где `remove` снимает подписку из реестра).
|
|
140
|
+
return this._deps.connection.withTransaction(async (tx) => {
|
|
141
|
+
await tx.query('DELETE FROM webhook_deliveries WHERE subscription_id = $1', [id]);
|
|
142
|
+
const rows = await tx.query('DELETE FROM webhooks WHERE id = $1 RETURNING id', [id]);
|
|
143
|
+
return rows.length > 0;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** Ротация signing-секрета: новый `whsec_…` (шифруется), plaintext — один раз. */
|
|
147
|
+
async regenerateSecret(id) {
|
|
148
|
+
const { secret, enc } = await this._newSecret();
|
|
149
|
+
const rows = await this._deps.connection.query(`UPDATE webhooks SET secret_enc = $2, secret_prefix = $3 WHERE id = $1 RETURNING *`, [id, enc, `${secret.slice(0, SECRET_PREFIX_VISIBLE)}…`]);
|
|
150
|
+
return rows[0] ? { ...toPublicWebhook(rows[0]), secret } : null;
|
|
151
|
+
}
|
|
152
|
+
/** Расшифрованный signing-секрет (только для доставки); неизвестный id — null. */
|
|
153
|
+
async getSecret(id) {
|
|
154
|
+
const rows = await this._deps.connection.query('SELECT secret_enc FROM webhooks WHERE id = $1 LIMIT 1', [id]);
|
|
155
|
+
const stored = rows[0]?.secret_enc;
|
|
156
|
+
if (stored === undefined)
|
|
157
|
+
return null;
|
|
158
|
+
const key = await this._masterKey();
|
|
159
|
+
const { decryptSecret } = await loadCore();
|
|
160
|
+
return decryptSecret(Buffer.from(stored).toString('utf8'), key);
|
|
161
|
+
}
|
|
162
|
+
/** Best-effort отметка последней доставки (`lastDeliveryAt`/`lastStatus`). */
|
|
163
|
+
async touchDelivery(id, status) {
|
|
164
|
+
await this._deps.connection.query('UPDATE webhooks SET last_delivery_at = now(), last_status = $2 WHERE id = $1', [id, status]);
|
|
165
|
+
}
|
|
166
|
+
/** Новый signing-секрет + его зашифрованное представление (bytea). */
|
|
167
|
+
async _newSecret() {
|
|
168
|
+
const key = await this._masterKey();
|
|
169
|
+
const { encryptSecret } = await loadCore();
|
|
170
|
+
const secret = `${WEBHOOK_SECRET_PREFIX}${randomBytes(24).toString('base64url')}`;
|
|
171
|
+
return { secret, enc: Buffer.from(encryptSecret(secret, key), 'utf8') };
|
|
172
|
+
}
|
|
173
|
+
async _throwConflict(label) {
|
|
174
|
+
const { WebhookConflictError } = await loadCore();
|
|
175
|
+
throw new WebhookConflictError(label);
|
|
176
|
+
}
|
|
177
|
+
/** Мастер-ключ секретов at-rest (env > `secretKey` > файл `{dataDir}/secrets`). */
|
|
178
|
+
_masterKey() {
|
|
179
|
+
if (!this._masterKeyPromise) {
|
|
180
|
+
this._masterKeyPromise = (async () => {
|
|
181
|
+
const { resolveMasterKey } = await loadCore();
|
|
182
|
+
const result = await resolveMasterKey({
|
|
183
|
+
dataDir: this._deps.dataDir,
|
|
184
|
+
secretKey: this._deps.secretKey,
|
|
185
|
+
env: this._deps.env,
|
|
186
|
+
});
|
|
187
|
+
return result.key;
|
|
188
|
+
})().catch((err) => {
|
|
189
|
+
this._masterKeyPromise = undefined;
|
|
190
|
+
throw err;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return this._masterKeyPromise;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function toDelivery(row) {
|
|
197
|
+
return compact({
|
|
198
|
+
id: row.id,
|
|
199
|
+
subscriptionId: row.subscription_id,
|
|
200
|
+
eventType: row.event_type,
|
|
201
|
+
status: row.status,
|
|
202
|
+
attempts: toInt(row.attempts) ?? 0,
|
|
203
|
+
responseStatus: toInt(row.response_status),
|
|
204
|
+
error: row.error ?? undefined,
|
|
205
|
+
createdAt: toIsoRequired(row.created_at),
|
|
206
|
+
completedAt: toIso(row.completed_at),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/** ADR-052 (этап II): append-only журнал доставок поверх `webhook_deliveries`. */
|
|
210
|
+
export class PgWebhookDeliveryRepository {
|
|
211
|
+
_deps;
|
|
212
|
+
constructor(_deps) {
|
|
213
|
+
this._deps = _deps;
|
|
214
|
+
}
|
|
215
|
+
async record(delivery) {
|
|
216
|
+
await this._deps.connection.query(`INSERT INTO webhook_deliveries
|
|
217
|
+
(id, subscription_id, event_type, status, attempts, response_status, error,
|
|
218
|
+
created_at, completed_at)
|
|
219
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [
|
|
220
|
+
delivery.id,
|
|
221
|
+
delivery.subscriptionId,
|
|
222
|
+
delivery.eventType,
|
|
223
|
+
delivery.status,
|
|
224
|
+
delivery.attempts,
|
|
225
|
+
delivery.responseStatus ?? null,
|
|
226
|
+
delivery.error ?? null,
|
|
227
|
+
delivery.createdAt,
|
|
228
|
+
delivery.completedAt ?? null,
|
|
229
|
+
]);
|
|
230
|
+
}
|
|
231
|
+
/** Все записи журнала (старые → новые), опционально последние `limit`. */
|
|
232
|
+
async list(limit) {
|
|
233
|
+
const rows = this._isLimited(limit)
|
|
234
|
+
? await this._deps.connection.query(`SELECT * FROM (
|
|
235
|
+
SELECT * FROM webhook_deliveries ORDER BY seq DESC LIMIT $1
|
|
236
|
+
) t ORDER BY seq ASC`, [Math.floor(limit)])
|
|
237
|
+
: await this._deps.connection.query('SELECT * FROM webhook_deliveries ORDER BY seq ASC');
|
|
238
|
+
return rows.map(toDelivery);
|
|
239
|
+
}
|
|
240
|
+
/** Последние записи конкретной подписки (`limit` — последние N). */
|
|
241
|
+
async listBySubscription(subscriptionId, limit) {
|
|
242
|
+
const rows = this._isLimited(limit)
|
|
243
|
+
? await this._deps.connection.query(`SELECT * FROM (
|
|
244
|
+
SELECT * FROM webhook_deliveries WHERE subscription_id = $1 ORDER BY seq DESC LIMIT $2
|
|
245
|
+
) t ORDER BY seq ASC`, [subscriptionId, Math.floor(limit)])
|
|
246
|
+
: await this._deps.connection.query('SELECT * FROM webhook_deliveries WHERE subscription_id = $1 ORDER BY seq ASC', [subscriptionId]);
|
|
247
|
+
return rows.map(toDelivery);
|
|
248
|
+
}
|
|
249
|
+
/** Retention: удаляет старше `retentionDays` (по `createdAt`); `0`/≤0 — no-op. */
|
|
250
|
+
async prune(retentionDays) {
|
|
251
|
+
if (!Number.isFinite(retentionDays) || retentionDays <= 0)
|
|
252
|
+
return 0;
|
|
253
|
+
const rows = await this._deps.connection.query(`DELETE FROM webhook_deliveries
|
|
254
|
+
WHERE created_at < now() - interval '1 day' * $1::double precision
|
|
255
|
+
RETURNING seq`, [retentionDays]);
|
|
256
|
+
return rows.length;
|
|
257
|
+
}
|
|
258
|
+
_isLimited(limit) {
|
|
259
|
+
return limit !== undefined && Number.isFinite(limit) && limit > 0;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/** Собрать под-группу портов webhooks. */
|
|
263
|
+
export function buildEventWebhookPorts(deps) {
|
|
264
|
+
return {
|
|
265
|
+
webhooks: new PgWebhookRepository(deps),
|
|
266
|
+
webhookDeliveries: new PgWebhookDeliveryRepository(deps),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Группа портов **событий, расписаний и webhooks** PostgreSQL-драйвера
|
|
3
|
+
* (ADR-097, волна 3b).
|
|
4
|
+
*
|
|
5
|
+
* Фабрика `buildEventPorts(deps)` собирает свою часть `StorageContext` из четырёх
|
|
6
|
+
* независимых под-файлов (каждый — отдельная подсистема, удобно править/тестировать):
|
|
7
|
+
* - `events-bindings.ts` → `eventBindings`/`eventRoutes`/`eventApiKeys`;
|
|
8
|
+
* - `events-journal.ts` → `eventJournal`/`identityClaims`/`dedup`;
|
|
9
|
+
* - `events-scheduler.ts` → `schedules`/`jobs`;
|
|
10
|
+
* - `events-webhooks.ts` → `webhooks`/`webhookDeliveries`.
|
|
11
|
+
*
|
|
12
|
+
* Общие примитивы (ленивая загрузка core, типы-алиасы, хелперы) — `events-core.ts`.
|
|
13
|
+
* Контракты — `packages/core/src/storage/contract/{events,scheduler,secrets}.ts`.
|
|
14
|
+
*/
|
|
15
|
+
import type { StorageContext } from '@itphx/synth-core';
|
|
16
|
+
import type { PortDeps } from './deps.js';
|
|
17
|
+
/** Часть `StorageContext`, которой владеет группа `events`. */
|
|
18
|
+
export type EventPorts = Pick<StorageContext, 'eventBindings' | 'eventRoutes' | 'eventApiKeys' | 'eventJournal' | 'identityClaims' | 'dedup' | 'schedules' | 'jobs' | 'webhooks' | 'webhookDeliveries'>;
|
|
19
|
+
/** Собрать порты группы `events`. */
|
|
20
|
+
export declare function buildEventPorts(deps: PortDeps): EventPorts;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Группа портов **событий, расписаний и webhooks** PostgreSQL-драйвера
|
|
3
|
+
* (ADR-097, волна 3b).
|
|
4
|
+
*
|
|
5
|
+
* Фабрика `buildEventPorts(deps)` собирает свою часть `StorageContext` из четырёх
|
|
6
|
+
* независимых под-файлов (каждый — отдельная подсистема, удобно править/тестировать):
|
|
7
|
+
* - `events-bindings.ts` → `eventBindings`/`eventRoutes`/`eventApiKeys`;
|
|
8
|
+
* - `events-journal.ts` → `eventJournal`/`identityClaims`/`dedup`;
|
|
9
|
+
* - `events-scheduler.ts` → `schedules`/`jobs`;
|
|
10
|
+
* - `events-webhooks.ts` → `webhooks`/`webhookDeliveries`.
|
|
11
|
+
*
|
|
12
|
+
* Общие примитивы (ленивая загрузка core, типы-алиасы, хелперы) — `events-core.ts`.
|
|
13
|
+
* Контракты — `packages/core/src/storage/contract/{events,scheduler,secrets}.ts`.
|
|
14
|
+
*/
|
|
15
|
+
import { buildEventBindingPorts } from './events-bindings.js';
|
|
16
|
+
import { buildEventJournalPorts } from './events-journal.js';
|
|
17
|
+
import { buildEventSchedulerPorts } from './events-scheduler.js';
|
|
18
|
+
import { buildEventWebhookPorts } from './events-webhooks.js';
|
|
19
|
+
/** Собрать порты группы `events`. */
|
|
20
|
+
export function buildEventPorts(deps) {
|
|
21
|
+
return {
|
|
22
|
+
...buildEventBindingPorts(deps),
|
|
23
|
+
...buildEventJournalPorts(deps),
|
|
24
|
+
...buildEventSchedulerPorts(deps),
|
|
25
|
+
...buildEventWebhookPorts(deps),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StorageContext } from '@itphx/synth-core';
|
|
2
|
+
import type { PortDeps } from './deps.js';
|
|
3
|
+
/** Часть `StorageContext`, которой владеет модуль внешних доступов. */
|
|
4
|
+
export type ExternalCredentialPorts = Pick<StorageContext, 'externalCredentials'>;
|
|
5
|
+
/** Собрать порт внешних доступов. */
|
|
6
|
+
export declare function buildExternalCredentialPorts(deps: PortDeps): ExternalCredentialPorts;
|