Add OAuth-protected MCP server with generated API client packages
This commit is contained in:
1 parent
26e236c95c
commit
65bf19e067
235 files changed
+33755
-3199
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { isOAuthEnabled } from '@/lib/oauth/config';
|
||||
import {
|
||||
buildAuthorizationServerMetadata,
|
||||
corsPreflight,
|
||||
metadataResponse,
|
||||
} from '@/lib/oauth/metadata';
|
||||
import { notFound } from '@/lib/response';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export function OPTIONS() {
|
||||
return corsPreflight();
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
return metadataResponse(buildAuthorizationServerMetadata(request.headers));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { isOAuthEnabled } from '@/lib/oauth/config';
|
||||
import {
|
||||
buildProtectedResourceMetadata,
|
||||
corsPreflight,
|
||||
metadataResponse,
|
||||
} from '@/lib/oauth/metadata';
|
||||
import { notFound } from '@/lib/response';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export function OPTIONS() {
|
||||
return corsPreflight();
|
||||
}
|
||||
|
||||
/** Path-scoped protected resource metadata for the MCP endpoint (RFC 9728 §3.1). */
|
||||
export async function GET(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
return metadataResponse(buildProtectedResourceMetadata(request.headers));
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { isOAuthEnabled } from '@/lib/oauth/config';
|
||||
import {
|
||||
buildProtectedResourceMetadata,
|
||||
corsPreflight,
|
||||
metadataResponse,
|
||||
} from '@/lib/oauth/metadata';
|
||||
import { notFound } from '@/lib/response';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export function OPTIONS() {
|
||||
return corsPreflight();
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
return metadataResponse(buildProtectedResourceMetadata(request.headers));
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'post2faDisable',
|
||||
operationId: 'disableTwoFactor',
|
||||
summary: 'Create or update 2fa disable',
|
||||
tags: ['Two-factor authentication'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'post2faSetupCancel',
|
||||
operationId: 'cancelTwoFactorSetup',
|
||||
summary: 'Create or update 2fa setup cancel',
|
||||
tags: ['Two-factor authentication'],
|
||||
responses: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'post2faSetupConfirm',
|
||||
operationId: 'confirmTwoFactorSetup',
|
||||
summary: 'Create or update 2fa setup confirm',
|
||||
tags: ['Two-factor authentication'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'post2faSetupInitiate',
|
||||
operationId: 'initiateTwoFactorSetup',
|
||||
summary: 'Create or update 2fa setup initiate',
|
||||
tags: ['Two-factor authentication'],
|
||||
responses: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'get2faStatus',
|
||||
operationId: 'getTwoFactorStatus',
|
||||
summary: 'Get 2fa status',
|
||||
tags: ['Two-factor authentication'],
|
||||
responses: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'post2faVerify',
|
||||
operationId: 'verifyTwoFactor',
|
||||
summary: 'Create or update 2fa verify',
|
||||
tags: ['Two-factor authentication'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postAuthLogout',
|
||||
operationId: 'logout',
|
||||
summary: 'Create or update auth logout',
|
||||
tags: ['Authentication'],
|
||||
responses: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postAuthSso',
|
||||
operationId: 'sso',
|
||||
summary: 'Create or update auth sso',
|
||||
tags: ['Authentication'],
|
||||
responses: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getAuthSubscription',
|
||||
operationId: 'getSubscription',
|
||||
summary: 'Get auth subscription',
|
||||
tags: ['Authentication'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postAuthVerify',
|
||||
operationId: 'verify',
|
||||
summary: 'Create or update auth verify',
|
||||
tags: ['Authentication'],
|
||||
responses: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'collect',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'postBatch',
|
||||
operationId: 'batch',
|
||||
summary: 'Create or update batch',
|
||||
tags: ['Collection'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postBoardsBoardIdClone',
|
||||
operationId: 'cloneBoard',
|
||||
summary: 'Create or update boards board id clone',
|
||||
tags: ['Boards'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteBoardsBoardId',
|
||||
operationId: 'deleteBoard',
|
||||
summary: 'Delete boards board id',
|
||||
tags: ['Boards'],
|
||||
parameters: [
|
||||
@@ -66,7 +66,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getBoardsBoardId',
|
||||
operationId: 'getBoard',
|
||||
summary: 'Get boards board id',
|
||||
tags: ['Boards'],
|
||||
parameters: [
|
||||
@@ -211,7 +211,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postBoardsBoardId',
|
||||
operationId: 'updateBoard',
|
||||
summary: 'Create or update boards board id',
|
||||
tags: ['Boards'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getBoardsBoardIdShares',
|
||||
operationId: 'getBoardShares',
|
||||
summary: 'Get boards board id shares',
|
||||
tags: ['Boards'],
|
||||
parameters: [
|
||||
@@ -428,7 +428,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postBoardsBoardIdShares',
|
||||
operationId: 'createBoardShare',
|
||||
summary: 'Create or update boards board id shares',
|
||||
tags: ['Boards'],
|
||||
parameters: [
|
||||
|
||||
@@ -245,7 +245,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postBoards',
|
||||
operationId: 'createBoard',
|
||||
summary: 'Create or update boards',
|
||||
tags: ['Boards'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteLinksLinkId',
|
||||
operationId: 'deleteLink',
|
||||
summary: 'Delete links link id',
|
||||
tags: ['Links'],
|
||||
parameters: [
|
||||
@@ -66,7 +66,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getLinksLinkId',
|
||||
operationId: 'getLink',
|
||||
summary: 'Get links link id',
|
||||
tags: ['Links'],
|
||||
parameters: [
|
||||
@@ -160,7 +160,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postLinksLinkId',
|
||||
operationId: 'updateLink',
|
||||
summary: 'Create or update links link id',
|
||||
tags: ['Links'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getLinksLinkIdShares',
|
||||
operationId: 'getLinkShares',
|
||||
summary: 'Get links link id shares',
|
||||
tags: ['Links'],
|
||||
parameters: [
|
||||
@@ -428,7 +428,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postLinksLinkIdShares',
|
||||
operationId: 'createLinkShare',
|
||||
summary: 'Create or update links link id shares',
|
||||
tags: ['Links'],
|
||||
parameters: [
|
||||
|
||||
@@ -194,7 +194,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postLinks',
|
||||
operationId: 'createLink',
|
||||
summary: 'Create or update links',
|
||||
tags: ['Links'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteMeApiKeysKeyId',
|
||||
operationId: 'deleteMyApiKey',
|
||||
summary: 'Delete me api keys key id',
|
||||
tags: ['Account'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'getMeApiKeys',
|
||||
operationId: 'getMyApiKeys',
|
||||
summary: 'Get me api keys',
|
||||
tags: ['Account'],
|
||||
responses: {
|
||||
@@ -90,7 +90,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postMeApiKeys',
|
||||
operationId: 'createMyApiKey',
|
||||
summary: 'Create or update me api keys',
|
||||
tags: ['Account'],
|
||||
requestBody: {
|
||||
|
||||
@@ -12,6 +12,7 @@ const operation1 = defineOperation({
|
||||
operationId: 'getMe',
|
||||
summary: 'Get me',
|
||||
tags: ['Account'],
|
||||
'x-umami-oauth-scope': 'websites:read',
|
||||
responses: {
|
||||
'200': {
|
||||
description: 'The operation completed successfully.',
|
||||
@@ -50,6 +51,40 @@ const operation1 = defineOperation({
|
||||
},
|
||||
required: ['id', 'name'],
|
||||
},
|
||||
authType: {
|
||||
anyOf: [
|
||||
{
|
||||
const: 'session',
|
||||
},
|
||||
{
|
||||
const: 'share',
|
||||
},
|
||||
{
|
||||
const: 'api-key',
|
||||
},
|
||||
{
|
||||
const: 'oauth',
|
||||
},
|
||||
],
|
||||
},
|
||||
oauth: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
clientId: {
|
||||
type: 'string',
|
||||
},
|
||||
scopes: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
tokenId: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['clientId', 'scopes'],
|
||||
},
|
||||
shareToken: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postMePassword',
|
||||
operationId: 'updateMyPassword',
|
||||
summary: 'Create or update me password',
|
||||
tags: ['Account'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'getMeTeams',
|
||||
operationId: 'getMyTeams',
|
||||
summary: 'Get me teams',
|
||||
tags: ['Account'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'getMeWebsites',
|
||||
operationId: 'getMyWebsites',
|
||||
summary: 'Get me websites',
|
||||
tags: ['Account'],
|
||||
parameters: [
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { badRequestResponse, jsonResponse, unauthorizedResponse } from '@/openapi/schemas';
|
||||
import {
|
||||
authorizationDecisionSchema,
|
||||
authorizationDetailsSchema,
|
||||
authorizationRedirectSchema,
|
||||
authorizationRequestSchema,
|
||||
oauthErrorSchema,
|
||||
} from '../schema';
|
||||
|
||||
const describeAuthorizationOperation = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/oauth/authorize',
|
||||
audience: 'internal',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'describeOAuthAuthorization',
|
||||
summary: 'Describe a pending OAuth authorization request',
|
||||
description:
|
||||
'Validates an OAuth 2.1 authorization request and returns the client and scopes for the consent screen. Requires an interactive user session.',
|
||||
tags: ['OAuth'],
|
||||
requestParams: { query: authorizationRequestSchema },
|
||||
responses: {
|
||||
'200': jsonResponse(authorizationDetailsSchema, 'Authorization request details.'),
|
||||
'400': jsonResponse(oauthErrorSchema, 'Invalid authorization request.'),
|
||||
'401': unauthorizedResponse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const decideAuthorizationOperation = defineOperation({
|
||||
method: 'post',
|
||||
path: '/api/oauth/authorize',
|
||||
audience: 'internal',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'decideOAuthAuthorization',
|
||||
summary: 'Approve or deny an OAuth authorization request',
|
||||
description:
|
||||
'Records the user decision. On approval an authorization code is issued and the redirect URL (with code, state and iss) is returned.',
|
||||
tags: ['OAuth'],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: { 'application/json': { schema: authorizationDecisionSchema } },
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(authorizationRedirectSchema, 'Redirect URL for the browser.'),
|
||||
'400': badRequestResponse,
|
||||
'401': unauthorizedResponse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [describeAuthorizationOperation, decideAuthorizationOperation] as const;
|
||||
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
buildErrorRedirect,
|
||||
buildSuccessRedirect,
|
||||
issueAuthorizationCode,
|
||||
validateAuthorizationRequest,
|
||||
} from '@/lib/oauth/authorize';
|
||||
import { getIssuer, isOAuthEnabled } from '@/lib/oauth/config';
|
||||
import { OAuthError, oauthErrorResponse } from '@/lib/oauth/errors';
|
||||
import { OAUTH_SCOPE_DESCRIPTIONS } from '@/lib/oauth/scopes';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, notFound, unauthorized } from '@/lib/response';
|
||||
import { authorizationDecisionSchema, authorizationRequestSchema } from '../schema';
|
||||
|
||||
function requireSession(auth: { user?: { id: string }; authType?: string } | null) {
|
||||
// Only an interactive user session may grant consent: never an API key or another OAuth token.
|
||||
return !!auth?.user?.id && (auth.authType === undefined || auth.authType === 'session');
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes a pending authorization request for the consent screen. Validation errors are
|
||||
* returned as JSON (the consent UI renders them) — no redirect happens until the user decides.
|
||||
*/
|
||||
export async function GET(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const { auth, query, error } = await parseRequest(request, authorizationRequestSchema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!requireSession(auth)) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
try {
|
||||
const validated = await validateAuthorizationRequest(query, getIssuer(request.headers));
|
||||
|
||||
return json({
|
||||
client: {
|
||||
id: validated.client.clientId,
|
||||
name: validated.client.clientName,
|
||||
uri: validated.client.clientUri,
|
||||
logoUri: validated.client.logoUri,
|
||||
source: validated.client.source,
|
||||
},
|
||||
scopes: validated.scopes.map(scope => ({
|
||||
scope,
|
||||
description: OAUTH_SCOPE_DESCRIPTIONS[scope],
|
||||
})),
|
||||
redirectUri: validated.redirectUri,
|
||||
resource: validated.resource,
|
||||
});
|
||||
} catch (err) {
|
||||
return oauthErrorResponse(err);
|
||||
}
|
||||
}
|
||||
|
||||
/** Records the user's decision and returns the redirect URL the browser should navigate to. */
|
||||
export async function POST(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, authorizationDecisionSchema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
if (!requireSession(auth)) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const issuer = getIssuer(request.headers);
|
||||
const { decision, ...params } = body;
|
||||
|
||||
try {
|
||||
const validated = await validateAuthorizationRequest(params, issuer);
|
||||
|
||||
if (decision !== 'approve') {
|
||||
return json({
|
||||
redirectUrl: buildErrorRedirect(
|
||||
validated.redirectUri,
|
||||
new OAuthError('access_denied', 'The user denied the request.'),
|
||||
validated.state,
|
||||
issuer,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
const code = await issueAuthorizationCode(validated, auth.user.id);
|
||||
|
||||
return json({ redirectUrl: buildSuccessRedirect(validated, code, issuer) });
|
||||
} catch (err) {
|
||||
return oauthErrorResponse(err);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { jsonResponse } from '@/openapi/schemas';
|
||||
import {
|
||||
clientRegistrationRequestSchema,
|
||||
clientRegistrationResponseSchema,
|
||||
oauthErrorSchema,
|
||||
} from '../schema';
|
||||
|
||||
const registerOperation = defineOperation({
|
||||
method: 'post',
|
||||
path: '/api/oauth/register',
|
||||
audience: 'internal',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'oauthRegisterClient',
|
||||
summary: 'Register an OAuth client (dynamic client registration)',
|
||||
description:
|
||||
'RFC 7591 compatibility endpoint for MCP clients without Client ID Metadata Document support. Registers a public client. Prefer Client ID Metadata Documents (https URL client_id).',
|
||||
tags: ['OAuth'],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: { 'application/json': { schema: clientRegistrationRequestSchema } },
|
||||
},
|
||||
responses: {
|
||||
'201': jsonResponse(clientRegistrationResponseSchema, 'Registered client.'),
|
||||
'400': jsonResponse(oauthErrorSchema, 'Invalid client metadata.'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [registerOperation] as const;
|
||||
@@ -0,0 +1,107 @@
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { getIpAddress } from '@/lib/ip';
|
||||
import { isDynamicRegistrationEnabled } from '@/lib/oauth/config';
|
||||
import { OAuthError, oauthErrorResponse, oauthJson } from '@/lib/oauth/errors';
|
||||
import { corsPreflight } from '@/lib/oauth/metadata';
|
||||
import { isAcceptableRedirectUri } from '@/lib/oauth/redirect';
|
||||
import redis from '@/lib/redis';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { notFound } from '@/lib/response';
|
||||
import { createOauthClient } from '@/queries/prisma/oauth';
|
||||
import { clientRegistrationRequestSchema } from '../schema';
|
||||
|
||||
const REGISTRATIONS_PER_HOUR = 20;
|
||||
|
||||
export function OPTIONS() {
|
||||
return corsPreflight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Client Registration (RFC 7591) compatibility endpoint for MCP clients that do not yet
|
||||
* support Client ID Metadata Documents. Public clients only; disable with OAUTH_DISABLE_DCR=1.
|
||||
*/
|
||||
export async function POST(request: Request) {
|
||||
if (!isDynamicRegistrationEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const { body, error } = await parseRequest(request, clientRegistrationRequestSchema, {
|
||||
skipAuth: true,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return oauthJson(
|
||||
{ error: 'invalid_client_metadata', error_description: 'Invalid registration request.' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
if (redis.enabled) {
|
||||
const ip = getIpAddress(request.headers) ?? 'unknown';
|
||||
const allowed = await redis.client.rateLimit(
|
||||
`oauth:register:${ip}`,
|
||||
REGISTRATIONS_PER_HOUR,
|
||||
60 * 60,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
throw new OAuthError('temporarily_unavailable', 'Too many registrations. Try again later.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!body.redirect_uris.every(isAcceptableRedirectUri)) {
|
||||
throw new OAuthError(
|
||||
'invalid_redirect_uri',
|
||||
'redirect_uris must be absolute https, loopback http or custom-scheme URLs without fragments.',
|
||||
);
|
||||
}
|
||||
|
||||
const grantTypes = body.grant_types ?? ['authorization_code', 'refresh_token'];
|
||||
const responseTypes = body.response_types ?? ['code'];
|
||||
|
||||
if (grantTypes.some(type => !['authorization_code', 'refresh_token'].includes(type))) {
|
||||
throw new OAuthError('invalid_client_metadata', 'Unsupported grant_types.');
|
||||
}
|
||||
|
||||
if (responseTypes.some(type => type !== 'code')) {
|
||||
throw new OAuthError('invalid_client_metadata', 'Unsupported response_types.');
|
||||
}
|
||||
|
||||
const id = uuid();
|
||||
const metadata = {
|
||||
client_uri: body.client_uri,
|
||||
logo_uri: body.logo_uri,
|
||||
application_type: body.application_type,
|
||||
software_id: body.software_id,
|
||||
software_version: body.software_version,
|
||||
scope: body.scope,
|
||||
};
|
||||
|
||||
const client = await createOauthClient({
|
||||
id,
|
||||
name: body.client_name,
|
||||
redirectUris: body.redirect_uris,
|
||||
metadata,
|
||||
});
|
||||
|
||||
return oauthJson(
|
||||
{
|
||||
client_id: client.id,
|
||||
client_id_issued_at: Math.floor((client.createdAt ?? new Date()).getTime() / 1000),
|
||||
client_name: client.name,
|
||||
redirect_uris: body.redirect_uris,
|
||||
token_endpoint_auth_method: 'none',
|
||||
grant_types: grantTypes,
|
||||
response_types: responseTypes,
|
||||
...(body.client_uri ? { client_uri: body.client_uri } : {}),
|
||||
...(body.logo_uri ? { logo_uri: body.logo_uri } : {}),
|
||||
...(body.application_type ? { application_type: body.application_type } : {}),
|
||||
...(body.scope ? { scope: body.scope } : {}),
|
||||
},
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
return oauthErrorResponse(err);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { z } from 'zod';
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { jsonResponse } from '@/openapi/schemas';
|
||||
import { oauthErrorSchema, revocationRequestSchema } from '../schema';
|
||||
|
||||
const revokeOperation = defineOperation({
|
||||
method: 'post',
|
||||
path: '/api/oauth/revoke',
|
||||
audience: 'internal',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'oauthRevoke',
|
||||
summary: 'Revoke an OAuth refresh token',
|
||||
description:
|
||||
'RFC 7009 revocation endpoint. Revokes the given refresh token; unknown tokens are accepted silently.',
|
||||
tags: ['OAuth'],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/x-www-form-urlencoded': { schema: revocationRequestSchema },
|
||||
'application/json': { schema: revocationRequestSchema },
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(z.object({}), 'Token revoked (or already invalid).'),
|
||||
'400': jsonResponse(oauthErrorSchema, 'Malformed request.'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [revokeOperation] as const;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { isOAuthEnabled } from '@/lib/oauth/config';
|
||||
import { oauthErrorResponse, oauthJson } from '@/lib/oauth/errors';
|
||||
import { readOAuthBody } from '@/lib/oauth/form';
|
||||
import { corsPreflight } from '@/lib/oauth/metadata';
|
||||
import { handleRevocationRequest } from '@/lib/oauth/token';
|
||||
import { notFound } from '@/lib/response';
|
||||
|
||||
export function OPTIONS() {
|
||||
return corsPreflight();
|
||||
}
|
||||
|
||||
/** RFC 7009 token revocation. Always returns 200 for well-formed requests. */
|
||||
export async function POST(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
try {
|
||||
const params = await readOAuthBody(request);
|
||||
|
||||
if (typeof params.token !== 'string' || !params.token) {
|
||||
return oauthJson(
|
||||
{ error: 'invalid_request', error_description: 'token is required.' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
await handleRevocationRequest(params);
|
||||
|
||||
return oauthJson({});
|
||||
} catch (error) {
|
||||
return oauthErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const authorizationRequestSchema = z
|
||||
.object({
|
||||
response_type: z.string().optional(),
|
||||
client_id: z.string().max(2048),
|
||||
redirect_uri: z.string().max(2048).optional(),
|
||||
scope: z.string().max(500).optional(),
|
||||
state: z.string().max(1024).optional(),
|
||||
code_challenge: z.string().max(128).optional(),
|
||||
code_challenge_method: z.string().max(10).optional(),
|
||||
resource: z.string().max(2048).optional(),
|
||||
})
|
||||
.meta({ id: 'OAuthAuthorizationRequest' });
|
||||
|
||||
export const authorizationDecisionSchema = authorizationRequestSchema
|
||||
.extend({
|
||||
decision: z.enum(['approve', 'deny']),
|
||||
})
|
||||
.meta({ id: 'OAuthAuthorizationDecision' });
|
||||
|
||||
export const authorizationDetailsSchema = z
|
||||
.object({
|
||||
client: z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
uri: z.string().optional(),
|
||||
logoUri: z.string().optional(),
|
||||
source: z.enum(['metadata-document', 'registered']),
|
||||
}),
|
||||
scopes: z.array(z.object({ scope: z.string(), description: z.string() })),
|
||||
redirectUri: z.string(),
|
||||
resource: z.string(),
|
||||
})
|
||||
.meta({ id: 'OAuthAuthorizationDetails' });
|
||||
|
||||
export const authorizationRedirectSchema = z
|
||||
.object({ redirectUrl: z.string() })
|
||||
.meta({ id: 'OAuthAuthorizationRedirect' });
|
||||
|
||||
export const tokenRequestSchema = z
|
||||
.object({
|
||||
grant_type: z.enum(['authorization_code', 'refresh_token']),
|
||||
code: z.string().optional(),
|
||||
redirect_uri: z.string().optional(),
|
||||
client_id: z.string().optional(),
|
||||
code_verifier: z.string().optional(),
|
||||
refresh_token: z.string().optional(),
|
||||
scope: z.string().optional(),
|
||||
resource: z.string().optional(),
|
||||
})
|
||||
.meta({ id: 'OAuthTokenRequest' });
|
||||
|
||||
export const tokenResponseSchema = z
|
||||
.object({
|
||||
access_token: z.string(),
|
||||
token_type: z.literal('Bearer'),
|
||||
expires_in: z.number().int(),
|
||||
refresh_token: z.string(),
|
||||
scope: z.string(),
|
||||
})
|
||||
.meta({ id: 'OAuthTokenResponse' });
|
||||
|
||||
export const oauthErrorSchema = z
|
||||
.object({
|
||||
error: z.string(),
|
||||
error_description: z.string().optional(),
|
||||
})
|
||||
.meta({ id: 'OAuthErrorResponse' });
|
||||
|
||||
export const revocationRequestSchema = z
|
||||
.object({
|
||||
token: z.string(),
|
||||
token_type_hint: z.string().optional(),
|
||||
})
|
||||
.meta({ id: 'OAuthRevocationRequest' });
|
||||
|
||||
export const clientRegistrationRequestSchema = z
|
||||
.object({
|
||||
redirect_uris: z.array(z.string().max(2048)).min(1).max(20),
|
||||
client_name: z.string().trim().min(1).max(255),
|
||||
client_uri: z.string().max(2048).optional(),
|
||||
logo_uri: z.string().max(2048).optional(),
|
||||
token_endpoint_auth_method: z.literal('none').optional(),
|
||||
grant_types: z.array(z.string()).optional(),
|
||||
response_types: z.array(z.string()).optional(),
|
||||
application_type: z.enum(['web', 'native']).optional(),
|
||||
scope: z.string().max(500).optional(),
|
||||
software_id: z.string().max(255).optional(),
|
||||
software_version: z.string().max(255).optional(),
|
||||
})
|
||||
.meta({ id: 'OAuthClientRegistrationRequest' });
|
||||
|
||||
export const clientRegistrationResponseSchema = clientRegistrationRequestSchema
|
||||
.extend({
|
||||
client_id: z.string(),
|
||||
client_id_issued_at: z.number().int(),
|
||||
token_endpoint_auth_method: z.literal('none'),
|
||||
grant_types: z.array(z.string()),
|
||||
response_types: z.array(z.string()),
|
||||
})
|
||||
.meta({ id: 'OAuthClientRegistrationResponse' });
|
||||
@@ -0,0 +1,31 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { jsonResponse } from '@/openapi/schemas';
|
||||
import { oauthErrorSchema, tokenRequestSchema, tokenResponseSchema } from '../schema';
|
||||
|
||||
const tokenOperation = defineOperation({
|
||||
method: 'post',
|
||||
path: '/api/oauth/token',
|
||||
audience: 'internal',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'oauthToken',
|
||||
summary: 'OAuth 2.1 token endpoint',
|
||||
description:
|
||||
'Exchanges an authorization code (with PKCE code_verifier) or a refresh token for an access token. Accepts application/x-www-form-urlencoded or JSON. Refresh tokens are rotated on every use.',
|
||||
tags: ['OAuth'],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/x-www-form-urlencoded': { schema: tokenRequestSchema },
|
||||
'application/json': { schema: tokenRequestSchema },
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(tokenResponseSchema, 'Access and refresh tokens.'),
|
||||
'400': jsonResponse(oauthErrorSchema, 'Invalid grant or request.'),
|
||||
'401': jsonResponse(oauthErrorSchema, 'Invalid client.'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [tokenOperation] as const;
|
||||
@@ -0,0 +1,26 @@
|
||||
import { getIssuer, isOAuthEnabled } from '@/lib/oauth/config';
|
||||
import { oauthErrorResponse, oauthJson } from '@/lib/oauth/errors';
|
||||
import { readOAuthBody } from '@/lib/oauth/form';
|
||||
import { corsPreflight } from '@/lib/oauth/metadata';
|
||||
import { handleTokenRequest } from '@/lib/oauth/token';
|
||||
import { notFound } from '@/lib/response';
|
||||
|
||||
export function OPTIONS() {
|
||||
return corsPreflight();
|
||||
}
|
||||
|
||||
/** OAuth 2.1 token endpoint: authorization_code (PKCE) and refresh_token grants. */
|
||||
export async function POST(request: Request) {
|
||||
if (!isOAuthEnabled()) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
try {
|
||||
const params = await readOAuthBody(request);
|
||||
const tokens = await handleTokenRequest(params, getIssuer(request.headers));
|
||||
|
||||
return oauthJson(tokens);
|
||||
} catch (error) {
|
||||
return oauthErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deletePixelsPixelId',
|
||||
operationId: 'deletePixel',
|
||||
summary: 'Delete pixels pixel id',
|
||||
tags: ['Pixels'],
|
||||
parameters: [
|
||||
@@ -66,7 +66,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getPixelsPixelId',
|
||||
operationId: 'getPixel',
|
||||
summary: 'Get pixels pixel id',
|
||||
tags: ['Pixels'],
|
||||
parameters: [
|
||||
@@ -156,7 +156,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postPixelsPixelId',
|
||||
operationId: 'updatePixel',
|
||||
summary: 'Create or update pixels pixel id',
|
||||
tags: ['Pixels'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getPixelsPixelIdShares',
|
||||
operationId: 'getPixelShares',
|
||||
summary: 'Get pixels pixel id shares',
|
||||
tags: ['Pixels'],
|
||||
parameters: [
|
||||
@@ -428,7 +428,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postPixelsPixelIdShares',
|
||||
operationId: 'createPixelShare',
|
||||
summary: 'Create or update pixels pixel id shares',
|
||||
tags: ['Pixels'],
|
||||
parameters: [
|
||||
|
||||
@@ -190,7 +190,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postPixels',
|
||||
operationId: 'createPixel',
|
||||
summary: 'Create or update pixels',
|
||||
tags: ['Pixels'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getRealtimeWebsiteId',
|
||||
operationId: 'getRealtime',
|
||||
summary: 'Get realtime website id',
|
||||
tags: ['Realtime'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'collect',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'postRecord',
|
||||
operationId: 'record',
|
||||
summary: 'Create or update record',
|
||||
tags: ['Collection'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteReportsReportId',
|
||||
operationId: 'deleteReport',
|
||||
summary: 'Delete reports report id',
|
||||
tags: ['Reports'],
|
||||
parameters: [
|
||||
@@ -83,7 +83,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getReportsReportId',
|
||||
operationId: 'getReport',
|
||||
summary: 'Get reports report id',
|
||||
tags: ['Reports'],
|
||||
parameters: [
|
||||
@@ -245,7 +245,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postReportsReportId',
|
||||
operationId: 'updateReport',
|
||||
summary: 'Create or update reports report id',
|
||||
tags: ['Reports'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsAttribution',
|
||||
operationId: 'runAttributionReport',
|
||||
summary: 'Create or update reports attribution',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsBreakdown',
|
||||
operationId: 'runBreakdownReport',
|
||||
summary: 'Create or update reports breakdown',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -258,7 +258,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postReports',
|
||||
operationId: 'createReport',
|
||||
summary: 'Create or update reports',
|
||||
tags: ['Reports'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsFunnel',
|
||||
operationId: 'runFunnelReport',
|
||||
summary: 'Create or update reports funnel',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsGoal',
|
||||
operationId: 'runGoalReport',
|
||||
summary: 'Create or update reports goal',
|
||||
tags: ['Reports'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsHeatmap',
|
||||
operationId: 'runHeatmapReport',
|
||||
summary: 'Create or update reports heatmap',
|
||||
tags: ['Reports'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsJourney',
|
||||
operationId: 'runJourneyReport',
|
||||
summary: 'Create or update reports journey',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsPerformance',
|
||||
operationId: 'runPerformanceReport',
|
||||
summary: 'Create or update reports performance',
|
||||
tags: ['Reports'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsRetention',
|
||||
operationId: 'runRetentionReport',
|
||||
summary: 'Create or update reports retention',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsRevenue',
|
||||
operationId: 'runRevenueReport',
|
||||
summary: 'Create or update reports revenue',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'postReportsUtm',
|
||||
operationId: 'runUtmReport',
|
||||
summary: 'Create or update reports utm',
|
||||
tags: ['Reports'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'collect',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'postSend',
|
||||
operationId: 'send',
|
||||
summary: 'Create or update send',
|
||||
tags: ['Collection'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'none',
|
||||
operation: {
|
||||
operationId: 'getShareSlug',
|
||||
operationId: 'getShareBySlug',
|
||||
summary: 'Get share slug',
|
||||
tags: ['Shares'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postShare',
|
||||
operationId: 'createShare',
|
||||
summary: 'Create or update share',
|
||||
tags: ['Shares'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteShareIdShareId',
|
||||
operationId: 'deleteShare',
|
||||
summary: 'Delete share id share id',
|
||||
tags: ['Shares'],
|
||||
parameters: [
|
||||
@@ -66,7 +66,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getShareIdShareId',
|
||||
operationId: 'getShare',
|
||||
summary: 'Get share id share id',
|
||||
tags: ['Shares'],
|
||||
parameters: [
|
||||
@@ -207,7 +207,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postShareIdShareId',
|
||||
operationId: 'updateShare',
|
||||
summary: 'Create or update share id share id',
|
||||
tags: ['Shares'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamIdBoards',
|
||||
operationId: 'getTeamBoards',
|
||||
summary: 'Get teams team id boards',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteTeamsTeamId',
|
||||
operationId: 'deleteTeam',
|
||||
summary: 'Delete teams team id',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
@@ -66,7 +66,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamId',
|
||||
operationId: 'getTeam',
|
||||
summary: 'Get teams team id',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
@@ -173,7 +173,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postTeamsTeamId',
|
||||
operationId: 'updateTeam',
|
||||
summary: 'Create or update teams team id',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamIdLinks',
|
||||
operationId: 'getTeamLinks',
|
||||
summary: 'Get teams team id links',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamIdPixels',
|
||||
operationId: 'getTeamPixels',
|
||||
summary: 'Get teams team id pixels',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteTeamsTeamIdUsersUserId',
|
||||
operationId: 'deleteTeamUser',
|
||||
summary: 'Delete teams team id users user id',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
@@ -91,7 +91,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamIdUsersUserId',
|
||||
operationId: 'getTeamUser',
|
||||
summary: 'Get teams team id users user id',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
@@ -173,7 +173,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postTeamsTeamIdUsersUserId',
|
||||
operationId: 'updateTeamUser',
|
||||
summary: 'Create or update teams team id users user id',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamIdUsers',
|
||||
operationId: 'getTeamUsers',
|
||||
summary: 'Get teams team id users',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
@@ -186,7 +186,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postTeamsTeamIdUsers',
|
||||
operationId: 'createTeamUser',
|
||||
summary: 'Create or update teams team id users',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getTeamsTeamIdWebsites',
|
||||
operationId: 'getTeamWebsites',
|
||||
summary: 'Get teams team id websites',
|
||||
tags: ['Teams'],
|
||||
parameters: [
|
||||
|
||||
@@ -182,7 +182,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postTeams',
|
||||
operationId: 'createTeam',
|
||||
summary: 'Create or update teams',
|
||||
tags: ['Teams'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postTeamsJoin',
|
||||
operationId: 'joinTeam',
|
||||
summary: 'Create or update teams join',
|
||||
tags: ['Teams'],
|
||||
requestBody: {
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteUsersUserId',
|
||||
operationId: 'deleteUser',
|
||||
summary: 'Delete users user id',
|
||||
tags: ['Users'],
|
||||
parameters: [
|
||||
@@ -83,7 +83,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getUsersUserId',
|
||||
operationId: 'getUser',
|
||||
summary: 'Get users user id',
|
||||
tags: ['Users'],
|
||||
parameters: [
|
||||
@@ -810,6 +810,121 @@ const operation2 = defineOperation({
|
||||
],
|
||||
},
|
||||
},
|
||||
oauthAuthorizationCodes: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
},
|
||||
userId: {
|
||||
type: 'string',
|
||||
},
|
||||
createdAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
codeHash: {
|
||||
type: 'string',
|
||||
},
|
||||
expiresAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
clientId: {
|
||||
type: 'string',
|
||||
},
|
||||
redirectUri: {
|
||||
type: 'string',
|
||||
},
|
||||
scope: {
|
||||
type: 'string',
|
||||
},
|
||||
resource: {
|
||||
type: 'string',
|
||||
},
|
||||
codeChallenge: {
|
||||
type: 'string',
|
||||
},
|
||||
codeChallengeMethod: {
|
||||
type: 'string',
|
||||
},
|
||||
usedAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'userId',
|
||||
'createdAt',
|
||||
'codeHash',
|
||||
'expiresAt',
|
||||
'clientId',
|
||||
'redirectUri',
|
||||
'scope',
|
||||
'resource',
|
||||
'codeChallenge',
|
||||
'codeChallengeMethod',
|
||||
'usedAt',
|
||||
],
|
||||
},
|
||||
},
|
||||
oauthRefreshTokens: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
},
|
||||
userId: {
|
||||
type: 'string',
|
||||
},
|
||||
createdAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
expiresAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
lastUsedAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
clientId: {
|
||||
type: 'string',
|
||||
},
|
||||
scope: {
|
||||
type: 'string',
|
||||
},
|
||||
resource: {
|
||||
type: 'string',
|
||||
},
|
||||
tokenHash: {
|
||||
type: 'string',
|
||||
},
|
||||
revokedAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'userId',
|
||||
'createdAt',
|
||||
'expiresAt',
|
||||
'lastUsedAt',
|
||||
'clientId',
|
||||
'scope',
|
||||
'resource',
|
||||
'tokenHash',
|
||||
'revokedAt',
|
||||
],
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -849,6 +964,12 @@ const operation2 = defineOperation({
|
||||
apiKeys: {
|
||||
type: 'number',
|
||||
},
|
||||
oauthAuthorizationCodes: {
|
||||
type: 'number',
|
||||
},
|
||||
oauthRefreshTokens: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'websites',
|
||||
@@ -863,6 +984,8 @@ const operation2 = defineOperation({
|
||||
'twoFactorOtpUseds',
|
||||
'twoFactorRateLimit',
|
||||
'apiKeys',
|
||||
'oauthAuthorizationCodes',
|
||||
'oauthRefreshTokens',
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -885,6 +1008,8 @@ const operation2 = defineOperation({
|
||||
'twoFactorBackupCodes',
|
||||
'twoFactorOtpUseds',
|
||||
'apiKeys',
|
||||
'oauthAuthorizationCodes',
|
||||
'oauthRefreshTokens',
|
||||
'_count',
|
||||
],
|
||||
},
|
||||
@@ -918,7 +1043,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postUsersUserId',
|
||||
operationId: 'updateUser',
|
||||
summary: 'Create or update users user id',
|
||||
tags: ['Users'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'getUsersUserIdTeams',
|
||||
operationId: 'getUserTeams',
|
||||
summary: 'Get users user id teams',
|
||||
tags: ['Users'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'getUsersUserIdWebsites',
|
||||
operationId: 'getUserWebsites',
|
||||
summary: 'Get users user id websites',
|
||||
tags: ['Users'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postUsers',
|
||||
operationId: 'createUser',
|
||||
summary: 'Create or update users',
|
||||
tags: ['Users'],
|
||||
requestBody: {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
// Generated by `pnpm openapi:contracts`. Do not edit directly.
|
||||
|
||||
import type { ZodOpenApiOperationObject } from 'zod-openapi';
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
|
||||
const operation1 = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/active',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdActive',
|
||||
summary: 'Get websites website id active',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: 'The operation completed successfully.',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
visitors: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
required: ['visitors'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'401': {
|
||||
description: 'Unauthorized.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Unauthorized.',
|
||||
code: 'unauthorized',
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ZodOpenApiOperationObject,
|
||||
});
|
||||
|
||||
export const operations = [operation1] as const;
|
||||
@@ -0,0 +1,26 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { jsonResponse, unauthorizedResponse } from '@/openapi/schemas';
|
||||
import { websiteIdPathSchema } from '../../response-schema';
|
||||
import { activeVisitorsSchema } from '../analytics-schema';
|
||||
|
||||
const getWebsiteActiveOperation = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/active',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsiteActive',
|
||||
summary: 'Get current active visitors',
|
||||
description: 'Returns the number of visitors active on the website in the last few minutes.',
|
||||
tags: ['Websites'],
|
||||
requestParams: {
|
||||
path: websiteIdPathSchema,
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(activeVisitorsSchema, 'Active visitor count.'),
|
||||
'401': unauthorizedResponse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [getWebsiteActiveOperation] as const;
|
||||
@@ -0,0 +1,145 @@
|
||||
import { z } from 'zod';
|
||||
import { filterParams, pagingParams, searchParams, withDateRange } from '@/lib/schema';
|
||||
|
||||
/** Shared request/response schemas for the analytics routes under /api/websites/{websiteId}. */
|
||||
|
||||
export const analyticsQuerySchema = withDateRange({ ...filterParams }).meta({
|
||||
id: 'AnalyticsQuery',
|
||||
description:
|
||||
'Date range (startAt/endAt in milliseconds or startDate/endDate ISO) plus optional filters. Filter values match exactly unless prefixed with an operator such as `neq.`, `c.` (contains) or `re.`.',
|
||||
});
|
||||
|
||||
export const pagedAnalyticsQuerySchema = withDateRange({
|
||||
...filterParams,
|
||||
...pagingParams,
|
||||
...searchParams,
|
||||
}).meta({ id: 'PagedAnalyticsQuery' });
|
||||
|
||||
export const metricsQuerySchema = withDateRange({
|
||||
type: z.string().meta({
|
||||
description:
|
||||
'Dimension to rank: path, entry, exit, title, query, hostname, referrer, domain, channel, event, tag, browser, os, device, screen, language, country, region, city, distinctId, utmSource, utmMedium, utmCampaign, utmContent, utmTerm.',
|
||||
}),
|
||||
limit: z.coerce.number().optional(),
|
||||
offset: z.coerce.number().optional(),
|
||||
...searchParams,
|
||||
...filterParams,
|
||||
}).meta({ id: 'MetricsQuery' });
|
||||
|
||||
export const websiteStatsValuesSchema = z
|
||||
.object({
|
||||
pageviews: z.number(),
|
||||
visitors: z.number(),
|
||||
visits: z.number(),
|
||||
bounces: z.number(),
|
||||
totaltime: z.number(),
|
||||
})
|
||||
.meta({ id: 'WebsiteStatsValues' });
|
||||
|
||||
export const websiteStatsSchema = websiteStatsValuesSchema
|
||||
.extend({
|
||||
comparison: websiteStatsValuesSchema.meta({
|
||||
description: 'The same totals for the comparison period (previous period by default).',
|
||||
}),
|
||||
})
|
||||
.meta({ id: 'WebsiteStats' });
|
||||
|
||||
export const timeSeriesPointSchema = z
|
||||
.object({
|
||||
x: z.string().meta({ description: 'Bucket start (ISO date/time).' }),
|
||||
y: z.number().meta({ description: 'Value for the bucket.' }),
|
||||
})
|
||||
.meta({ id: 'TimeSeriesPoint' });
|
||||
|
||||
const pageviewsSeriesSchema = z.object({
|
||||
pageviews: z.array(timeSeriesPointSchema),
|
||||
sessions: z.array(timeSeriesPointSchema),
|
||||
});
|
||||
|
||||
export const websitePageviewsSchema = pageviewsSeriesSchema
|
||||
.extend({
|
||||
startDate: z.iso.datetime().optional(),
|
||||
endDate: z.iso.datetime().optional(),
|
||||
compare: pageviewsSeriesSchema
|
||||
.extend({
|
||||
startDate: z.iso.datetime(),
|
||||
endDate: z.iso.datetime(),
|
||||
})
|
||||
.optional()
|
||||
.meta({ description: 'Present when `compare` was requested.' }),
|
||||
})
|
||||
.meta({ id: 'WebsitePageviews' });
|
||||
|
||||
export const metricRowSchema = z
|
||||
.object({
|
||||
x: z.string().nullable().meta({ description: 'Dimension value (e.g. a path or country).' }),
|
||||
y: z.number().meta({ description: 'Count of views/events or unique visitors.' }),
|
||||
t: z.string().optional(),
|
||||
})
|
||||
.meta({ id: 'MetricRow' });
|
||||
|
||||
export const metricRowsSchema = z.array(metricRowSchema).meta({ id: 'MetricRows' });
|
||||
|
||||
export const activeVisitorsSchema = z
|
||||
.object({ visitors: z.number().int().nonnegative() })
|
||||
.meta({ id: 'ActiveVisitors' });
|
||||
|
||||
export const websiteSessionSchema = z
|
||||
.looseObject({
|
||||
id: z.uuid(),
|
||||
websiteId: z.uuid(),
|
||||
hostname: z.string().nullable(),
|
||||
browser: z.string().nullable(),
|
||||
os: z.string().nullable(),
|
||||
device: z.string().nullable(),
|
||||
screen: z.string().nullable(),
|
||||
language: z.string().nullable(),
|
||||
country: z.string().nullable(),
|
||||
region: z.string().nullable(),
|
||||
city: z.string().nullable(),
|
||||
distinctId: z.string().nullable().optional(),
|
||||
firstAt: z.iso.datetime(),
|
||||
lastAt: z.iso.datetime(),
|
||||
visits: z.number(),
|
||||
views: z.number(),
|
||||
events: z.number().optional(),
|
||||
createdAt: z.iso.datetime(),
|
||||
})
|
||||
.meta({ id: 'WebsiteSession' });
|
||||
|
||||
export const websiteSessionPageSchema = z
|
||||
.object({
|
||||
data: z.array(websiteSessionSchema),
|
||||
count: z.number().int().nonnegative(),
|
||||
page: z.number().int().positive(),
|
||||
pageSize: z.number().int().nonnegative(),
|
||||
isCapped: z.boolean().optional(),
|
||||
})
|
||||
.meta({ id: 'WebsiteSessionPage' });
|
||||
|
||||
export const websiteEventSchema = z
|
||||
.looseObject({
|
||||
id: z.uuid(),
|
||||
websiteId: z.uuid(),
|
||||
sessionId: z.uuid(),
|
||||
createdAt: z.iso.datetime(),
|
||||
hostname: z.string().nullable().optional(),
|
||||
urlPath: z.string().nullable().optional(),
|
||||
urlQuery: z.string().nullable().optional(),
|
||||
referrerDomain: z.string().nullable().optional(),
|
||||
pageTitle: z.string().nullable().optional(),
|
||||
eventType: z.number().int(),
|
||||
eventName: z.string().nullable().optional(),
|
||||
distinctId: z.string().nullable().optional(),
|
||||
})
|
||||
.meta({ id: 'WebsiteEvent' });
|
||||
|
||||
export const websiteEventPageSchema = z
|
||||
.object({
|
||||
data: z.array(websiteEventSchema),
|
||||
count: z.number().int().nonnegative(),
|
||||
page: z.number().int().positive(),
|
||||
pageSize: z.number().int().nonnegative(),
|
||||
isCapped: z.boolean().optional(),
|
||||
})
|
||||
.meta({ id: 'WebsiteEventPage' });
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'deleteWebsitesWebsiteIdAnnotationsAnnotationId',
|
||||
operationId: 'deleteWebsiteAnnotation',
|
||||
summary: 'Delete websites website id annotations annotation id',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
@@ -91,7 +91,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdAnnotationsAnnotationId',
|
||||
operationId: 'getWebsiteAnnotation',
|
||||
summary: 'Get websites website id annotations annotation id',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
@@ -206,7 +206,7 @@ const operation3 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postWebsitesWebsiteIdAnnotationsAnnotationId',
|
||||
operationId: 'updateWebsiteAnnotation',
|
||||
summary: 'Create or update websites website id annotations annotation id',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdAnnotations',
|
||||
operationId: 'getWebsiteAnnotations',
|
||||
summary: 'Get websites website id annotations',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
@@ -197,7 +197,7 @@ const operation2 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer',
|
||||
operation: {
|
||||
operationId: 'postWebsitesWebsiteIdAnnotations',
|
||||
operationId: 'createWebsiteAnnotation',
|
||||
summary: 'Create or update websites website id annotations',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdDaterange',
|
||||
operationId: 'getWebsiteDateRange',
|
||||
summary: 'Get websites website id daterange',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataPivotArraySeries',
|
||||
operationId: 'getEventDataArraySeries',
|
||||
summary: 'Get websites website id event data pivot array series',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataPivot',
|
||||
operationId: 'getEventDataPivot',
|
||||
summary: 'Get websites website id event data pivot',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataPivotDateSeries',
|
||||
operationId: 'getEventDataDateSeries',
|
||||
summary: 'Get websites website id event data pivot date series',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataPivotNumericSeries',
|
||||
operationId: 'getEventDataNumericSeries',
|
||||
summary: 'Get websites website id event data pivot numeric series',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataPivotNumericStats',
|
||||
operationId: 'getEventDataNumericStats',
|
||||
summary: 'Get websites website id event data pivot numeric stats',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataPivotPropertySeries',
|
||||
operationId: 'getEventDataPropertySeries',
|
||||
summary: 'Get websites website id event data pivot property series',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataEventId',
|
||||
operationId: 'getEventDataById',
|
||||
summary: 'Get websites website id event data event id',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventData',
|
||||
operationId: 'getEventData',
|
||||
summary: 'Get websites website id event data',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataEvents',
|
||||
operationId: 'getEventDataEvents',
|
||||
summary: 'Get websites website id event data events',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataFields',
|
||||
operationId: 'getEventDataFields',
|
||||
summary: 'Get websites website id event data fields',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -41,7 +41,9 @@ test('uses eventName as the explicit event selector for property fields', async
|
||||
parseRequestMock.mockResolvedValue({ auth: {}, query, error: undefined });
|
||||
canViewWebsiteSectionMock.mockResolvedValue(true);
|
||||
getQueryFiltersMock.mockResolvedValue(filters as any);
|
||||
getEventDataFieldsMock.mockResolvedValue([{ propertyName: 'currency', dataType: 1, total: 1 }] as any);
|
||||
getEventDataFieldsMock.mockResolvedValue([
|
||||
{ propertyName: 'currency', dataType: 1, total: 1 },
|
||||
] as any);
|
||||
|
||||
const response = await GET(
|
||||
new Request(
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataProperties',
|
||||
operationId: 'getEventDataProperties',
|
||||
summary: 'Get websites website id event data properties',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataStats',
|
||||
operationId: 'getEventDataStats',
|
||||
summary: 'Get websites website id event data stats',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventDataValues',
|
||||
operationId: 'getEventDataValues',
|
||||
summary: 'Get websites website id event data values',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -1,490 +0,0 @@
|
||||
// Generated by `pnpm openapi:contracts`. Do not edit directly.
|
||||
|
||||
import type { ZodOpenApiOperationObject } from 'zod-openapi';
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
|
||||
const operation1 = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/events',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEvents',
|
||||
summary: 'Get websites website id events',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'startAt',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endAt',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'startDate',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endDate',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'timezone',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'unit',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'compare',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['prev', 'yoy'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'path',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'referrer',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'query',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'os',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'device',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'country',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'region',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'city',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'tag',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'hostname',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'distinctId',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'language',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'event',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmSource',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmMedium',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmCampaign',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmContent',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmTerm',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'excludeBounce',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'segment',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'cohort',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'eventType',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'match',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['all', 'any'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'page',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'pageSize',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'maxResults',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'search',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: 'The operation completed successfully.',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
data: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
},
|
||||
websiteId: {
|
||||
type: 'string',
|
||||
},
|
||||
sessionId: {
|
||||
type: 'string',
|
||||
},
|
||||
createdAt: {
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
],
|
||||
},
|
||||
hostname: {
|
||||
type: 'string',
|
||||
},
|
||||
urlPath: {
|
||||
type: 'string',
|
||||
},
|
||||
urlQuery: {
|
||||
type: 'string',
|
||||
},
|
||||
referrerPath: {
|
||||
type: 'string',
|
||||
},
|
||||
referrerQuery: {
|
||||
type: 'string',
|
||||
},
|
||||
referrerDomain: {
|
||||
type: 'string',
|
||||
},
|
||||
country: {
|
||||
type: 'string',
|
||||
},
|
||||
city: {
|
||||
type: 'string',
|
||||
},
|
||||
device: {
|
||||
type: 'string',
|
||||
},
|
||||
os: {
|
||||
type: 'string',
|
||||
},
|
||||
browser: {
|
||||
type: 'string',
|
||||
},
|
||||
pageTitle: {
|
||||
type: 'string',
|
||||
},
|
||||
eventType: {
|
||||
type: 'number',
|
||||
},
|
||||
eventName: {
|
||||
type: 'string',
|
||||
},
|
||||
hasData: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'websiteId',
|
||||
'sessionId',
|
||||
'createdAt',
|
||||
'hostname',
|
||||
'urlPath',
|
||||
'urlQuery',
|
||||
'referrerPath',
|
||||
'referrerQuery',
|
||||
'referrerDomain',
|
||||
'country',
|
||||
'city',
|
||||
'device',
|
||||
'os',
|
||||
'browser',
|
||||
'pageTitle',
|
||||
'eventType',
|
||||
'eventName',
|
||||
'hasData',
|
||||
],
|
||||
},
|
||||
},
|
||||
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': {
|
||||
description: 'Bad request.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Bad request.',
|
||||
code: 'bad-request',
|
||||
status: 400,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'401': {
|
||||
description: 'Unauthorized.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Unauthorized.',
|
||||
code: 'unauthorized',
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ZodOpenApiOperationObject,
|
||||
});
|
||||
|
||||
export const operations = [operation1] as const;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { badRequestResponse, jsonResponse, unauthorizedResponse } from '@/openapi/schemas';
|
||||
import { websiteIdPathSchema } from '../../response-schema';
|
||||
import { pagedAnalyticsQuerySchema, websiteEventPageSchema } from '../analytics-schema';
|
||||
|
||||
const getWebsiteEventsOperation = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/events',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsiteEvents',
|
||||
summary: 'List tracked events',
|
||||
description:
|
||||
'Returns a page of pageviews and custom events in the date range, newest first. Filter with `event` for a specific event name or `search` for free text.',
|
||||
tags: ['Websites'],
|
||||
requestParams: {
|
||||
path: websiteIdPathSchema,
|
||||
query: pagedAnalyticsQuerySchema,
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(websiteEventPageSchema, 'A page of events.'),
|
||||
'400': badRequestResponse,
|
||||
'401': unauthorizedResponse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [getWebsiteEventsOperation] as const;
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventsSeries',
|
||||
operationId: 'getWebsiteEventSeries',
|
||||
summary: 'Get websites website id events series',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdEventsStats',
|
||||
operationId: 'getWebsiteEventStats',
|
||||
summary: 'Get websites website id events stats',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -9,7 +9,7 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdExport',
|
||||
operationId: 'exportWebsite',
|
||||
summary: 'Get websites website id export',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
|
||||
@@ -1,384 +0,0 @@
|
||||
// Generated by `pnpm openapi:contracts`. Do not edit directly.
|
||||
|
||||
import type { ZodOpenApiOperationObject } from 'zod-openapi';
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
|
||||
const operation1 = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/metrics',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdMetrics',
|
||||
summary: 'Get websites website id metrics',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'startAt',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endAt',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'startDate',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endDate',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'timezone',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'unit',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'compare',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['prev', 'yoy'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'type',
|
||||
in: 'query',
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'limit',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'offset',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'search',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'path',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'referrer',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'query',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'os',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'device',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'country',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'region',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'city',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'tag',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'hostname',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'distinctId',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'language',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'event',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmSource',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmMedium',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmCampaign',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmContent',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmTerm',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'excludeBounce',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'segment',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'cohort',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'eventType',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'match',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['all', 'any'],
|
||||
},
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: 'The operation completed successfully.',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
x: {
|
||||
type: 'string',
|
||||
},
|
||||
t: {
|
||||
type: 'string',
|
||||
},
|
||||
y: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
required: ['x', 't', 'y'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'400': {
|
||||
description: 'Bad request.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Bad request.',
|
||||
code: 'bad-request',
|
||||
status: 400,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'401': {
|
||||
description: 'Unauthorized.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Unauthorized.',
|
||||
code: 'unauthorized',
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ZodOpenApiOperationObject,
|
||||
});
|
||||
|
||||
export const operations = [operation1] as const;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { badRequestResponse, jsonResponse, unauthorizedResponse } from '@/openapi/schemas';
|
||||
import { websiteIdPathSchema } from '../../response-schema';
|
||||
import { metricRowsSchema, metricsQuerySchema } from '../analytics-schema';
|
||||
|
||||
const getWebsiteMetricsOperation = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/metrics',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsiteMetrics',
|
||||
summary: 'Get ranked metrics for a dimension',
|
||||
description:
|
||||
'Returns the top values for one dimension (`type`), such as pages, referrers, countries, browsers, UTM parameters or events, ordered by count. Page-type dimensions count views/events; visitor dimensions count unique visitors.',
|
||||
tags: ['Websites'],
|
||||
requestParams: {
|
||||
path: websiteIdPathSchema,
|
||||
query: metricsQuerySchema,
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(metricRowsSchema, 'Ranked rows.'),
|
||||
'400': badRequestResponse,
|
||||
'401': unauthorizedResponse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [getWebsiteMetricsOperation] as const;
|
||||
@@ -9,9 +9,10 @@ const operation1 = defineOperation({
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdMetricsExpanded',
|
||||
operationId: 'getWebsiteExpandedMetrics',
|
||||
summary: 'Get websites website id metrics expanded',
|
||||
tags: ['Websites'],
|
||||
'x-umami-oauth-scope': 'analytics:read',
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
|
||||
@@ -1,378 +0,0 @@
|
||||
// Generated by `pnpm openapi:contracts`. Do not edit directly.
|
||||
|
||||
import type { ZodOpenApiOperationObject } from 'zod-openapi';
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
|
||||
const operation1 = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/pageviews',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitesWebsiteIdPageviews',
|
||||
summary: 'Get websites website id pageviews',
|
||||
tags: ['Websites'],
|
||||
parameters: [
|
||||
{
|
||||
name: 'websiteId',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'startAt',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endAt',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'startDate',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'endDate',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'timezone',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'unit',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'compare',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['prev', 'yoy'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'path',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'referrer',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'query',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'os',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'browser',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'device',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'country',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'region',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'city',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'tag',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'hostname',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'distinctId',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'language',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'event',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmSource',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmMedium',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmCampaign',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmContent',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'utmTerm',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'excludeBounce',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'segment',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'cohort',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'eventType',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'match',
|
||||
in: 'query',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'string',
|
||||
enum: ['all', 'any'],
|
||||
},
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: 'The operation completed successfully.',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
anyOf: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
pageviews: {},
|
||||
sessions: {},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
compare: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
pageviews: {},
|
||||
sessions: {},
|
||||
startDate: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
endDate: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
},
|
||||
required: ['pageviews', 'sessions', 'startDate', 'endDate'],
|
||||
},
|
||||
},
|
||||
required: ['pageviews', 'sessions', 'startDate', 'endDate', 'compare'],
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
pageviews: {},
|
||||
sessions: {},
|
||||
},
|
||||
required: ['pageviews', 'sessions'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'400': {
|
||||
description: 'Bad request.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Bad request.',
|
||||
code: 'bad-request',
|
||||
status: 400,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'401': {
|
||||
description: 'Unauthorized.',
|
||||
content: {
|
||||
'application/json': {
|
||||
example: {
|
||||
error: {
|
||||
message: 'Unauthorized.',
|
||||
code: 'unauthorized',
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
schema: {
|
||||
$ref: '#/components/schemas/ApiError',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as ZodOpenApiOperationObject,
|
||||
});
|
||||
|
||||
export const operations = [operation1] as const;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { defineOperation } from '@/openapi/operation';
|
||||
import { badRequestResponse, jsonResponse, unauthorizedResponse } from '@/openapi/schemas';
|
||||
import { websiteIdPathSchema } from '../../response-schema';
|
||||
import { analyticsQuerySchema, websitePageviewsSchema } from '../analytics-schema';
|
||||
|
||||
const getWebsitePageviewsOperation = defineOperation({
|
||||
method: 'get',
|
||||
path: '/api/websites/{websiteId}/pageviews',
|
||||
audience: 'public',
|
||||
auth: 'bearer-or-share',
|
||||
operation: {
|
||||
operationId: 'getWebsitePageviews',
|
||||
summary: 'Get pageview and session time series',
|
||||
description:
|
||||
'Returns pageviews and sessions bucketed by `unit` (minute, hour, day, month, year) in the given `timezone`. When `compare` is set the comparison period is included.',
|
||||
tags: ['Websites'],
|
||||
requestParams: {
|
||||
path: websiteIdPathSchema,
|
||||
query: analyticsQuerySchema,
|
||||
},
|
||||
responses: {
|
||||
'200': jsonResponse(websitePageviewsSchema, 'Time series.'),
|
||||
'400': badRequestResponse,
|
||||
'401': unauthorizedResponse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const operations = [getWebsitePageviewsOperation] as const;
|
||||
Loaded 100 of 235 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user