Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function registerMemberCommands(program: Command): void {
.option('--limit <numberOrAll>', 'Number of members per page or "all"')
.option('--page <number>', 'Page number')
.option('--filter <nql>', 'NQL filter')
.option('--status <status>', 'Member status (free|paid|comped)')
.option('--status <status>', 'Member status (free|paid|comped|gift)')
.option('--search <term>', 'Search term')
.option('--include <relations>', 'Include relationships')
.option('--fields <fields>', 'Select output fields')
Expand Down
3 changes: 2 additions & 1 deletion src/lib/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ function normalizeMembersSeries(rows: Record<string, unknown>[]): StatsSeriesPoi
row.count ??
getNumber(row.free_members ?? row.free) +
getNumber(row.paid_members ?? row.paid) +
getNumber(row.comped),
getNumber(row.comped) +
getNumber(row.gift),
),
mrr: null,
subscriptions: null,
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const MemberListInputSchema = z.object({
limit: z.union([z.number().int().positive().max(100), z.literal('all')]).optional(),
page: z.number().int().positive().optional(),
filter: z.string().optional(),
status: z.enum(['free', 'paid', 'comped']).optional(),
status: z.enum(['free', 'paid', 'comped', 'gift']).optional(),
search: z.string().optional(),
include: z.string().optional(),
fields: z.string().optional(),
Expand Down
3 changes: 3 additions & 0 deletions tests/commands-and-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,9 @@ describe('run + commands', () => {
await expect(run(['node', 'ghst', 'member', 'list', '--status', 'paid'])).resolves.toBe(
ExitCode.SUCCESS,
);
await expect(run(['node', 'ghst', 'member', 'list', '--status', 'gift'])).resolves.toBe(
ExitCode.SUCCESS,
);
await expect(run(['node', 'ghst', 'member', 'get', fixtureIds.memberId])).resolves.toBe(
ExitCode.SUCCESS,
);
Expand Down
25 changes: 25 additions & 0 deletions tests/lib-stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,31 @@ describe('stats library', () => {
]);
});

test('includes gift members in the total_members fallback when the row carries a gift bucket', async () => {
installGhostFixtureFetchMock({
onRequest: ({ pathname, method }) => {
if (pathname.endsWith('/ghost/api/admin/stats/member_count/') && method === 'GET') {
return new Response(
JSON.stringify({
stats: [{ date: '2026-02-06', free: 100, paid: 5, comped: 2, gift: 3 }],
meta: { totals: { free: 100, paid: 5, comped: 2, gift: 3 } },
}),
{
status: 200,
headers: { 'content-type': 'application/json' },
},
);
}

return undefined;
},
});

const payload = await getStatsGrowth({}, { from: '2026-02-06', to: '2026-02-06' });

expect(payload.members[0]?.total_members).toBe(110);
});

test('clips growth histories client-side to the selected range', async () => {
installGhostFixtureFetchMock();

Expand Down
8 changes: 8 additions & 0 deletions tests/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MemberBulkInputSchema,
MemberCreateInputSchema,
MemberGetInputSchema,
MemberListInputSchema,
MemberUpdateInputSchema,
} from '../src/schemas/member.js';
import {
Expand Down Expand Up @@ -222,6 +223,13 @@ describe('member schemas', () => {
expectInvalid(MemberUpdateInputSchema, { id: 'member-1' }, 'Provide at least one update field');
});

test('accepts gift alongside the existing member statuses on list input', () => {
for (const status of ['free', 'paid', 'comped', 'gift'] as const) {
expectValid<{ status?: string }>(MemberListInputSchema, { status });
}
expectInvalid(MemberListInputSchema, { status: 'unknown' });
});

test('enforce member selectors and bulk destructive safeguards', () => {
expectValid<{ email?: string }>(MemberGetInputSchema, { email: 'x@example.com' });
expectValid<{ update?: boolean; labels?: string }>(MemberBulkInputSchema, {
Expand Down