feat(api): publish feature contracts and migrate SDK and MCP

This commit is contained in:
Mike Cao committed 2026-09-09 19:23:21 -07:00
1 parent 007919b173
commit 7c4406bad0
24 files changed
+6071 -74

No files matched your search

+21
View File
@@ -80,6 +80,27 @@ describe('UmamiClient', () => {
expect(JSON.parse(calls[0].body as string)).toMatchObject({ websiteId: 'w1', type: 'funnel' });
});
test('sends structured funnel criteria through the GET stats API', async () => {
const { client, calls } = createClient([]);
const steps = [
{ type: 'path', value: '/a?x=1&y=日本語' },
{ type: 'event', value: 'signup' },
];
await client.getWebsiteFunnelStats({
websiteId: 'w1',
startAt: 1,
endAt: 2,
window: 60,
steps: JSON.stringify(steps),
browser1: 'eq.Chrome',
});
expect(calls[0].method).toBe('GET');
expect(calls[0].body).toBeUndefined();
expect(calls[0].url.pathname).toBe('/api/websites/w1/funnels/stats');
expect(JSON.parse(calls[0].url.searchParams.get('steps')!)).toEqual(steps);
expect(calls[0].url.searchParams.get('browser1')).toBe('eq.Chrome');
});
test('uses the Cloud base URL and API key header by default', async () => {
const calls: Captured[] = [];
const client = new UmamiClient({
@@ -162,6 +162,22 @@ export const operations = {
queryParams: [],
hasBody: true,
},
createWebsiteFunnel: {
operationId: 'createWebsiteFunnel',
method: 'post',
path: '/api/websites/{websiteId}/funnels',
pathParams: ['websiteId'],
queryParams: [],
hasBody: true,
},
createWebsiteGoal: {
operationId: 'createWebsiteGoal',
method: 'post',
path: '/api/websites/{websiteId}/goals',
pathParams: ['websiteId'],
queryParams: [],
hasBody: true,
},
createWebsiteSegment: {
operationId: 'createWebsiteSegment',
method: 'post',
@@ -266,6 +282,22 @@ export const operations = {
queryParams: [],
hasBody: false,
},
deleteWebsiteFunnel: {
operationId: 'deleteWebsiteFunnel',
method: 'delete',
path: '/api/websites/{websiteId}/funnels/{funnelId}',
pathParams: ['websiteId', 'funnelId'],
queryParams: [],
hasBody: false,
},
deleteWebsiteGoal: {
operationId: 'deleteWebsiteGoal',
method: 'delete',
path: '/api/websites/{websiteId}/goals/{goalId}',
pathParams: ['websiteId', 'goalId'],
queryParams: [],
hasBody: false,
},
deleteWebsiteSegment: {
operationId: 'deleteWebsiteSegment',
method: 'delete',
@@ -1549,6 +1581,87 @@ export const operations = {
queryParams: ['startAt', 'endAt', 'search', 'page', 'pageSize', 'maxResults'],
hasBody: false,
},
getWebsiteAttribution: {
operationId: 'getWebsiteAttribution',
method: 'get',
path: '/api/websites/{websiteId}/attribution',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'model',
'type',
'step',
'currency',
],
hasBody: false,
},
getWebsiteBreakdown: {
operationId: 'getWebsiteBreakdown',
method: 'get',
path: '/api/websites/{websiteId}/breakdown',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'fields',
],
hasBody: false,
},
getWebsiteDateRange: {
operationId: 'getWebsiteDateRange',
method: 'get',
@@ -1727,6 +1840,199 @@ export const operations = {
],
hasBody: false,
},
getWebsiteFunnel: {
operationId: 'getWebsiteFunnel',
method: 'get',
path: '/api/websites/{websiteId}/funnels/{funnelId}',
pathParams: ['websiteId', 'funnelId'],
queryParams: [],
hasBody: false,
},
getWebsiteFunnels: {
operationId: 'getWebsiteFunnels',
method: 'get',
path: '/api/websites/{websiteId}/funnels',
pathParams: ['websiteId'],
queryParams: ['page', 'pageSize', 'maxResults', 'search'],
hasBody: false,
},
getWebsiteFunnelStats: {
operationId: 'getWebsiteFunnelStats',
method: 'get',
path: '/api/websites/{websiteId}/funnels/stats',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'window',
'steps',
],
hasBody: false,
},
getWebsiteGoal: {
operationId: 'getWebsiteGoal',
method: 'get',
path: '/api/websites/{websiteId}/goals/{goalId}',
pathParams: ['websiteId', 'goalId'],
queryParams: [],
hasBody: false,
},
getWebsiteGoals: {
operationId: 'getWebsiteGoals',
method: 'get',
path: '/api/websites/{websiteId}/goals',
pathParams: ['websiteId'],
queryParams: ['page', 'pageSize', 'maxResults', 'search'],
hasBody: false,
},
getWebsiteGoalStats: {
operationId: 'getWebsiteGoalStats',
method: 'get',
path: '/api/websites/{websiteId}/goals/stats',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'type',
'value',
],
hasBody: false,
},
getWebsiteHeatmaps: {
operationId: 'getWebsiteHeatmaps',
method: 'get',
path: '/api/websites/{websiteId}/heatmaps',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'urlPath',
'mode',
],
hasBody: false,
},
getWebsiteJourneys: {
operationId: 'getWebsiteJourneys',
method: 'get',
path: '/api/websites/{websiteId}/journeys',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'steps',
'startStep',
'endStep',
],
hasBody: false,
},
getWebsiteMetrics: {
operationId: 'getWebsiteMetrics',
method: 'get',
@@ -1813,6 +2119,124 @@ export const operations = {
],
hasBody: false,
},
getWebsitePerformanceChart: {
operationId: 'getWebsitePerformanceChart',
method: 'get',
path: '/api/websites/{websiteId}/performance/chart',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'metric',
],
hasBody: false,
},
getWebsitePerformanceMetrics: {
operationId: 'getWebsitePerformanceMetrics',
method: 'get',
path: '/api/websites/{websiteId}/performance/metrics',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'metric',
'type',
'limit',
],
hasBody: false,
},
getWebsitePerformanceStats: {
operationId: 'getWebsitePerformanceStats',
method: 'get',
path: '/api/websites/{websiteId}/performance/stats',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
],
hasBody: false,
},
getWebsiteRecorderConfig: {
operationId: 'getWebsiteRecorderConfig',
method: 'get',
@@ -1891,6 +2315,44 @@ export const operations = {
queryParams: ['type', 'page', 'pageSize', 'maxResults'],
hasBody: false,
},
getWebsiteRetention: {
operationId: 'getWebsiteRetention',
method: 'get',
path: '/api/websites/{websiteId}/retention',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
],
hasBody: false,
},
getWebsiteRevenueChart: {
operationId: 'getWebsiteRevenueChart',
method: 'get',
@@ -2064,6 +2526,82 @@ export const operations = {
],
hasBody: false,
},
getWebsiteSavedFunnelStats: {
operationId: 'getWebsiteSavedFunnelStats',
method: 'get',
path: '/api/websites/{websiteId}/funnels/{funnelId}/stats',
pathParams: ['websiteId', 'funnelId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
],
hasBody: false,
},
getWebsiteSavedGoalStats: {
operationId: 'getWebsiteSavedGoalStats',
method: 'get',
path: '/api/websites/{websiteId}/goals/{goalId}/stats',
pathParams: ['websiteId', 'goalId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
],
hasBody: false,
},
getWebsiteSavedReplays: {
operationId: 'getWebsiteSavedReplays',
method: 'get',
@@ -2336,6 +2874,45 @@ export const operations = {
],
hasBody: false,
},
getWebsiteUtmMetrics: {
operationId: 'getWebsiteUtmMetrics',
method: 'get',
path: '/api/websites/{websiteId}/utm/metrics',
pathParams: ['websiteId'],
queryParams: [
'path',
'referrer',
'title',
'query',
'os',
'browser',
'device',
'country',
'region',
'city',
'tag',
'hostname',
'distinctId',
'language',
'event',
'utmSource',
'utmMedium',
'utmCampaign',
'utmContent',
'utmTerm',
'segment',
'cohort',
'eventType',
'excludeBounce',
'match',
'startAt',
'endAt',
'timezone',
'unit',
'type',
],
hasBody: false,
},
getWebsiteValues: {
operationId: 'getWebsiteValues',
method: 'get',
@@ -2618,6 +3195,22 @@ export const operations = {
queryParams: [],
hasBody: true,
},
updateWebsiteFunnel: {
operationId: 'updateWebsiteFunnel',
method: 'post',
path: '/api/websites/{websiteId}/funnels/{funnelId}',
pathParams: ['websiteId', 'funnelId'],
queryParams: [],
hasBody: true,
},
updateWebsiteGoal: {
operationId: 'updateWebsiteGoal',
method: 'post',
path: '/api/websites/{websiteId}/goals/{goalId}',
pathParams: ['websiteId', 'goalId'],
queryParams: [],
hasBody: true,
},
updateWebsiteSegment: {
operationId: 'updateWebsiteSegment',
method: 'post',
@@ -2900,6 +3493,28 @@ export abstract class GeneratedUmamiClient {
return this.execute('createWebsiteAnnotation', input, options);
}
/**
* Create website funnel
* `POST /api/websites/{websiteId}/funnels`
*/
createWebsiteFunnel(
input: OperationInput<'createWebsiteFunnel'>,
options?: RequestOptions,
): Promise<OperationOutput<'createWebsiteFunnel'>> {
return this.execute('createWebsiteFunnel', input, options);
}
/**
* Create website goal
* `POST /api/websites/{websiteId}/goals`
*/
createWebsiteGoal(
input: OperationInput<'createWebsiteGoal'>,
options?: RequestOptions,
): Promise<OperationOutput<'createWebsiteGoal'>> {
return this.execute('createWebsiteGoal', input, options);
}
/**
* Create a website segment or cohort
* Saves a named segment or cohort with its type and filter parameters for the website.
@@ -3056,6 +3671,28 @@ export abstract class GeneratedUmamiClient {
return this.execute('deleteWebsiteAnnotation', input, options);
}
/**
* Delete website funnel
* `DELETE /api/websites/{websiteId}/funnels/{funnelId}`
*/
deleteWebsiteFunnel(
input: OperationInput<'deleteWebsiteFunnel'>,
options?: RequestOptions,
): Promise<OperationOutput<'deleteWebsiteFunnel'>> {
return this.execute('deleteWebsiteFunnel', input, options);
}
/**
* Delete website goal
* `DELETE /api/websites/{websiteId}/goals/{goalId}`
*/
deleteWebsiteGoal(
input: OperationInput<'deleteWebsiteGoal'>,
options?: RequestOptions,
): Promise<OperationOutput<'deleteWebsiteGoal'>> {
return this.execute('deleteWebsiteGoal', input, options);
}
/**
* Delete a website segment or cohort
* Deletes the specified saved segment or cohort from the website.
@@ -3812,6 +4449,28 @@ export abstract class GeneratedUmamiClient {
return this.execute('getWebsiteAnnotations', input, options);
}
/**
* Get website attribution
* `GET /api/websites/{websiteId}/attribution`
*/
getWebsiteAttribution(
input: OperationInput<'getWebsiteAttribution'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteAttribution'>> {
return this.execute('getWebsiteAttribution', input, options);
}
/**
* Get website breakdown
* `GET /api/websites/{websiteId}/breakdown`
*/
getWebsiteBreakdown(
input: OperationInput<'getWebsiteBreakdown'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteBreakdown'>> {
return this.execute('getWebsiteBreakdown', input, options);
}
/**
* Get the website's available date range
* Returns the earliest and latest recorded event dates for the website.
@@ -3872,6 +4531,94 @@ export abstract class GeneratedUmamiClient {
return this.execute('getWebsiteExpandedMetrics', input, options);
}
/**
* Get website funnel
* `GET /api/websites/{websiteId}/funnels/{funnelId}`
*/
getWebsiteFunnel(
input: OperationInput<'getWebsiteFunnel'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteFunnel'>> {
return this.execute('getWebsiteFunnel', input, options);
}
/**
* Get website funnels
* `GET /api/websites/{websiteId}/funnels`
*/
getWebsiteFunnels(
input: OperationInput<'getWebsiteFunnels'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteFunnels'>> {
return this.execute('getWebsiteFunnels', input, options);
}
/**
* Get website funnel stats
* `GET /api/websites/{websiteId}/funnels/stats`
*/
getWebsiteFunnelStats(
input: OperationInput<'getWebsiteFunnelStats'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteFunnelStats'>> {
return this.execute('getWebsiteFunnelStats', input, options);
}
/**
* Get website goal
* `GET /api/websites/{websiteId}/goals/{goalId}`
*/
getWebsiteGoal(
input: OperationInput<'getWebsiteGoal'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteGoal'>> {
return this.execute('getWebsiteGoal', input, options);
}
/**
* Get website goals
* `GET /api/websites/{websiteId}/goals`
*/
getWebsiteGoals(
input: OperationInput<'getWebsiteGoals'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteGoals'>> {
return this.execute('getWebsiteGoals', input, options);
}
/**
* Get website goal stats
* `GET /api/websites/{websiteId}/goals/stats`
*/
getWebsiteGoalStats(
input: OperationInput<'getWebsiteGoalStats'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteGoalStats'>> {
return this.execute('getWebsiteGoalStats', input, options);
}
/**
* Get website heatmaps
* `GET /api/websites/{websiteId}/heatmaps`
*/
getWebsiteHeatmaps(
input: OperationInput<'getWebsiteHeatmaps'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteHeatmaps'>> {
return this.execute('getWebsiteHeatmaps', input, options);
}
/**
* Get website journeys
* `GET /api/websites/{websiteId}/journeys`
*/
getWebsiteJourneys(
input: OperationInput<'getWebsiteJourneys'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteJourneys'>> {
return this.execute('getWebsiteJourneys', input, options);
}
/**
* Get ranked website metrics
* Returns the most frequent values for a dimension such as pages, referrers, countries, browsers, campaigns, or events. Counts pageviews or events for activity dimensions and unique visitors for visitor dimensions.
@@ -3896,6 +4643,39 @@ export abstract class GeneratedUmamiClient {
return this.execute('getWebsitePageviews', input, options);
}
/**
* Get website performance chart
* `GET /api/websites/{websiteId}/performance/chart`
*/
getWebsitePerformanceChart(
input: OperationInput<'getWebsitePerformanceChart'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsitePerformanceChart'>> {
return this.execute('getWebsitePerformanceChart', input, options);
}
/**
* Get website performance metrics
* `GET /api/websites/{websiteId}/performance/metrics`
*/
getWebsitePerformanceMetrics(
input: OperationInput<'getWebsitePerformanceMetrics'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsitePerformanceMetrics'>> {
return this.execute('getWebsitePerformanceMetrics', input, options);
}
/**
* Get website performance stats
* `GET /api/websites/{websiteId}/performance/stats`
*/
getWebsitePerformanceStats(
input: OperationInput<'getWebsitePerformanceStats'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsitePerformanceStats'>> {
return this.execute('getWebsitePerformanceStats', input, options);
}
/**
* Get website recording settings
* Returns public replay and heatmap settings, including sampling, masking, and duration limits. Returns disabled status when recording is unavailable.
@@ -3956,6 +4736,17 @@ export abstract class GeneratedUmamiClient {
return this.execute('getWebsiteReports', input, options);
}
/**
* Get website retention
* `GET /api/websites/{websiteId}/retention`
*/
getWebsiteRetention(
input: OperationInput<'getWebsiteRetention'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteRetention'>> {
return this.execute('getWebsiteRetention', input, options);
}
/**
* Get website revenue over time
* Returns revenue chart data for the selected currency, date range, and website filters.
@@ -4004,6 +4795,28 @@ export abstract class GeneratedUmamiClient {
return this.execute('getWebsiteRevenueStats', input, options);
}
/**
* Get website saved funnel stats
* `GET /api/websites/{websiteId}/funnels/{funnelId}/stats`
*/
getWebsiteSavedFunnelStats(
input: OperationInput<'getWebsiteSavedFunnelStats'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteSavedFunnelStats'>> {
return this.execute('getWebsiteSavedFunnelStats', input, options);
}
/**
* Get website saved goal stats
* `GET /api/websites/{websiteId}/goals/{goalId}/stats`
*/
getWebsiteSavedGoalStats(
input: OperationInput<'getWebsiteSavedGoalStats'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteSavedGoalStats'>> {
return this.execute('getWebsiteSavedGoalStats', input, options);
}
/**
* List saved session replays
* Returns a paginated, searchable list of replays saved for the website.
@@ -4160,6 +4973,17 @@ export abstract class GeneratedUmamiClient {
return this.execute('getWebsiteStats', input, options);
}
/**
* Get website utm metrics
* `GET /api/websites/{websiteId}/utm/metrics`
*/
getWebsiteUtmMetrics(
input: OperationInput<'getWebsiteUtmMetrics'>,
options?: RequestOptions,
): Promise<OperationOutput<'getWebsiteUtmMetrics'>> {
return this.execute('getWebsiteUtmMetrics', input, options);
}
/**
* List website filter values
* Returns available values for a website filter, including saved segments or cohorts when requested, to populate filter choices.
@@ -4550,6 +5374,28 @@ export abstract class GeneratedUmamiClient {
return this.execute('updateWebsiteAnnotation', input, options);
}
/**
* Update website funnel
* `POST /api/websites/{websiteId}/funnels/{funnelId}`
*/
updateWebsiteFunnel(
input: OperationInput<'updateWebsiteFunnel'>,
options?: RequestOptions,
): Promise<OperationOutput<'updateWebsiteFunnel'>> {
return this.execute('updateWebsiteFunnel', input, options);
}
/**
* Update website goal
* `POST /api/websites/{websiteId}/goals/{goalId}`
*/
updateWebsiteGoal(
input: OperationInput<'updateWebsiteGoal'>,
options?: RequestOptions,
): Promise<OperationOutput<'updateWebsiteGoal'>> {
return this.execute('updateWebsiteGoal', input, options);
}
/**
* Update a website segment or cohort
* Updates a saved segment or cohort's type, name, and filter parameters.
File diff suppressed because it is too large. Load diff
+57 -6
View File
@@ -159,7 +159,7 @@ describe('createUmamiMcpServer', () => {
return { body: [{ dataKey: 'plan', stringValue: 'pro' }] };
}
if (path === '/api/reports/funnel') {
if (path === `/api/websites/${WEBSITE_ID}/funnels/stats`) {
return {
body: [
{
@@ -184,6 +184,25 @@ describe('createUmamiMcpServer', () => {
};
}
if (path === `/api/websites/${WEBSITE_ID}/revenue/stats`) {
return {
body: {
sum: 100,
count: 2,
average: 50,
unique_count: 2,
arpu: 50,
comparison: { sum: 80 },
},
};
}
if (path === `/api/websites/${WEBSITE_ID}/revenue/chart`) {
return { body: { chart: [{ t: '2024-01-01', sum: 100 }] } };
}
if (path === `/api/websites/${WEBSITE_ID}/revenue/metrics`) {
return { body: [{ name: url.searchParams.get('type'), value: 100 }] };
}
if (path.startsWith('/api/websites/')) {
return {
status: 401,
@@ -379,7 +398,7 @@ describe('createUmamiMcpServer', () => {
});
});
test('run_funnel posts a typed report body', async () => {
test('run_funnel sends structured criteria with GET', async () => {
const result = await harness.client.callTool({
name: 'run_funnel',
arguments: {
@@ -401,11 +420,43 @@ describe('createUmamiMcpServer', () => {
],
});
const body = JSON.parse(harness.calls[0].init?.body as string);
const { url, init } = harness.calls[0];
expect(init?.method).toBe('GET');
expect(init?.body).toBeUndefined();
expect(url.pathname).toBe(`/api/websites/${WEBSITE_ID}/funnels/stats`);
expect(JSON.parse(url.searchParams.get('steps')!)).toHaveLength(2);
expect(url.searchParams.get('window')).toBe('60');
expect(Number(url.searchParams.get('startAt'))).toBeGreaterThan(0);
});
expect(body).toMatchObject({ websiteId: WEBSITE_ID, type: 'funnel' });
expect(body.parameters.steps).toHaveLength(2);
expect(body.parameters.window).toBe(60);
test('get_revenue composes feature APIs without changing its tool output', async () => {
const result = await harness.client.callTool({
name: 'get_revenue',
arguments: {
websiteId: WEBSITE_ID,
startAt: '2024-01-01',
endAt: '2024-01-31',
currency: 'eur',
filters: { browser: 'Chrome' },
},
});
expect(result.isError).toBeFalsy();
expect(result.structuredContent).toMatchObject({
currency: 'EUR',
total: { sum: 100, comparison: { sum: 80 } },
chart: [{ sum: 100 }],
byCountry: [{ name: 'country', value: 100 }],
byRegion: [{ name: 'region' }],
byReferrer: [{ name: 'referrer' }],
byChannel: [{ name: 'channel' }],
});
expect(harness.calls).toHaveLength(6);
for (const { url, init } of harness.calls) {
expect(init?.method).toBe('GET');
expect(url.pathname).toContain(`/websites/${WEBSITE_ID}/revenue/`);
expect(url.searchParams.get('currency')).toBe('EUR');
expect(url.searchParams.get('startAt')).toBe(String(Date.parse('2024-01-01')));
}
});
test('maps unauthorized website access to a helpful error', async () => {
+38 -48
View File
@@ -1,17 +1,10 @@
import { z } from 'zod';
import { dateRangeInput, parseDateRange, timeUnit, timezone, toReportDates } from '../lib/dates';
import { dateRangeInput, parseDateRange, timeUnit, timezone } from '../lib/dates';
import { filtersSchema, toFilterParams } from '../lib/filters';
import { defineTool } from '../lib/tool';
const websiteId = z.string().uuid().describe('Website ID from list_websites.');
function reportFilters(
range: { startAt: number; endAt: number },
filters?: z.infer<typeof filtersSchema>,
) {
return { startAt: range.startAt, endAt: range.endAt, ...toFilterParams(filters) };
}
function isoRange(range: { startAt: number; endAt: number }) {
return {
startAt: new Date(range.startAt).toISOString(),
@@ -57,15 +50,12 @@ export const runFunnel = defineTool({
}),
async handler(input, { client }) {
const range = parseDateRange(input);
const result = await client.runFunnelReport({
const result = await client.getWebsiteFunnelStats({
websiteId: input.websiteId,
type: 'funnel',
filters: reportFilters(range, input.filters),
parameters: {
...toReportDates(range),
window: input.windowMinutes ?? 60,
steps: input.steps,
},
...range,
...toFilterParams(input.filters),
window: input.windowMinutes ?? 60,
steps: JSON.stringify(input.steps),
});
return {
@@ -112,16 +102,13 @@ export const runJourney = defineTool({
}),
async handler(input, { client }) {
const range = parseDateRange(input);
const result = await client.runJourneyReport({
const result = await client.getWebsiteJourneys({
websiteId: input.websiteId,
type: 'journey',
filters: reportFilters(range, input.filters),
parameters: {
...toReportDates(range),
steps: input.steps ?? 3,
startStep: input.startStep,
endStep: input.endStep,
},
...range,
...toFilterParams(input.filters),
steps: input.steps ?? 3,
startStep: input.startStep,
endStep: input.endStep,
});
return {
@@ -153,11 +140,11 @@ export const runRetention = defineTool({
}),
async handler(input, { client }) {
const range = parseDateRange(input);
const result = await client.runRetentionReport({
const result = await client.getWebsiteRetention({
websiteId: input.websiteId,
type: 'retention',
filters: reportFilters(range, input.filters),
parameters: { ...toReportDates(range), timezone: input.timezone },
...range,
...toFilterParams(input.filters),
timezone: input.timezone,
});
return {
@@ -209,16 +196,13 @@ export const runAttribution = defineTool({
}),
async handler(input, { client }) {
const range = parseDateRange(input);
const result = (await client.runAttributionReport({
const result = (await client.getWebsiteAttribution({
websiteId: input.websiteId,
type: 'attribution',
filters: reportFilters(range, input.filters),
parameters: {
...toReportDates(range),
model: input.model ?? 'last-click',
type: input.conversionType,
step: input.conversion,
},
...range,
...toFilterParams(input.filters),
model: input.model ?? 'last-click',
type: input.conversionType,
step: input.conversion,
})) as Record<string, unknown>;
const list = (value: unknown) =>
@@ -262,17 +246,23 @@ export const getRevenue = defineTool({
}),
async handler(input, { client }) {
const range = parseDateRange(input);
const result = (await client.runRevenueReport({
const params = {
websiteId: input.websiteId,
type: 'revenue',
filters: reportFilters(range, input.filters),
parameters: {
...toReportDates(range),
currency: (input.currency ?? 'USD').toUpperCase(),
unit: input.unit,
timezone: input.timezone,
},
})) as Record<string, unknown>;
...range,
...toFilterParams(input.filters),
currency: (input.currency ?? 'USD').toUpperCase(),
unit: input.unit,
timezone: input.timezone,
};
const [total, chart, country, region, referrer, channel] = await Promise.all([
client.getWebsiteRevenueStats(params),
client.getWebsiteRevenueChart(params),
client.getWebsiteRevenueMetrics({ ...params, type: 'country' }),
client.getWebsiteRevenueMetrics({ ...params, type: 'region' }),
client.getWebsiteRevenueMetrics({ ...params, type: 'referrer' }),
client.getWebsiteRevenueMetrics({ ...params, type: 'channel' }),
]);
const result = { total, chart: chart.chart, country, region, referrer, channel };
return {
websiteId: input.websiteId,
@@ -0,0 +1,166 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { attributionQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/attribution',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteAttribution',
summary: 'Get website attribution',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: attributionQuerySchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
referrer: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
paidAds: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
utm_source: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
utm_medium: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
utm_campaign: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
utm_content: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
utm_term: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
value: {
type: 'number',
},
},
required: ['name', 'value'],
},
},
total: {
type: 'object',
properties: {
pageviews: {
type: 'number',
},
visitors: {
type: 'number',
},
visits: {
type: 'number',
},
},
required: ['pageviews', 'visitors', 'visits'],
},
},
required: [
'referrer',
'paidAds',
'utm_source',
'utm_medium',
'utm_campaign',
'utm_content',
'utm_term',
'total',
],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,65 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { breakdownQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/breakdown',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteBreakdown',
summary: 'Get website breakdown',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: breakdownQuerySchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
views: {
type: 'number',
},
visitors: {
type: 'number',
},
visits: {
type: 'number',
},
bounces: {
type: 'number',
},
totaltime: {
type: 'number',
},
},
required: ['views', 'visitors', 'visits', 'bounces', 'totaltime'],
additionalProperties: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
],
},
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,101 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import {
badRequestResponse,
unauthorizedResponse,
notFoundResponse,
jsonResponse,
okSchema,
} from '@/openapi/schemas';
import { funnelDefinitionSchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/funnels/{funnelId}',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteFunnel',
summary: 'Get website funnel',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }) },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
ok: {
const: true,
},
},
required: ['ok'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
defineOperation({
method: 'post',
path: '/api/websites/{websiteId}/funnels/{funnelId}',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'updateWebsiteFunnel',
summary: 'Update website funnel',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }) },
requestBody: {
required: true,
content: { 'application/json': { schema: funnelDefinitionSchema } },
},
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
ok: {
const: true,
},
},
required: ['ok'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
defineOperation({
method: 'delete',
path: '/api/websites/{websiteId}/funnels/{funnelId}',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'deleteWebsiteFunnel',
summary: 'Delete website funnel',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }) },
responses: {
'200': jsonResponse(okSchema, 'Deleted successfully.'),
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,90 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { savedStatsQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/funnels/{funnelId}/stats',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteSavedFunnelStats',
summary: 'Get website saved funnel stats',
tags: ['Websites'],
requestParams: {
path: z.object({ websiteId: z.uuid(), funnelId: z.uuid() }),
query: savedStatsQuerySchema,
},
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
visitors: {
type: 'number',
},
previous: {
type: 'number',
},
dropped: {
type: 'number',
},
dropoff: {
type: 'number',
},
remaining: {
type: 'number',
},
type: {
type: 'string',
},
value: {
type: 'string',
},
filters: {
type: 'array',
items: {
type: 'object',
properties: {
property: {
type: 'string',
},
operator: {
type: 'string',
},
value: {
type: 'string',
},
},
required: ['property', 'operator', 'value'],
},
},
},
required: [
'visitors',
'previous',
'dropped',
'dropoff',
'remaining',
'type',
'value',
],
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,216 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { definitionListSchema, funnelDefinitionSchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/funnels',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteFunnels',
summary: 'Get website funnels',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: definitionListSchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
data: {
type: 'array',
items: {
allOf: [
{
type: 'object',
properties: {
id: {
type: 'string',
},
userId: {
type: 'string',
},
createdAt: {
type: 'string',
format: 'date-time',
},
updatedAt: {
type: 'string',
format: 'date-time',
},
name: {
type: 'string',
},
type: {
type: 'string',
},
description: {
type: 'string',
},
parameters: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
{
const: false,
},
{
const: true,
},
{
type: 'object',
properties: {},
additionalProperties: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
{
const: false,
},
{
const: true,
},
{},
{
type: 'object',
properties: {
length: {
type: 'number',
},
},
required: ['length'],
},
],
},
},
{
type: 'object',
properties: {
length: {
type: 'number',
},
},
required: ['length'],
},
],
},
websiteId: {
type: 'string',
},
},
required: [
'id',
'userId',
'createdAt',
'updatedAt',
'name',
'type',
'description',
'parameters',
'websiteId',
],
},
{
type: 'object',
properties: {
website: {
type: 'object',
properties: {
domain: {
type: 'string',
},
userId: {
type: 'string',
},
},
required: ['domain', 'userId'],
},
},
},
],
},
},
count: {
type: 'number',
},
page: {
type: 'number',
},
pageSize: {
type: 'number',
},
orderBy: {
type: 'string',
},
sortDescending: {
type: 'boolean',
},
search: {
type: 'string',
},
isCapped: {
type: 'boolean',
},
},
required: ['data', 'count', 'page', 'pageSize'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
defineOperation({
method: 'post',
path: '/api/websites/{websiteId}/funnels',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'createWebsiteFunnel',
summary: 'Create website funnel',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }) },
requestBody: {
required: true,
content: { 'application/json': { schema: funnelDefinitionSchema } },
},
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
ok: {
const: true,
},
},
required: ['ok'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,87 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { funnelQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/funnels/stats',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteFunnelStats',
summary: 'Get website funnel stats',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: funnelQuerySchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
visitors: {
type: 'number',
},
previous: {
type: 'number',
},
dropped: {
type: 'number',
},
dropoff: {
type: 'number',
},
remaining: {
type: 'number',
},
type: {
type: 'string',
},
value: {
type: 'string',
},
filters: {
type: 'array',
items: {
type: 'object',
properties: {
property: {
type: 'string',
},
operator: {
type: 'string',
},
value: {
type: 'string',
},
},
required: ['property', 'operator', 'value'],
},
},
},
required: [
'visitors',
'previous',
'dropped',
'dropoff',
'remaining',
'type',
'value',
],
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,101 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import {
badRequestResponse,
unauthorizedResponse,
notFoundResponse,
jsonResponse,
okSchema,
} from '@/openapi/schemas';
import { goalDefinitionSchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/goals/{goalId}',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteGoal',
summary: 'Get website goal',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }) },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
ok: {
const: true,
},
},
required: ['ok'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
defineOperation({
method: 'post',
path: '/api/websites/{websiteId}/goals/{goalId}',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'updateWebsiteGoal',
summary: 'Update website goal',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }) },
requestBody: {
required: true,
content: { 'application/json': { schema: goalDefinitionSchema } },
},
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
ok: {
const: true,
},
},
required: ['ok'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
defineOperation({
method: 'delete',
path: '/api/websites/{websiteId}/goals/{goalId}',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'deleteWebsiteGoal',
summary: 'Delete website goal',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }) },
responses: {
'200': jsonResponse(okSchema, 'Deleted successfully.'),
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,46 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { savedStatsQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/goals/{goalId}/stats',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteSavedGoalStats',
summary: 'Get website saved goal stats',
tags: ['Websites'],
requestParams: {
path: z.object({ websiteId: z.uuid(), goalId: z.uuid() }),
query: savedStatsQuerySchema,
},
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
num: {
type: 'number',
},
total: {
type: 'number',
},
},
required: ['num', 'total'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,216 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { definitionListSchema, goalDefinitionSchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/goals',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteGoals',
summary: 'Get website goals',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: definitionListSchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
data: {
type: 'array',
items: {
allOf: [
{
type: 'object',
properties: {
id: {
type: 'string',
},
userId: {
type: 'string',
},
createdAt: {
type: 'string',
format: 'date-time',
},
updatedAt: {
type: 'string',
format: 'date-time',
},
name: {
type: 'string',
},
type: {
type: 'string',
},
description: {
type: 'string',
},
parameters: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
{
const: false,
},
{
const: true,
},
{
type: 'object',
properties: {},
additionalProperties: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
{
const: false,
},
{
const: true,
},
{},
{
type: 'object',
properties: {
length: {
type: 'number',
},
},
required: ['length'],
},
],
},
},
{
type: 'object',
properties: {
length: {
type: 'number',
},
},
required: ['length'],
},
],
},
websiteId: {
type: 'string',
},
},
required: [
'id',
'userId',
'createdAt',
'updatedAt',
'name',
'type',
'description',
'parameters',
'websiteId',
],
},
{
type: 'object',
properties: {
website: {
type: 'object',
properties: {
domain: {
type: 'string',
},
userId: {
type: 'string',
},
},
required: ['domain', 'userId'],
},
},
},
],
},
},
count: {
type: 'number',
},
page: {
type: 'number',
},
pageSize: {
type: 'number',
},
orderBy: {
type: 'string',
},
sortDescending: {
type: 'boolean',
},
search: {
type: 'string',
},
isCapped: {
type: 'boolean',
},
},
required: ['data', 'count', 'page', 'pageSize'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
defineOperation({
method: 'post',
path: '/api/websites/{websiteId}/goals',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'createWebsiteGoal',
summary: 'Create website goal',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }) },
requestBody: {
required: true,
content: { 'application/json': { schema: goalDefinitionSchema } },
},
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
ok: {
const: true,
},
},
required: ['ok'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,43 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { goalQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/goals/stats',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteGoalStats',
summary: 'Get website goal stats',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: goalQuerySchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
num: {
type: 'number',
},
total: {
type: 'number',
},
},
required: ['num', 'total'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,200 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { heatmapQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/heatmaps',
audience: 'public',
auth: 'bearer',
operation: {
operationId: 'getWebsiteHeatmaps',
summary: 'Get website heatmaps',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: heatmapQuerySchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
mode: {
anyOf: [
{
const: 'click',
},
{
const: 'scroll',
},
],
},
pages: {
type: 'array',
items: {
type: 'object',
properties: {
urlPath: {
type: 'string',
},
count: {
type: 'number',
},
sessions: {
type: 'number',
},
},
required: ['urlPath', 'count', 'sessions'],
},
},
points: {
type: 'array',
items: {
type: 'object',
properties: {
x: {
type: 'number',
},
y: {
type: 'number',
},
pageX: {
type: 'number',
},
pageY: {
type: 'number',
},
pageW: {
type: 'number',
},
pageH: {
type: 'number',
},
viewportW: {
type: 'number',
},
viewportH: {
type: 'number',
},
count: {
type: 'number',
},
},
required: [
'x',
'y',
'pageX',
'pageY',
'pageW',
'pageH',
'viewportW',
'viewportH',
'count',
],
},
},
snapshot: {
type: 'object',
properties: {
kind: {
const: 'iframe',
},
id: {
type: 'string',
},
url: {
type: 'string',
},
pageW: {
type: 'number',
},
pageH: {
type: 'number',
},
viewportW: {
type: 'number',
},
viewportH: {
type: 'number',
},
},
required: ['kind', 'id', 'url', 'pageW', 'pageH', 'viewportW', 'viewportH'],
},
scroll: {
type: 'object',
properties: {
buckets: {
type: 'array',
items: {
type: 'object',
properties: {
depth: {
type: 'number',
},
sessions: {
type: 'number',
},
pageW: {
type: 'number',
},
pageH: {
type: 'number',
},
viewportW: {
type: 'number',
},
viewportH: {
type: 'number',
},
},
required: [
'depth',
'sessions',
'pageW',
'pageH',
'viewportW',
'viewportH',
],
},
},
totalSessions: {
type: 'number',
},
pageW: {
type: 'number',
},
pageH: {
type: 'number',
},
viewportW: {
type: 'number',
},
viewportH: {
type: 'number',
},
},
required: [
'buckets',
'totalSessions',
'pageW',
'pageH',
'viewportW',
'viewportH',
],
},
},
required: ['mode', 'pages', 'points', 'snapshot', 'scroll'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,49 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { journeyQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/journeys',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteJourneys',
summary: 'Get website journeys',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: journeyQuerySchema },
responses: {
'200': {
description: 'Analytics results.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
items: {
type: 'array',
items: {
type: 'string',
},
},
count: {
type: 'number',
},
},
required: ['items', 'count'],
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,61 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { performanceChartQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/performance/chart',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsitePerformanceChart',
summary: 'Get website performance chart',
tags: ['Websites'],
requestParams: {
path: z.object({ websiteId: z.uuid() }),
query: performanceChartQuerySchema,
},
responses: {
'200': {
description: 'Analytics results.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
chart: {
type: 'array',
items: {
type: 'object',
properties: {
t: {
type: 'string',
},
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
},
required: ['t', 'p50', 'p75', 'p95'],
},
},
},
required: ['chart'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,58 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { performanceMetricsQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/performance/metrics',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsitePerformanceMetrics',
summary: 'Get website performance metrics',
tags: ['Websites'],
requestParams: {
path: z.object({ websiteId: z.uuid() }),
query: performanceMetricsQuerySchema,
},
responses: {
'200': {
description: 'Analytics results.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
count: {
type: 'number',
},
},
required: ['name', 'p50', 'p75', 'p95', 'count'],
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,118 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { performanceStatsQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/performance/stats',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsitePerformanceStats',
summary: 'Get website performance stats',
tags: ['Websites'],
requestParams: {
path: z.object({ websiteId: z.uuid() }),
query: performanceStatsQuerySchema,
},
responses: {
'200': {
description: 'Analytics results.',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
lcp: {
type: 'object',
properties: {
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
},
required: ['p50', 'p75', 'p95'],
},
inp: {
type: 'object',
properties: {
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
},
required: ['p50', 'p75', 'p95'],
},
cls: {
type: 'object',
properties: {
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
},
required: ['p50', 'p75', 'p95'],
},
fcp: {
type: 'object',
properties: {
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
},
required: ['p50', 'p75', 'p95'],
},
ttfb: {
type: 'object',
properties: {
p50: {
type: 'number',
},
p75: {
type: 'number',
},
p95: {
type: 'number',
},
},
required: ['p50', 'p75', 'p95'],
},
count: {
type: 'number',
},
},
required: ['lcp', 'inp', 'cls', 'fcp', 'ttfb', 'count'],
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,55 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { retentionQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/retention',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteRetention',
summary: 'Get website retention',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: retentionQuerySchema },
responses: {
'200': {
description: 'The operation completed successfully.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
date: {
type: 'string',
},
day: {
type: 'number',
},
visitors: {
type: 'number',
},
returnVisitors: {
type: 'number',
},
percentage: {
type: 'number',
},
},
required: ['date', 'day', 'visitors', 'returnVisitors', 'percentage'],
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -0,0 +1,46 @@
import { z } from 'zod';
import { defineOperation } from '@/openapi/operation';
import { badRequestResponse, unauthorizedResponse, notFoundResponse } from '@/openapi/schemas';
import { utmMetricsQuerySchema } from '@/lib/analytics-schema';
export const operations = [
defineOperation({
method: 'get',
path: '/api/websites/{websiteId}/utm/metrics',
audience: 'public',
auth: 'bearer-or-share',
operation: {
operationId: 'getWebsiteUtmMetrics',
summary: 'Get website utm metrics',
tags: ['Websites'],
requestParams: { path: z.object({ websiteId: z.uuid() }), query: utmMetricsQuerySchema },
responses: {
'200': {
description: 'Analytics results.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
utm: {
type: 'string',
},
views: {
type: 'number',
},
},
required: ['utm', 'views'],
},
},
},
},
},
'400': badRequestResponse,
'401': unauthorizedResponse,
'404': notFoundResponse,
},
},
}),
] as const;
@@ -13,5 +13,11 @@ export async function GET(
const { websiteId } = await params;
if (!(await canViewWebsiteSection(auth, websiteId, 'utm'))) return unauthorized();
const filters = await getQueryFilters(query, websiteId);
return json(await getUTM(websiteId, { startDate: filters.startDate, endDate: filters.endDate, column: query.type }, filters));
return json(
await getUTM(
websiteId,
{ startDate: filters.startDate, endDate: filters.endDate, column: query.type },
filters,
),
);
}
+33 -19
View File
@@ -119,36 +119,50 @@ export const MCP_DISPATCH_ROUTES: readonly DispatchRoute[] = [
load: () => import('@/app/api/websites/[websiteId]/sessions/[sessionId]/properties/route'),
},
{
method: 'POST',
path: '/api/reports/attribution',
load: () => import('@/app/api/reports/attribution/route'),
method: 'GET',
path: '/api/websites/{websiteId}/attribution',
load: () => import('@/app/api/websites/[websiteId]/attribution/route'),
},
{
method: 'POST',
path: '/api/reports/breakdown',
load: () => import('@/app/api/reports/breakdown/route'),
method: 'GET',
path: '/api/websites/{websiteId}/breakdown',
load: () => import('@/app/api/websites/[websiteId]/breakdown/route'),
},
{
method: 'POST',
path: '/api/reports/funnel',
load: () => import('@/app/api/reports/funnel/route'),
method: 'GET',
path: '/api/websites/{websiteId}/funnels/stats',
load: () => import('@/app/api/websites/[websiteId]/funnels/stats/route'),
},
{
method: 'POST',
path: '/api/reports/journey',
load: () => import('@/app/api/reports/journey/route'),
method: 'GET',
path: '/api/websites/{websiteId}/journeys',
load: () => import('@/app/api/websites/[websiteId]/journeys/route'),
},
{
method: 'POST',
path: '/api/reports/retention',
load: () => import('@/app/api/reports/retention/route'),
method: 'GET',
path: '/api/websites/{websiteId}/retention',
load: () => import('@/app/api/websites/[websiteId]/retention/route'),
},
{
method: 'POST',
path: '/api/reports/revenue',
load: () => import('@/app/api/reports/revenue/route'),
method: 'GET',
path: '/api/websites/{websiteId}/utm/metrics',
load: () => import('@/app/api/websites/[websiteId]/utm/metrics/route'),
},
{
method: 'GET',
path: '/api/websites/{websiteId}/revenue/stats',
load: () => import('@/app/api/websites/[websiteId]/revenue/stats/route'),
},
{
method: 'GET',
path: '/api/websites/{websiteId}/revenue/chart',
load: () => import('@/app/api/websites/[websiteId]/revenue/chart/route'),
},
{
method: 'GET',
path: '/api/websites/{websiteId}/revenue/metrics',
load: () => import('@/app/api/websites/[websiteId]/revenue/metrics/route'),
},
{ method: 'POST', path: '/api/reports/utm', load: () => import('@/app/api/reports/utm/route') },
];
function escapeRegExp(value: string) {