@haneinfo/settings 0.0.0-stage → 0.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.
@@ -0,0 +1,540 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SettingsService = void 0;
16
+ exports.canonicalSettingJson = canonicalSettingJson;
17
+ const plugin_api_1 = require("@haneinfo/plugin-api");
18
+ const plugin_host_nest_1 = require("@haneinfo/plugin-host-nest");
19
+ const common_1 = require("@nestjs/common");
20
+ const core_1 = require("@nestjs/core");
21
+ const config_1 = require("./config");
22
+ const store_1 = require("./store");
23
+ const CONSTRAINT_KEYS = ['min', 'max', 'values', 'pattern', 'maxItems', 'maxLength'];
24
+ const REASON_MAX_LENGTH = 2000;
25
+ const ID_MAX_LENGTH = 128;
26
+ /** Canonical JSON with sorted keys: equal values compare equal regardless of key order. */
27
+ function canonicalSettingJson(value) {
28
+ if (Array.isArray(value))
29
+ return `[${value.map(canonicalSettingJson).join(',')}]`;
30
+ if (value && typeof value === 'object')
31
+ return `{${Object.keys(value)
32
+ .filter((key) => value[key] !== undefined)
33
+ .sort()
34
+ .map((key) => `${JSON.stringify(key)}:${canonicalSettingJson(value[key])}`)
35
+ .join(',')}}`;
36
+ return JSON.stringify(value);
37
+ }
38
+ function utf8Bytes(text) {
39
+ return Buffer.byteLength(text, 'utf8');
40
+ }
41
+ function isRecord(value) {
42
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
43
+ }
44
+ function invalid(message, problems = []) {
45
+ return new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.invalid, message, 400, problems.length ? 'Fix the listed paths and retry' : undefined, [], problems.length ? { problems } : {});
46
+ }
47
+ function notFound(code) {
48
+ return new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.notFound, code ? `Setting ${code} not found` : 'Setting not found', 404);
49
+ }
50
+ function proposalNotFound() {
51
+ return new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.proposalNotFound, 'Proposal not found', 404);
52
+ }
53
+ let SettingsService = class SettingsService {
54
+ constructor(store, config = {}, rbac, events, moduleRef, clock) {
55
+ this.store = store;
56
+ this.rbac = rbac;
57
+ this.events = events;
58
+ this.moduleRef = moduleRef;
59
+ this.clock = clock;
60
+ this.logger = new common_1.Logger('SettingsService');
61
+ this.declarations = new Map();
62
+ this.cache = new Map();
63
+ /** Bumped on every local invalidation so a read that raced a write never re-caches stale data. */
64
+ this.generations = new Map();
65
+ this.config = config_1.settingsConfigSchema.parse(config);
66
+ }
67
+ now() {
68
+ return this.clock?.now() ?? new Date();
69
+ }
70
+ // --- Declarations ------------------------------------------------------------------------------
71
+ /**
72
+ * The App's static runtime configuration (`haneinfo.config.ts` `runtime`), found the way the
73
+ * plugin host binds capabilities: by its stable token anywhere in the injector. Null without a host.
74
+ */
75
+ runtime() {
76
+ if (this.staticRuntime !== undefined)
77
+ return this.staticRuntime;
78
+ let runtime = null;
79
+ try {
80
+ const host = this.moduleRef?.get(plugin_host_nest_1.HANEINFO_HOST_CONFIG, { strict: false });
81
+ runtime = host?.runtime ?? null;
82
+ }
83
+ catch {
84
+ runtime = null;
85
+ }
86
+ this.staticRuntime = runtime;
87
+ return runtime;
88
+ }
89
+ staticValue(declaration) {
90
+ if (!declaration.staticRef)
91
+ return undefined;
92
+ const runtime = this.runtime();
93
+ return runtime ? (0, plugin_host_nest_1.resolveConfigRef)(runtime, declaration.staticRef) : undefined;
94
+ }
95
+ /** Validates and adds declarations; an invalid or duplicate one throws (startup fails). */
96
+ register(...declarations) {
97
+ const batch = new Set();
98
+ for (const declaration of declarations) {
99
+ const problems = (0, plugin_api_1.validateSettingDeclaration)(declaration);
100
+ const code = String(declaration?.code);
101
+ if (problems.length)
102
+ throw new Error(`Invalid setting declaration ${code}: ${problems.map((p) => `${p.path || '(declaration)'}: ${p.message}`).join('; ')}`);
103
+ if (this.declarations.has(code) || batch.has(code))
104
+ throw new Error(`Setting ${code} is declared more than once`);
105
+ const staticValue = this.staticValue(declaration);
106
+ if (staticValue !== undefined) {
107
+ const checked = (0, plugin_api_1.validateSettingValue)(declaration, staticValue);
108
+ if (!checked.ok)
109
+ throw new Error(`Static value of setting ${code} at ${declaration.staticRef} is invalid: ${checked.problems.map((p) => `${p.path || '(value)'}: ${p.message}`).join('; ')}`);
110
+ }
111
+ batch.add(code);
112
+ }
113
+ for (const declaration of declarations)
114
+ this.declarations.set(declaration.code, Object.freeze({ ...declaration }));
115
+ }
116
+ declared(code) {
117
+ return this.declarations.get(code);
118
+ }
119
+ declaredCodes() {
120
+ return [...this.declarations.keys()].sort();
121
+ }
122
+ // --- Resolution and cache ----------------------------------------------------------------------
123
+ invalidate(code) {
124
+ this.cache.delete(code);
125
+ this.generations.set(code, (this.generations.get(code) ?? 0) + 1);
126
+ }
127
+ async cachedRow(code) {
128
+ const now = this.now().getTime();
129
+ const hit = this.cache.get(code);
130
+ if (hit && hit.expiresAt > now)
131
+ return hit.row;
132
+ const generation = this.generations.get(code) ?? 0;
133
+ const row = await this.store.get(code);
134
+ this.remember(code, row, generation);
135
+ return row;
136
+ }
137
+ /** Caches a row read when the code was at `generation`, unless a local write happened since. */
138
+ remember(code, row, generation) {
139
+ if (this.config.cacheTtlMs > 0 && (this.generations.get(code) ?? 0) === generation)
140
+ this.cache.set(code, { row, expiresAt: this.now().getTime() + this.config.cacheTtlMs });
141
+ }
142
+ resolve(declaration, row) {
143
+ let overrideProblems;
144
+ if (row) {
145
+ const checked = (0, plugin_api_1.validateSettingValue)(declaration, row.value);
146
+ if (checked.ok)
147
+ return { value: checked.value, source: 'OVERRIDE', revision: row.revision };
148
+ // The declaration narrowed after the override was stored: fall back, keep the row visible.
149
+ overrideProblems = checked.problems;
150
+ this.logger.warn(`Override of ${declaration.code} no longer matches its declaration`);
151
+ }
152
+ const staticValue = this.staticValue(declaration);
153
+ if (staticValue !== undefined) {
154
+ const checked = (0, plugin_api_1.validateSettingValue)(declaration, staticValue);
155
+ if (checked.ok)
156
+ return {
157
+ value: checked.value,
158
+ source: 'STATIC',
159
+ revision: row?.revision ?? 0,
160
+ overrideProblems,
161
+ };
162
+ }
163
+ return {
164
+ value: this.defaultOf(declaration),
165
+ source: 'DEFAULT',
166
+ revision: row?.revision ?? 0,
167
+ overrideProblems,
168
+ };
169
+ }
170
+ defaultOf(declaration) {
171
+ const checked = (0, plugin_api_1.validateSettingValue)(declaration, declaration.default);
172
+ return checked.ok ? checked.value : declaration.default;
173
+ }
174
+ async get(code) {
175
+ const declaration = this.declarations.get(code);
176
+ if (!declaration)
177
+ throw notFound(code);
178
+ const { value, source, revision } = this.resolve(declaration, await this.cachedRow(code));
179
+ return { code, value: value, source, revision };
180
+ }
181
+ async value(code) {
182
+ return (await this.get(code)).value;
183
+ }
184
+ async evaluateFlag(code, subject) {
185
+ const declaration = this.declarations.get(code);
186
+ if (declaration?.kind !== 'flag')
187
+ throw new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.notFound, `Feature flag ${code} not found`, 404);
188
+ const value = await this.value(code);
189
+ const userId = subject.userId || null;
190
+ const roleNames = subject.roleNames ??
191
+ (userId && this.rbac ? (await (0, plugin_api_1.authorizationOfUser)(this.rbac, userId)).roleNames : []);
192
+ return { code, ...(0, plugin_api_1.evaluateSettingFlag)(code, value, { userId, roleNames }) };
193
+ }
194
+ async isEnabled(code, subject) {
195
+ return (await this.evaluateFlag(code, subject)).enabled;
196
+ }
197
+ // --- Authorization and validation --------------------------------------------------------------
198
+ async requirePermission(userId, permission) {
199
+ if (!userId)
200
+ throw new plugin_api_1.MechanismError('FORBIDDEN', 'A user identity is required', 403);
201
+ if (!(0, plugin_api_1.hasPermission)(await (0, plugin_api_1.authorizationOfUser)(this.rbac, userId), permission))
202
+ throw new plugin_api_1.MechanismError('FORBIDDEN', `${permission} is required`, 403);
203
+ }
204
+ /** Declaration check plus the configured byte limit; returns the normalized value. */
205
+ checkValue(declaration, value) {
206
+ const checked = (0, plugin_api_1.validateSettingValue)(declaration, value);
207
+ if (!checked.ok)
208
+ throw invalid(`Invalid value for ${declaration.code}`, checked.problems);
209
+ const bytes = utf8Bytes(JSON.stringify(checked.value));
210
+ if (bytes > this.config.maxValueBytes)
211
+ throw invalid(`Invalid value for ${declaration.code}`, [
212
+ { path: '', message: `Use at most ${this.config.maxValueBytes} bytes of JSON` },
213
+ ]);
214
+ return checked.value;
215
+ }
216
+ reason(value) {
217
+ if (value === undefined || value === null)
218
+ return null;
219
+ if (typeof value !== 'string' || [...value].length > REASON_MAX_LENGTH)
220
+ throw invalid('Invalid request', [
221
+ { path: 'reason', message: `Use at most ${REASON_MAX_LENGTH} characters` },
222
+ ]);
223
+ return value.trim() || null;
224
+ }
225
+ body(input, allowed) {
226
+ if (input === undefined || input === null)
227
+ return {};
228
+ if (!isRecord(input))
229
+ throw invalid('The request body must be a JSON object');
230
+ const unknown = Object.keys(input).filter((key) => !allowed.includes(key));
231
+ if (unknown.length)
232
+ throw invalid('Invalid request', unknown.map((path) => ({ path, message: 'Unknown property' })));
233
+ return input;
234
+ }
235
+ revision(value) {
236
+ if (value === undefined)
237
+ return undefined;
238
+ if (!Number.isSafeInteger(value) || value < 0)
239
+ throw invalid('Invalid request', [
240
+ { path: 'expectedRevision', message: 'Use a non-negative integer' },
241
+ ]);
242
+ return value;
243
+ }
244
+ page(query) {
245
+ const offset = query.offset ?? 0;
246
+ const limit = query.limit ?? Math.min(50, this.config.historyPageMaxLimit);
247
+ const problems = [];
248
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset > 100_000)
249
+ problems.push({ path: 'offset', message: 'Use an integer 0–100000' });
250
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > this.config.historyPageMaxLimit)
251
+ problems.push({
252
+ path: 'limit',
253
+ message: `Use an integer 1–${this.config.historyPageMaxLimit}`,
254
+ });
255
+ if (problems.length)
256
+ throw invalid('Invalid page', problems);
257
+ return { offset, limit };
258
+ }
259
+ // --- Views -------------------------------------------------------------------------------------
260
+ view(code, row) {
261
+ const declaration = this.declarations.get(code);
262
+ if (!declaration) {
263
+ if (!row)
264
+ throw notFound(code);
265
+ return {
266
+ code,
267
+ status: 'ORPHAN',
268
+ kind: null,
269
+ type: null,
270
+ description: null,
271
+ value: row.value,
272
+ source: 'OVERRIDE',
273
+ default: null,
274
+ constraints: {},
275
+ staticRef: null,
276
+ revision: row.revision,
277
+ updatedBy: row.updatedBy,
278
+ updatedAt: row.updatedAt,
279
+ };
280
+ }
281
+ const resolved = this.resolve(declaration, row);
282
+ const constraints = {};
283
+ for (const key of CONSTRAINT_KEYS)
284
+ if (declaration[key] !== undefined)
285
+ constraints[key] = declaration[key];
286
+ const known = declaration.knownItems?.();
287
+ return {
288
+ code,
289
+ status: 'DECLARED',
290
+ kind: declaration.kind,
291
+ type: declaration.type,
292
+ description: declaration.description,
293
+ value: resolved.value,
294
+ source: resolved.source,
295
+ default: this.defaultOf(declaration),
296
+ constraints,
297
+ staticRef: declaration.staticRef ?? null,
298
+ revision: row?.revision ?? 0,
299
+ updatedBy: row?.updatedBy ?? null,
300
+ updatedAt: row?.updatedAt ?? null,
301
+ ...(known
302
+ ? {
303
+ unknownItems: Array.isArray(resolved.value)
304
+ ? resolved.value.filter((item) => !known.includes(item))
305
+ : [],
306
+ }
307
+ : {}),
308
+ ...(resolved.overrideProblems
309
+ ? { overrideProblems: resolved.overrideProblems, storedValue: row?.value }
310
+ : {}),
311
+ };
312
+ }
313
+ async listFor(userId) {
314
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_READ_PERMISSION);
315
+ const rows = new Map((await this.store.list()).map((row) => [row.code, row]));
316
+ const codes = [...new Set([...this.declarations.keys(), ...rows.keys()])].sort();
317
+ return { items: codes.map((code) => this.view(code, rows.get(code) ?? null)) };
318
+ }
319
+ async getFor(userId, code) {
320
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_READ_PERMISSION);
321
+ const generation = this.generations.get(code) ?? 0;
322
+ const row = await this.store.get(code);
323
+ this.remember(code, row, generation);
324
+ return this.view(code, row);
325
+ }
326
+ // --- Writes ------------------------------------------------------------------------------------
327
+ async emit(tx, code, revision, actorId, operation, source) {
328
+ // Code, revision and actor only: values never leave the settings tables.
329
+ await this.events?.record(tx.client, {
330
+ aggregateType: 'Setting',
331
+ aggregateId: code,
332
+ eventType: plugin_api_1.SETTINGS_CHANGED_EVENT,
333
+ operation,
334
+ actorUserId: actorId,
335
+ before: null,
336
+ after: null,
337
+ changedFields: [],
338
+ metadata: { code, revision, actorId, source },
339
+ });
340
+ }
341
+ /** Inside the caller's transaction, under the code lock. Unchanged values write nothing. */
342
+ async applyWrite(tx, input) {
343
+ const current = await tx.getSetting(input.code);
344
+ const currentRevision = current?.revision ?? 0;
345
+ if (input.expectedRevision !== undefined && input.expectedRevision !== currentRevision)
346
+ throw new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.revisionConflict, 'The setting changed since you read it', 409, 'Reload the setting and apply your change again', [], { currentRevision });
347
+ if (current && canonicalSettingJson(current.value) === canonicalSettingJson(input.value))
348
+ return { row: current, changed: false };
349
+ const revision = currentRevision + 1;
350
+ const row = await tx.saveSetting(input.code, input.value, revision, input.actorId);
351
+ await tx.appendChange({
352
+ code: input.code,
353
+ before: (current?.value ?? null),
354
+ after: input.value,
355
+ actorId: input.actorId,
356
+ reason: input.reason,
357
+ source: input.source,
358
+ });
359
+ if (this.config.maxHistoryPerCode)
360
+ await tx.pruneHistory(input.code, this.config.maxHistoryPerCode);
361
+ await this.emit(tx, input.code, revision, input.actorId, current ? 'UPDATE' : 'CREATE', input.source);
362
+ return { row, changed: true };
363
+ }
364
+ async putFor(userId, code, input) {
365
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_WRITE_PERMISSION);
366
+ const body = this.body(input, ['value', 'expectedRevision', 'reason']);
367
+ const declaration = this.declarations.get(code);
368
+ if (!declaration)
369
+ throw notFound(code);
370
+ if (!('value' in body))
371
+ throw invalid('Invalid request', [{ path: 'value', message: 'Required' }]);
372
+ const value = this.checkValue(declaration, body.value);
373
+ const expectedRevision = this.revision(body.expectedRevision);
374
+ const reason = this.reason(body.reason);
375
+ let row;
376
+ try {
377
+ ({ row } = await this.store.transaction(async (tx) => {
378
+ await tx.lock(code);
379
+ return this.applyWrite(tx, {
380
+ code,
381
+ value,
382
+ actorId: userId,
383
+ reason,
384
+ source: 'HTTP',
385
+ expectedRevision,
386
+ });
387
+ }));
388
+ }
389
+ finally {
390
+ this.invalidate(code);
391
+ }
392
+ return this.view(code, row);
393
+ }
394
+ async deleteFor(userId, code, input = {}) {
395
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_WRITE_PERMISSION);
396
+ const body = this.body(input, ['expectedRevision', 'reason']);
397
+ const expectedRevision = this.revision(body.expectedRevision);
398
+ const reason = this.reason(body.reason);
399
+ try {
400
+ await this.store.transaction(async (tx) => {
401
+ await tx.lock(code);
402
+ const current = await tx.getSetting(code);
403
+ if (!current) {
404
+ if (!this.declarations.has(code))
405
+ throw notFound(code);
406
+ if (expectedRevision !== undefined && expectedRevision !== 0)
407
+ throw new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.revisionConflict, 'The setting changed since you read it', 409, 'Reload the setting and apply your change again', [], { currentRevision: 0 });
408
+ return;
409
+ }
410
+ if (expectedRevision !== undefined && expectedRevision !== current.revision)
411
+ throw new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.revisionConflict, 'The setting changed since you read it', 409, 'Reload the setting and apply your change again', [], { currentRevision: current.revision });
412
+ await tx.deleteSetting(code);
413
+ await tx.appendChange({
414
+ code,
415
+ before: current.value,
416
+ after: null,
417
+ actorId: userId,
418
+ reason,
419
+ source: 'HTTP',
420
+ });
421
+ if (this.config.maxHistoryPerCode)
422
+ await tx.pruneHistory(code, this.config.maxHistoryPerCode);
423
+ await this.emit(tx, code, 0, userId, 'DELETE', 'HTTP');
424
+ });
425
+ }
426
+ finally {
427
+ this.invalidate(code);
428
+ }
429
+ }
430
+ async historyFor(userId, code, query = {}) {
431
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_READ_PERMISSION);
432
+ const { offset, limit } = this.page(query);
433
+ const page = await this.store.history(code, offset, limit);
434
+ if (!page.total && !this.declarations.has(code) && !(await this.store.get(code)))
435
+ throw notFound(code);
436
+ return { ...page, offset, limit };
437
+ }
438
+ async evaluateFor(userId, code, input) {
439
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_READ_PERMISSION);
440
+ const body = this.body(input, ['userId']);
441
+ if (typeof body.userId !== 'string' || !body.userId || body.userId.length > ID_MAX_LENGTH)
442
+ throw invalid('Invalid request', [{ path: 'userId', message: 'Use a user id' }]);
443
+ const evaluation = await this.evaluateFlag(code, { userId: body.userId });
444
+ const { source, revision } = await this.get(code);
445
+ return { ...evaluation, userId: body.userId, source, revision };
446
+ }
447
+ // --- Proposals ---------------------------------------------------------------------------------
448
+ /**
449
+ * Agents propose; people apply. Validated exactly like a write. A new proposal replaces the
450
+ * code's pending one (marked REJECTED without a decider), so at most one is PENDING per code.
451
+ */
452
+ async proposeFor(userId, input) {
453
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_READ_PERMISSION);
454
+ const body = this.body(input, ['code', 'value', 'reason']);
455
+ const code = typeof body.code === 'string' ? body.code : '';
456
+ const declaration = this.declarations.get(code);
457
+ if (!declaration)
458
+ throw notFound(code || undefined);
459
+ if (!('value' in body))
460
+ throw invalid('Invalid request', [{ path: 'value', message: 'Required' }]);
461
+ const value = this.checkValue(declaration, body.value);
462
+ const reason = this.reason(body.reason);
463
+ return this.store.transaction(async (tx) => {
464
+ await tx.lock(code);
465
+ await tx.supersedePending(code, this.now());
466
+ return tx.createProposal({ code, value, reason, proposedBy: userId });
467
+ });
468
+ }
469
+ async proposalsFor(userId, query = {}) {
470
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_READ_PERMISSION);
471
+ if (query.status !== undefined &&
472
+ !plugin_api_1.SETTING_PROPOSAL_STATUSES.includes(query.status))
473
+ throw invalid('Invalid page', [
474
+ { path: 'status', message: 'Use PENDING, APPLIED or REJECTED' },
475
+ ]);
476
+ const { offset, limit } = this.page(query);
477
+ return { ...(await this.store.proposals(query.status, offset, limit)), offset, limit };
478
+ }
479
+ async decide(id, work) {
480
+ const first = await this.store.getProposal(id);
481
+ if (!first)
482
+ throw proposalNotFound();
483
+ try {
484
+ return await this.store.transaction(async (tx) => {
485
+ await tx.lock(first.code);
486
+ const proposal = await tx.getProposal(id);
487
+ if (!proposal)
488
+ throw proposalNotFound();
489
+ if (proposal.status !== 'PENDING')
490
+ throw new plugin_api_1.MechanismError(plugin_api_1.SETTING_ERROR_CODES.proposalNotPending, `The proposal is already ${proposal.status}`, 409);
491
+ return work(tx, proposal);
492
+ });
493
+ }
494
+ finally {
495
+ this.invalidate(first.code);
496
+ }
497
+ }
498
+ /** Applies the proposed value as the approver, audited with source PROPOSAL. */
499
+ async approveFor(userId, id, input = {}) {
500
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_WRITE_PERMISSION);
501
+ const body = this.body(input, ['reason']);
502
+ const reason = this.reason(body.reason);
503
+ const { proposal, row } = await this.decide(id, async (tx, proposal) => {
504
+ const declaration = this.declarations.get(proposal.code);
505
+ if (!declaration)
506
+ throw notFound(proposal.code);
507
+ const value = this.checkValue(declaration, proposal.value);
508
+ const { row } = await this.applyWrite(tx, {
509
+ code: proposal.code,
510
+ value,
511
+ actorId: userId,
512
+ reason: reason ?? proposal.reason,
513
+ source: 'PROPOSAL',
514
+ });
515
+ return { proposal: await tx.decideProposal(id, 'APPLIED', userId, this.now()), row };
516
+ });
517
+ return { proposal, setting: this.view(proposal.code, row) };
518
+ }
519
+ async rejectFor(userId, id, input = {}) {
520
+ await this.requirePermission(userId, plugin_api_1.SETTINGS_WRITE_PERMISSION);
521
+ this.body(input, []);
522
+ return this.decide(id, (tx) => tx.decideProposal(id, 'REJECTED', userId, this.now()));
523
+ }
524
+ };
525
+ exports.SettingsService = SettingsService;
526
+ exports.SettingsService = SettingsService = __decorate([
527
+ (0, common_1.Injectable)(),
528
+ __param(0, (0, common_1.Inject)(store_1.SETTINGS_STORE)),
529
+ __param(1, (0, common_1.Inject)(store_1.SETTINGS_CONFIG)),
530
+ __param(2, (0, common_1.Optional)()),
531
+ __param(2, (0, common_1.Inject)(plugin_api_1.RBAC_POLICY)),
532
+ __param(3, (0, common_1.Optional)()),
533
+ __param(3, (0, common_1.Inject)(plugin_api_1.DOMAIN_EVENTS)),
534
+ __param(4, (0, common_1.Optional)()),
535
+ __param(4, (0, common_1.Inject)(core_1.ModuleRef)),
536
+ __param(5, (0, common_1.Optional)()),
537
+ __param(5, (0, common_1.Inject)(store_1.SETTINGS_CLOCK)),
538
+ __metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object])
539
+ ], SettingsService);
540
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAiDA,oDAYC;AA7DD,qDA8B8B;AAC9B,iEAAoF;AACpF,2CAAsE;AACtE,uCAAyC;AACzC,qCAAkG;AAClG,mCAOiB;AAEjB,MAAM,eAAe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GAAG,CAAC,EAAE,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,EAAU,EAAE,QAAiB,EAAE;QAC7D,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,sCAAyB,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACxF,CAAC;CACF,CAAA;AA1hBY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,eAAM,EAAC,sBAAc,CAAC,CAAA;IACtB,WAAA,IAAA,eAAM,EAAC,uBAAe,CAAC,CAAA;IACvB,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,wBAAW,CAAC,CAAA;IAC/B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,0BAAa,CAAC,CAAA;IACjC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,gBAAS,CAAC,CAAA;IAC7B,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,sBAAc,CAAC,CAAA;;GAf1B,eAAe,CA0hB3B"}
@@ -0,0 +1,74 @@
1
+ import type { SettingChangeRecord, SettingChangeSource, SettingProposalRecord, SettingProposalStatus, SettingValue } from '@haneinfo/plugin-api';
2
+ export declare const SETTINGS_STORE: unique symbol;
3
+ export declare const SETTINGS_CONFIG: unique symbol;
4
+ /** Optional clock for cache expiry and decision times; defaults to the system clock. */
5
+ export declare const SETTINGS_CLOCK: unique symbol;
6
+ export interface StoredSetting {
7
+ code: string;
8
+ value: unknown;
9
+ revision: number;
10
+ updatedBy: string;
11
+ updatedAt: Date;
12
+ }
13
+ export interface NewSettingChange {
14
+ code: string;
15
+ /** Null: there was no override before (or none after, for a delete). */
16
+ before: SettingValue | null;
17
+ after: SettingValue | null;
18
+ actorId: string;
19
+ reason: string | null;
20
+ source: SettingChangeSource;
21
+ }
22
+ export interface Page<T> {
23
+ items: T[];
24
+ total: number;
25
+ }
26
+ /** Everything a write does happens inside one transaction, serialized per code. */
27
+ export interface SettingsStoreTx {
28
+ /** The raw transaction client, for capabilities such as domain events. */
29
+ readonly client: unknown;
30
+ /** Transaction-scoped advisory lock on one code: writes, deletes and proposals serialize. */
31
+ lock(code: string): Promise<void>;
32
+ getSetting(code: string): Promise<StoredSetting | null>;
33
+ saveSetting(code: string, value: SettingValue, revision: number, actorId: string): Promise<StoredSetting>;
34
+ deleteSetting(code: string): Promise<void>;
35
+ /** Append-only: there is no update or delete of a change record besides retention pruning. */
36
+ appendChange(change: NewSettingChange): Promise<void>;
37
+ /** Keeps the newest `keep` change records of a code. */
38
+ pruneHistory(code: string, keep: number): Promise<void>;
39
+ getProposal(id: string): Promise<SettingProposalRecord | null>;
40
+ /** Marks every PENDING proposal of the code REJECTED without a decider (replaced). */
41
+ supersedePending(code: string, at: Date): Promise<void>;
42
+ createProposal(input: {
43
+ code: string;
44
+ value: SettingValue;
45
+ reason: string | null;
46
+ proposedBy: string;
47
+ }): Promise<SettingProposalRecord>;
48
+ decideProposal(id: string, status: Exclude<SettingProposalStatus, 'PENDING'>, decidedBy: string, at: Date): Promise<SettingProposalRecord>;
49
+ }
50
+ export interface SettingsStore {
51
+ get(code: string): Promise<StoredSetting | null>;
52
+ list(): Promise<StoredSetting[]>;
53
+ history(code: string, offset: number, limit: number): Promise<Page<SettingChangeRecord>>;
54
+ proposals(status: SettingProposalStatus | undefined, offset: number, limit: number): Promise<Page<SettingProposalRecord>>;
55
+ getProposal(id: string): Promise<SettingProposalRecord | null>;
56
+ transaction<T>(work: (tx: SettingsStoreTx) => Promise<T>): Promise<T>;
57
+ }
58
+ export declare class PrismaSettingsStore implements SettingsStore {
59
+ private readonly db;
60
+ constructor(prisma: unknown);
61
+ get(code: string): Promise<StoredSetting | null>;
62
+ list(): Promise<StoredSetting[]>;
63
+ history(code: string, offset: number, limit: number): Promise<{
64
+ items: SettingChangeRecord[];
65
+ total: number;
66
+ }>;
67
+ proposals(status: SettingProposalStatus | undefined, offset: number, limit: number): Promise<{
68
+ items: SettingProposalRecord[];
69
+ total: number;
70
+ }>;
71
+ getProposal(id: string): Promise<SettingProposalRecord | null>;
72
+ transaction<T>(work: (tx: SettingsStoreTx) => Promise<T>): Promise<T>;
73
+ }
74
+ //# sourceMappingURL=store.d.ts.map