@jini-ai/user-management 0.7.3-next.3 → 0.7.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/CHANGELOG.md +7 -0
- package/dist/newsletter/confirmation.js +1 -1
- package/dist/newsletter/lists.js +2 -2
- package/dist/newsletter/ports.d.ts +7 -2
- package/dist/newsletter/repo-subscribers.d.ts +3 -2
- package/dist/newsletter/repo-subscribers.js +36 -14
- package/dist/newsletter/repo.memory.d.ts +3 -2
- package/dist/newsletter/repo.memory.js +25 -15
- package/dist/newsletter/save-guard.d.ts +32 -0
- package/dist/newsletter/save-guard.js +27 -0
- package/dist/newsletter/send-pipeline.d.ts +6 -2
- package/dist/newsletter/send-pipeline.js +1 -1
- package/dist/newsletter/subscriptions.js +2 -2
- package/dist/newsletter/unsubscribe.js +1 -1
- package/dist/server/agent-tool-registrations.js +6 -2
- package/dist/server/agent-tools.js +6 -4
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.4
|
|
4
|
+
|
|
5
|
+
### Changes
|
|
6
|
+
|
|
7
|
+
- Expand reusable identity, mail, newsletter, subscription, and consent services with host ports and named options.
|
|
8
|
+
- Compare saved versions for subscription and consent updates, honor cancellation after password hashing, and retain all newsletter send identifiers.
|
|
9
|
+
|
|
3
10
|
## 0.7.2
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -136,7 +136,7 @@ export async function consumeConfirmationToken(required, _optional = {}) {
|
|
|
136
136
|
subscribedAt: now,
|
|
137
137
|
updatedAt: now,
|
|
138
138
|
};
|
|
139
|
-
await deps.subscriptionRepo.save(updated);
|
|
139
|
+
await deps.subscriptionRepo.save(updated, { expected: subscription });
|
|
140
140
|
return { subscription: updated, changed: subscription.status !== "subscribed", eventId: `newsletter-subscribed:${token.id}` };
|
|
141
141
|
}
|
|
142
142
|
//# sourceMappingURL=confirmation.js.map
|
package/dist/newsletter/lists.js
CHANGED
|
@@ -27,7 +27,7 @@ export async function saveList(required, _optional = {}) {
|
|
|
27
27
|
if (!existing)
|
|
28
28
|
throw new NewsletterListNotFoundError(`list ${input.id} was not found`);
|
|
29
29
|
const list = { ...existing, name: input.name, slug: input.slug, updatedAt: now };
|
|
30
|
-
await deps.listRepo.save(list);
|
|
30
|
+
await deps.listRepo.save(list, { expected: existing });
|
|
31
31
|
return { list };
|
|
32
32
|
}
|
|
33
33
|
const list = {
|
|
@@ -53,7 +53,7 @@ export async function archiveList(required, _optional = {}) {
|
|
|
53
53
|
throw new NewsletterDefaultListProtectedError({ message: `the default list cannot be archived`, listId: existing.id });
|
|
54
54
|
}
|
|
55
55
|
const list = { ...existing, status: "archived", updatedAt: deps.clock.nowIso() };
|
|
56
|
-
await deps.listRepo.save(list);
|
|
56
|
+
await deps.listRepo.save(list, { expected: existing });
|
|
57
57
|
return { list };
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import type { UUID } from "@jini-ai/core/primitives";
|
|
25
25
|
import type { ListPage } from "@jini-ai/core/list-page";
|
|
26
|
+
import type { NewsletterSaveOptions } from "./save-guard.js";
|
|
27
|
+
export type { NewsletterSaveOptions } from "./save-guard.js";
|
|
26
28
|
import type { AudienceSnapshotRow, CampaignRecord, CampaignRevision, ConfirmationTokenRecord, NewsletterListRow, SendRow, SubscriptionRow } from "./types.js";
|
|
27
29
|
export type { PositionalMailer as MailerPort } from "@jini-ai/core/contracts/mail";
|
|
28
30
|
/** The subset of a Members-owned subscriber that Newsletter needs at send time. */
|
|
@@ -130,7 +132,8 @@ export interface NewsletterListRepoPort {
|
|
|
130
132
|
list(required: {
|
|
131
133
|
workspaceId: UUID;
|
|
132
134
|
}): Promise<NewsletterListRow[]>;
|
|
133
|
-
|
|
135
|
+
/** Atomically checks an expected snapshot; blind saves cannot restore an archived list. */
|
|
136
|
+
save(row: NewsletterListRow, optional?: NewsletterSaveOptions<NewsletterListRow>): Promise<void>;
|
|
134
137
|
}
|
|
135
138
|
/** C-003 — `p_newsletter__subscriptions`. */
|
|
136
139
|
export interface NewsletterSubscriptionRepoPort {
|
|
@@ -155,7 +158,9 @@ export interface NewsletterSubscriptionRepoPort {
|
|
|
155
158
|
workspaceId: UUID;
|
|
156
159
|
listId: UUID;
|
|
157
160
|
}): Promise<SubscriptionRow[]>;
|
|
158
|
-
|
|
161
|
+
/** Atomically checks an expected snapshot; blind saves cannot undo an opt-out or suppression.
|
|
162
|
+
* Re-subscription requires a fresh expected snapshot, supplied by confirmation after consent. */
|
|
163
|
+
save(row: SubscriptionRow, optional?: NewsletterSaveOptions<SubscriptionRow>): Promise<void>;
|
|
159
164
|
remove(required: {
|
|
160
165
|
workspaceId: UUID;
|
|
161
166
|
id: UUID;
|
|
@@ -4,6 +4,7 @@ import type { StorageKernel } from "@jini-ai/core/contracts/storage";
|
|
|
4
4
|
import type { NewsletterConfirmationTokenRepoPort, NewsletterListRepoPort, NewsletterSubscriptionRepoPort } from "./ports.js";
|
|
5
5
|
import { type NewsletterSqlRequired, type NewsletterSqlTables } from "./repo.rows.js";
|
|
6
6
|
import type { ConfirmationTokenRecord, NewsletterListRow, SubscriptionRow } from "./types.js";
|
|
7
|
+
import { type NewsletterSaveOptions } from "./save-guard.js";
|
|
7
8
|
/**
|
|
8
9
|
* @file The list, subscription and confirmation-token repositories over the host's
|
|
9
10
|
* `p_newsletter__*` dataModule tables: one Kysely query body for every dialect, the table names
|
|
@@ -24,7 +25,7 @@ export declare class SqlNewsletterListRepo implements NewsletterListRepoPort {
|
|
|
24
25
|
list(required: {
|
|
25
26
|
workspaceId: string;
|
|
26
27
|
}): Promise<NewsletterListRow[]>;
|
|
27
|
-
save(row: NewsletterListRow): Promise<void>;
|
|
28
|
+
save(row: NewsletterListRow, optional?: NewsletterSaveOptions<NewsletterListRow>): Promise<void>;
|
|
28
29
|
}
|
|
29
30
|
export declare class SqlNewsletterSubscriptionRepo implements NewsletterSubscriptionRepoPort {
|
|
30
31
|
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
@@ -54,7 +55,7 @@ export declare class SqlNewsletterSubscriptionRepo implements NewsletterSubscrip
|
|
|
54
55
|
workspaceId: string;
|
|
55
56
|
listId: string;
|
|
56
57
|
}): Promise<SubscriptionRow[]>;
|
|
57
|
-
save(row: SubscriptionRow): Promise<void>;
|
|
58
|
+
save(row: SubscriptionRow, optional?: NewsletterSaveOptions<SubscriptionRow>): Promise<void>;
|
|
58
59
|
remove(required: {
|
|
59
60
|
workspaceId: string;
|
|
60
61
|
id: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { decodeListCursor, pageFromOverfetch } from "@jini-ai/core/list-page";
|
|
2
2
|
import { toConfirmationTokenRecord, toConfirmationTokenRow, toListRecord, toListRow, toSubscriptionRecord, toSubscriptionRow, updatableListColumns, updatableSubscriptionColumns, } from "./repo.rows.js";
|
|
3
|
+
import { newsletterSaveConflict, newsletterSaveGuard } from "./save-guard.js";
|
|
3
4
|
/**
|
|
4
5
|
* @file The list, subscription and confirmation-token repositories over the host's
|
|
5
6
|
* `p_newsletter__*` dataModule tables: one Kysely query body for every dialect, the table names
|
|
@@ -45,14 +46,25 @@ export class SqlNewsletterListRepo {
|
|
|
45
46
|
.execute());
|
|
46
47
|
return rows.map(toListRecord);
|
|
47
48
|
}
|
|
48
|
-
async save(row) {
|
|
49
|
+
async save(row, optional = {}) {
|
|
49
50
|
const values = toListRow(row);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const guard = newsletterSaveGuard({ row, options: optional });
|
|
52
|
+
const saved = await this.kernel.run((db) => {
|
|
53
|
+
const connection = db.withTables();
|
|
54
|
+
// An expected existing row uses UPDATE so a concurrent removal cannot recreate it.
|
|
55
|
+
if (optional.expected)
|
|
56
|
+
return connection.updateTable(this.tables.lists)
|
|
57
|
+
.set(updatableListColumns(values))
|
|
58
|
+
.where("workspace_id", "=", row.workspaceId).where("id", "=", row.id)
|
|
59
|
+
.where("status", "=", optional.expected.status).where("updated_at", "=", optional.expected.updatedAt)
|
|
60
|
+
.returning("id").executeTakeFirst();
|
|
61
|
+
return connection.insertInto(this.tables.lists).values(values)
|
|
62
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(updatableListColumns(values))
|
|
63
|
+
.where("status", "in", guard.statuses))
|
|
64
|
+
.returning("id").executeTakeFirst();
|
|
65
|
+
});
|
|
66
|
+
if (!saved)
|
|
67
|
+
throw newsletterSaveConflict({ row, entity: "list" });
|
|
56
68
|
}
|
|
57
69
|
}
|
|
58
70
|
export class SqlNewsletterSubscriptionRepo {
|
|
@@ -120,14 +132,24 @@ export class SqlNewsletterSubscriptionRepo {
|
|
|
120
132
|
.execute());
|
|
121
133
|
return rows.map(toSubscriptionRecord);
|
|
122
134
|
}
|
|
123
|
-
async save(row) {
|
|
135
|
+
async save(row, optional = {}) {
|
|
124
136
|
const values = toSubscriptionRow(row);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.
|
|
128
|
-
.
|
|
129
|
-
|
|
130
|
-
|
|
137
|
+
const guard = newsletterSaveGuard({ row, options: optional });
|
|
138
|
+
const saved = await this.kernel.run((db) => {
|
|
139
|
+
const connection = db.withTables();
|
|
140
|
+
if (optional.expected)
|
|
141
|
+
return connection.updateTable(this.tables.subscriptions)
|
|
142
|
+
.set(updatableSubscriptionColumns(values))
|
|
143
|
+
.where("workspace_id", "=", row.workspaceId).where("id", "=", row.id)
|
|
144
|
+
.where("status", "=", optional.expected.status).where("updated_at", "=", optional.expected.updatedAt)
|
|
145
|
+
.returning("id").executeTakeFirst();
|
|
146
|
+
return connection.insertInto(this.tables.subscriptions).values(values)
|
|
147
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(updatableSubscriptionColumns(values))
|
|
148
|
+
.where("status", "in", guard.statuses))
|
|
149
|
+
.returning("id").executeTakeFirst();
|
|
150
|
+
});
|
|
151
|
+
if (!saved)
|
|
152
|
+
throw newsletterSaveConflict({ row, entity: "subscription" });
|
|
131
153
|
}
|
|
132
154
|
async remove(required) {
|
|
133
155
|
await this.kernel.run((db) => db
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ListPage } from "@jini-ai/core/list-page";
|
|
2
|
+
import { type NewsletterSaveOptions } from "./save-guard.js";
|
|
2
3
|
import type { AudienceSnapshotRow, CampaignRecord, CampaignRevision, ConfirmationTokenRecord, NewsletterListRow, SendRow, SubscriptionRow } from "./types.js";
|
|
3
4
|
import type { CampaignOutcomeCounter, NewsletterAudienceSnapshotRepoPort, NewsletterCampaignRepoPort, NewsletterConfirmationTokenRepoPort, NewsletterListRepoPort, NewsletterSendRepoPort, NewsletterSubscriptionRepoPort } from "./ports.js";
|
|
4
5
|
export declare class InMemoryNewsletterCampaignRepo implements NewsletterCampaignRepoPort {
|
|
@@ -66,7 +67,7 @@ export declare class InMemoryNewsletterListRepo implements NewsletterListRepoPor
|
|
|
66
67
|
list(required: {
|
|
67
68
|
workspaceId: string;
|
|
68
69
|
}): Promise<NewsletterListRow[]>;
|
|
69
|
-
save(row: NewsletterListRow): Promise<void>;
|
|
70
|
+
save(row: NewsletterListRow, optional?: NewsletterSaveOptions<NewsletterListRow>): Promise<void>;
|
|
70
71
|
}
|
|
71
72
|
export declare class InMemoryNewsletterSubscriptionRepo implements NewsletterSubscriptionRepoPort {
|
|
72
73
|
private rows;
|
|
@@ -97,7 +98,7 @@ export declare class InMemoryNewsletterSubscriptionRepo implements NewsletterSub
|
|
|
97
98
|
workspaceId: string;
|
|
98
99
|
listId: string;
|
|
99
100
|
}): Promise<SubscriptionRow[]>;
|
|
100
|
-
save(row: SubscriptionRow): Promise<void>;
|
|
101
|
+
save(row: SubscriptionRow, optional?: NewsletterSaveOptions<SubscriptionRow>): Promise<void>;
|
|
101
102
|
remove(required: {
|
|
102
103
|
workspaceId: string;
|
|
103
104
|
id: string;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { upsertRecord } from "@jini-ai/core/records";
|
|
9
9
|
import { decodeListCursor, pageFromArray } from "@jini-ai/core/list-page";
|
|
10
|
+
import { assertNewsletterSave } from "./save-guard.js";
|
|
10
11
|
const DEFAULT_LIST_LIMIT = 100;
|
|
11
12
|
export class InMemoryNewsletterCampaignRepo {
|
|
12
13
|
campaigns;
|
|
@@ -77,33 +78,40 @@ export class InMemoryNewsletterCampaignRepo {
|
|
|
77
78
|
export class InMemoryNewsletterListRepo {
|
|
78
79
|
rows;
|
|
79
80
|
constructor(_required = {}, { initialRows = [] } = {}) {
|
|
80
|
-
|
|
81
|
+
// Read/write snapshots must not let callers mutate stored state around the save guard.
|
|
82
|
+
this.rows = initialRows.map((row) => ({ ...row }));
|
|
81
83
|
}
|
|
82
84
|
async findById(required) {
|
|
83
|
-
|
|
85
|
+
const row = this.rows.find((r) => r.workspaceId === required.workspaceId && r.id === required.id);
|
|
86
|
+
return row ? { ...row } : null;
|
|
84
87
|
}
|
|
85
88
|
async findDefault(required) {
|
|
86
|
-
|
|
89
|
+
const row = this.rows.find((r) => r.workspaceId === required.workspaceId && r.isDefault);
|
|
90
|
+
return row ? { ...row } : null;
|
|
87
91
|
}
|
|
88
92
|
async list(required) {
|
|
89
|
-
return this.rows.filter((r) => r.workspaceId === required.workspaceId);
|
|
93
|
+
return this.rows.filter((r) => r.workspaceId === required.workspaceId).map((row) => ({ ...row }));
|
|
90
94
|
}
|
|
91
|
-
async save(row) {
|
|
92
|
-
|
|
95
|
+
async save(row, optional = {}) {
|
|
96
|
+
const current = this.rows.find((item) => item.workspaceId === row.workspaceId && item.id === row.id);
|
|
97
|
+
assertNewsletterSave({ row, current, options: optional, entity: "list" });
|
|
98
|
+
upsertRecord({ records: this.rows, record: { ...row }, identity: { workspaceId: row.workspaceId, id: row.id } });
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
export class InMemoryNewsletterSubscriptionRepo {
|
|
96
102
|
rows;
|
|
97
103
|
constructor(_required = {}, { initialRows = [] } = {}) {
|
|
98
|
-
|
|
104
|
+
// Match SQL snapshots: caller-owned objects must never alias stored rows.
|
|
105
|
+
this.rows = initialRows.map((row) => ({ ...row }));
|
|
99
106
|
}
|
|
100
107
|
async findById(required) {
|
|
101
|
-
|
|
108
|
+
const row = this.rows.find((r) => r.workspaceId === required.workspaceId && r.id === required.id);
|
|
109
|
+
return row ? { ...row } : null;
|
|
102
110
|
}
|
|
103
111
|
async findBySubscriberAndList(required) {
|
|
104
|
-
|
|
105
|
-
r.listId === required.listId &&
|
|
106
|
-
|
|
112
|
+
const row = this.rows.find((r) => r.workspaceId === required.workspaceId &&
|
|
113
|
+
r.listId === required.listId && r.subscriberId === required.subscriberId);
|
|
114
|
+
return row ? { ...row } : null;
|
|
107
115
|
}
|
|
108
116
|
/** Lists one list's subscriptions with the SQL adapter's position-based contract.
|
|
109
117
|
* @throws {ToolInputError} If the cursor is malformed, even for an empty list.
|
|
@@ -113,14 +121,16 @@ export class InMemoryNewsletterSubscriptionRepo {
|
|
|
113
121
|
const limit = Math.min(optional.limit ?? DEFAULT_LIST_LIMIT, DEFAULT_LIST_LIMIT);
|
|
114
122
|
if (optional.cursor != null)
|
|
115
123
|
decodeListCursor({ cursor: optional.cursor, shape: ['string'] });
|
|
116
|
-
return pageFromArray({ rows: this.rows.filter(r => r.workspaceId === required.workspaceId && r.listId === required.listId),
|
|
124
|
+
return pageFromArray({ rows: this.rows.filter(r => r.workspaceId === required.workspaceId && r.listId === required.listId).map(row => ({ ...row })),
|
|
117
125
|
limit, cursor: optional.cursor ?? null, positionOf: row => [row.id], shape: ['string'] });
|
|
118
126
|
}
|
|
119
127
|
async listSubscribed(required) {
|
|
120
|
-
return this.rows.filter((r) => r.workspaceId === required.workspaceId && r.listId === required.listId && r.status === "subscribed");
|
|
128
|
+
return this.rows.filter((r) => r.workspaceId === required.workspaceId && r.listId === required.listId && r.status === "subscribed").map((row) => ({ ...row }));
|
|
121
129
|
}
|
|
122
|
-
async save(row) {
|
|
123
|
-
|
|
130
|
+
async save(row, optional = {}) {
|
|
131
|
+
const current = this.rows.find((item) => item.workspaceId === row.workspaceId && item.id === row.id);
|
|
132
|
+
assertNewsletterSave({ row, current, options: optional, entity: "subscription" });
|
|
133
|
+
upsertRecord({ records: this.rows, record: { ...row }, identity: { workspaceId: row.workspaceId, id: row.id } });
|
|
124
134
|
}
|
|
125
135
|
async remove(required) {
|
|
126
136
|
this.rows = this.rows.filter((r) => !(r.workspaceId === required.workspaceId && r.id === required.id));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NewsletterConflictError } from "./errors.js";
|
|
2
|
+
import type { NewsletterListRow, SubscriptionRow } from "./types.js";
|
|
3
|
+
type SaveState = Pick<NewsletterListRow | SubscriptionRow, "status" | "updatedAt">;
|
|
4
|
+
export interface NewsletterSaveOptions<Row extends SaveState> {
|
|
5
|
+
/** A fresh read authorizes a state transition only while its status and timestamp still match. */
|
|
6
|
+
expected?: Pick<Row, "status" | "updatedAt">;
|
|
7
|
+
}
|
|
8
|
+
/** Blind saves must not undo an archive or suppression. Explicit fresh snapshots still allow
|
|
9
|
+
* deliberate re-subscription; ordering timestamps alone cannot distinguish these transitions. */
|
|
10
|
+
export declare function newsletterSaveGuard({ row, options }: {
|
|
11
|
+
row: SaveState;
|
|
12
|
+
options: NewsletterSaveOptions<SaveState>;
|
|
13
|
+
}): {
|
|
14
|
+
statuses: SaveState["status"][];
|
|
15
|
+
updatedAt?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function newsletterSaveConflict({ row, entity }: {
|
|
18
|
+
row: {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
entity: "list" | "subscription";
|
|
22
|
+
}): NewsletterConflictError;
|
|
23
|
+
export declare function assertNewsletterSave({ row, current, options, entity }: {
|
|
24
|
+
row: SaveState & {
|
|
25
|
+
id: string;
|
|
26
|
+
};
|
|
27
|
+
current: SaveState | undefined;
|
|
28
|
+
options: NewsletterSaveOptions<SaveState>;
|
|
29
|
+
entity: "list" | "subscription";
|
|
30
|
+
}): void;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=save-guard.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NewsletterConflictError } from "./errors.js";
|
|
2
|
+
/** Blind saves must not undo an archive or suppression. Explicit fresh snapshots still allow
|
|
3
|
+
* deliberate re-subscription; ordering timestamps alone cannot distinguish these transitions. */
|
|
4
|
+
export function newsletterSaveGuard({ row, options }) {
|
|
5
|
+
if (options.expected)
|
|
6
|
+
return { statuses: [options.expected.status], updatedAt: options.expected.updatedAt };
|
|
7
|
+
if (row.status === "active" || row.status === "pending")
|
|
8
|
+
return { statuses: [row.status] };
|
|
9
|
+
if (row.status === "subscribed")
|
|
10
|
+
return { statuses: ["pending", "subscribed"] };
|
|
11
|
+
return { statuses: ["active", "archived", "pending", "subscribed", "unsubscribed", "bounced", "complained"] };
|
|
12
|
+
}
|
|
13
|
+
export function newsletterSaveConflict({ row, entity }) {
|
|
14
|
+
// These tables have no numeric version. Keep the existing conflict ABI's inert placeholders.
|
|
15
|
+
return new NewsletterConflictError({ message: "The saved state changed. Read it again before saving.",
|
|
16
|
+
entity, id: row.id, expectedVersion: 0, actualVersion: 0 });
|
|
17
|
+
}
|
|
18
|
+
export function assertNewsletterSave({ row, current, options, entity }) {
|
|
19
|
+
const guard = newsletterSaveGuard({ row, options });
|
|
20
|
+
if (!current && !options.expected)
|
|
21
|
+
return;
|
|
22
|
+
if (!current || !guard.statuses.includes(current.status) ||
|
|
23
|
+
(guard.updatedAt !== undefined && current.updatedAt !== guard.updatedAt)) {
|
|
24
|
+
throw newsletterSaveConflict({ row, entity });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=save-guard.js.map
|
|
@@ -140,10 +140,14 @@ export declare function dispatchRow(required: {
|
|
|
140
140
|
/** The subscription's consent revision, bound into the unsubscribe token (INV-04). */
|
|
141
141
|
consentRevisionId?: string | null;
|
|
142
142
|
}, _optional?: Record<string, never>): Promise<{
|
|
143
|
-
outcome: "sent" | "suppressed" | "failed"
|
|
143
|
+
outcome: "sent" | "suppressed" | "failed";
|
|
144
144
|
providerMessageId: string | null;
|
|
145
145
|
error: string | null;
|
|
146
|
-
|
|
146
|
+
} | {
|
|
147
|
+
outcome: "deferred";
|
|
148
|
+
providerMessageId: null;
|
|
149
|
+
error: string;
|
|
150
|
+
retryAfterMs: number;
|
|
147
151
|
}>;
|
|
148
152
|
/**
|
|
149
153
|
* REQ-24/INV-02 — records one send row's outcome with the atomic `recordOutcome` (2026-09-16; it was a read-then-write
|
|
@@ -401,7 +401,7 @@ async function dispatchAndRecord(required) {
|
|
|
401
401
|
});
|
|
402
402
|
// Rate limited: leave the row pending (its lease expires) so the retried batch sends it later.
|
|
403
403
|
if (dispatchResult.outcome === "deferred")
|
|
404
|
-
return { kind: "deferred", retryAfterMs: dispatchResult.retryAfterMs
|
|
404
|
+
return { kind: "deferred", retryAfterMs: dispatchResult.retryAfterMs };
|
|
405
405
|
// BUG FIX: `recordResult` is the ONLY place a send row's status ever leaves "pending" --
|
|
406
406
|
// `dispatchRow` above never writes. Previously this call was skipped for a "suppressed"
|
|
407
407
|
// outcome, which left the row at "pending" forever: `countPendingByCampaign` could never reach
|
|
@@ -37,7 +37,7 @@ export async function saveSubscription(required, _optional = {}) {
|
|
|
37
37
|
createdAt: now,
|
|
38
38
|
updatedAt: now,
|
|
39
39
|
};
|
|
40
|
-
await deps.subscriptionRepo.save(subscription);
|
|
40
|
+
await deps.subscriptionRepo.save(subscription, existing ? { expected: existing } : {});
|
|
41
41
|
await issueConfirmationToken({
|
|
42
42
|
deps: deps.confirmationDeps,
|
|
43
43
|
input: { workspaceId: input.workspaceId, subscriptionId: subscription.id, recipientEmail: contact.email },
|
|
@@ -68,7 +68,7 @@ export async function unsubscribeSubscription(required, _optional = {}) {
|
|
|
68
68
|
}
|
|
69
69
|
const now = deps.clock.nowIso();
|
|
70
70
|
const updated = { ...existing, status: "unsubscribed", unsubscribedAt: now, updatedAt: now };
|
|
71
|
-
await deps.subscriptionRepo.save(updated);
|
|
71
|
+
await deps.subscriptionRepo.save(updated, { expected: existing });
|
|
72
72
|
return { subscription: updated };
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
@@ -88,7 +88,7 @@ export async function processUnsubscribe(required, _optional = {}) {
|
|
|
88
88
|
}
|
|
89
89
|
const now = deps.clock.nowIso();
|
|
90
90
|
const updated = { ...subscription, status: "unsubscribed", unsubscribedAt: now, updatedAt: now };
|
|
91
|
-
await deps.subscriptionRepo.save(updated);
|
|
91
|
+
await deps.subscriptionRepo.save(updated, { expected: subscription });
|
|
92
92
|
return { outcome: "unsubscribed" };
|
|
93
93
|
}
|
|
94
94
|
/** Constant-time hex comparison (defense in depth against signature timing attacks). */
|
|
@@ -185,6 +185,8 @@ async function assertIdentityReadAllowed(routeDeps, toolId, callerPrincipalId) {
|
|
|
185
185
|
function toIdentityUserView(record) {
|
|
186
186
|
const view = {
|
|
187
187
|
principalId: record.principal.id,
|
|
188
|
+
// Return the profile's read basis; a later server read cannot replace the editor's version.
|
|
189
|
+
version: record.user.version,
|
|
188
190
|
username: record.user.username,
|
|
189
191
|
status: record.principal.status,
|
|
190
192
|
roleIds: [...record.roleIds],
|
|
@@ -331,6 +333,7 @@ function createIdentityUserCreateHandler(routeDeps, serviceDeps) {
|
|
|
331
333
|
}
|
|
332
334
|
function createIdentityUserUpdateEmailHandler(routeDeps, serviceDeps) {
|
|
333
335
|
return async (ctx) => {
|
|
336
|
+
requireEditorBasis({ toolId: "identity_user_update_email", readTool: "identity_user_list", input: ctx.input });
|
|
334
337
|
const input = identityInput({ toolId: "identity_user_update_email", input: ctx.input });
|
|
335
338
|
const { user } = await updateUser({
|
|
336
339
|
deps: serviceDeps(),
|
|
@@ -341,7 +344,7 @@ function createIdentityUserUpdateEmailHandler(routeDeps, serviceDeps) {
|
|
|
341
344
|
// Absent stays absent: `updateUser` treats a falsy email as "clear", which is exactly
|
|
342
345
|
// what this tool's description tells the model omitting it does.
|
|
343
346
|
},
|
|
344
|
-
}, { email: input.opt("email") });
|
|
347
|
+
}, { email: input.opt("email"), expectedVersion: input.int("expectedVersion") });
|
|
345
348
|
const principal = await routeDeps.principalRepo.findById({ workspaceId: routeDeps.workspaceId, id: input.req("principalId") });
|
|
346
349
|
if (!principal)
|
|
347
350
|
throw new Error(`principal '${input.req("principalId")}' was not found`);
|
|
@@ -350,13 +353,14 @@ function createIdentityUserUpdateEmailHandler(routeDeps, serviceDeps) {
|
|
|
350
353
|
}
|
|
351
354
|
function createIdentityUserChangeUsernameHandler(routeDeps, serviceDeps) {
|
|
352
355
|
return async (ctx) => {
|
|
356
|
+
requireEditorBasis({ toolId: "identity_user_change_username", readTool: "identity_user_list", input: ctx.input });
|
|
353
357
|
const input = identityInput({ toolId: "identity_user_change_username", input: ctx.input });
|
|
354
358
|
const principalId = input.req("principalId");
|
|
355
359
|
const { user } = await updateUser({
|
|
356
360
|
deps: serviceDeps(), input: {
|
|
357
361
|
workspaceId: routeDeps.workspaceId, callerPrincipalId: ctx.principal.id, principalId,
|
|
358
362
|
}
|
|
359
|
-
}, { username: input.req("username") });
|
|
363
|
+
}, { username: input.req("username"), expectedVersion: input.int("expectedVersion") });
|
|
360
364
|
const principal = await routeDeps.principalRepo.findById({ workspaceId: routeDeps.workspaceId, id: principalId });
|
|
361
365
|
if (!principal)
|
|
362
366
|
throw new Error(`principal '${principalId}' was not found`);
|
|
@@ -63,7 +63,7 @@ const PRINCIPAL_ONLY_INPUT_SCHEMA = {
|
|
|
63
63
|
export const identityAgentToolCatalog = [
|
|
64
64
|
{
|
|
65
65
|
name: "identity_user_list",
|
|
66
|
-
description: "Lists the workspace's human operator users with their principalId, username, status, and assigned role ids. Read-only. Call this to find a user's principalId before updating, disabling, enabling, or assigning a role to them. There is no password-reset tool. The owner resets a user's password from the Users screen in the admin (Reset password).",
|
|
66
|
+
description: "Lists the workspace's human operator users with their principalId, version, username, status, and assigned role ids. Read-only. Call this to find a user's principalId before updating, disabling, enabling, or assigning a role to them. Pass the returned version as expectedVersion when editing email or username; a stale edit is refused. There is no password-reset tool. The owner resets a user's password from the Users screen in the admin (Reset password).",
|
|
67
67
|
sideEffects: "none",
|
|
68
68
|
authorization: { permission: USER_MANAGE, orPermission: "member.manage" },
|
|
69
69
|
inputSchema: NO_INPUT_SCHEMA,
|
|
@@ -114,10 +114,11 @@ export const identityAgentToolCatalog = [
|
|
|
114
114
|
inputSchema: {
|
|
115
115
|
type: "object",
|
|
116
116
|
additionalProperties: false,
|
|
117
|
-
required: ["principalId"],
|
|
117
|
+
required: ["principalId", "expectedVersion"],
|
|
118
118
|
properties: {
|
|
119
119
|
principalId: PRINCIPAL_ID_SCHEMA,
|
|
120
120
|
email: { type: "string", description: "The new email. Omit it or pass an empty string to clear the stored value." },
|
|
121
|
+
expectedVersion: editorBasisSchema({ readTool: "identity_user_list", noun: "user" }),
|
|
121
122
|
},
|
|
122
123
|
},
|
|
123
124
|
},
|
|
@@ -127,12 +128,13 @@ export const identityAgentToolCatalog = [
|
|
|
127
128
|
sideEffects: MUTATES_DURABLE_STATE,
|
|
128
129
|
authorization: { permission: USER_MANAGE },
|
|
129
130
|
inputSchema: {
|
|
130
|
-
type: "object", additionalProperties: false, required: ["principalId", "username"],
|
|
131
|
+
type: "object", additionalProperties: false, required: ["principalId", "username", "expectedVersion"],
|
|
131
132
|
properties: {
|
|
132
133
|
principalId: PRINCIPAL_ID_SCHEMA, username: {
|
|
133
134
|
type: "string", minLength: 1,
|
|
134
135
|
description: "New login name. Trimmed, lowercased and Unicode NFC normalized; unique per workspace, including users in Trash."
|
|
135
|
-
}
|
|
136
|
+
},
|
|
137
|
+
expectedVersion: editorBasisSchema({ readTool: "identity_user_list", noun: "user" }),
|
|
136
138
|
},
|
|
137
139
|
},
|
|
138
140
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/user-management",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Runtime-separated user management contracts and Node authentication, authorization, and administration services.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -168,7 +168,7 @@
|
|
|
168
168
|
"./identity/sql/kernel-user-purge": "universal"
|
|
169
169
|
},
|
|
170
170
|
"optionalPeers": {
|
|
171
|
-
"kysely": "opt-in: sql storage adapters; import @jini-ai/user-management/
|
|
171
|
+
"kysely": "opt-in: sql storage adapters; import @jini-ai/user-management/identity/repo — SQL storage adapters could not load kysely. Install kysely to enable this feature, or check its installed version and native binaries.",
|
|
172
172
|
"argon2": "opt-in: argon2 password hashing; import @jini-ai/user-management/server — Argon2 password hashing could not load argon2. Install argon2 to enable this feature, or check its installed version and native binaries.",
|
|
173
173
|
"@jini-ai/ui-kit": "opt-in: ui kit integrations; import @jini-ai/user-management/admin/react — UI kit integrations could not load @jini-ai/ui-kit. Install @jini-ai/ui-kit to enable this feature, or check its installed version and native binaries.",
|
|
174
174
|
"react": "opt-in: react user-management ui; import @jini-ai/user-management/react — React user-management UI could not load react. Install react to enable this feature, or check its installed version.",
|
|
@@ -997,10 +997,10 @@
|
|
|
997
997
|
"@simplewebauthn/browser": "14.0.0",
|
|
998
998
|
"@simplewebauthn/server": "14.0.3",
|
|
999
999
|
"otplib": "13.6.0",
|
|
1000
|
-
"@jini-ai/core": "^0.7.
|
|
1000
|
+
"@jini-ai/core": "^0.7.4"
|
|
1001
1001
|
},
|
|
1002
1002
|
"peerDependencies": {
|
|
1003
|
-
"@jini-ai/ui-kit": "^0.7.
|
|
1003
|
+
"@jini-ai/ui-kit": "^0.7.4",
|
|
1004
1004
|
"argon2": "^0.44.0",
|
|
1005
1005
|
"kysely": "^0.29.6",
|
|
1006
1006
|
"react": "^18.3.0 || ^19.0.0",
|
|
@@ -1022,13 +1022,13 @@
|
|
|
1022
1022
|
"react-dom": "^19.2.0",
|
|
1023
1023
|
"typescript": "^5.6.0",
|
|
1024
1024
|
"vitest": "^3.2.6",
|
|
1025
|
-
"@jini-ai/
|
|
1026
|
-
"@jini-ai/
|
|
1027
|
-
"@jini-ai/ui": "0.7.
|
|
1028
|
-
"@jini-ai/
|
|
1029
|
-
"@jini-ai/
|
|
1030
|
-
"@jini-ai/
|
|
1031
|
-
"@jini-ai/
|
|
1025
|
+
"@jini-ai/ui": "0.7.4",
|
|
1026
|
+
"@jini-ai/admin": "0.7.4",
|
|
1027
|
+
"@jini-ai/ui-kit": "^0.7.4",
|
|
1028
|
+
"@jini-ai/core": "^0.7.4",
|
|
1029
|
+
"@jini-ai/platform": "0.7.4",
|
|
1030
|
+
"@jini-ai/db": "0.7.4",
|
|
1031
|
+
"@jini-ai/cms": "0.7.4"
|
|
1032
1032
|
},
|
|
1033
1033
|
"peerDependenciesMeta": {
|
|
1034
1034
|
"argon2": {
|