🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance API documentation and endpoints for Sites and Organizations
Bill Yangfa25b9cd737d
diff --git a/client/src/app/[site]/api-playground/utils/endpointConfig.ts b/client/src/app/[site]/api-playground/utils/endpointConfig.tsindex 4143902be..41bae7512 100644--- a/client/src/app/[site]/api-playground/utils/endpointConfig.ts+++ b/client/src/app/[site]/api-playground/utils/endpointConfig.ts@@ -19,6 +19,126 @@ export interface EndpointCategory {}export const endpointCategories: EndpointCategory[] = [+ {+ name: "Sites",+ endpoints: [+ {+ method: "GET",+ path: "/sites/:site",+ name: "Get Site",+ description: "Returns details for a specific site",+ hasCommonParams: false,+ },+ {+ method: "DELETE",+ path: "/sites/:site",+ name: "Delete Site",+ description: "Permanently deletes a site and all its data. Requires admin/owner role.",+ hasCommonParams: false,+ },+ {+ method: "PUT",+ path: "/sites/:site/config",+ name: "Update Site Config",+ description: "Updates site configuration settings. Requires admin/owner role.",+ hasCommonParams: false,+ hasRequestBody: true,+ requestBodyExample: {+ public: true,+ blockBots: true,+ excludedCountries: ["CN", "RU"],+ },+ },+ {+ method: "GET",+ path: "/sites/:site/excluded-ips",+ name: "Get Excluded IPs",+ description: "Returns the list of excluded IP addresses",+ hasCommonParams: false,+ },+ {+ method: "GET",+ path: "/sites/:site/excluded-countries",+ name: "Get Excluded Countries",+ description: "Returns the list of excluded country codes",+ hasCommonParams: false,+ },+ {+ method: "GET",+ path: "/sites/:site/private-link-config",+ name: "Get Private Link Config",+ description: "Returns the private link key configuration",+ hasCommonParams: false,+ },+ {+ method: "POST",+ path: "/sites/:site/private-link-config",+ name: "Update Private Link",+ description: "Generates or revokes a private link key. Requires admin/owner role.",+ hasCommonParams: false,+ hasRequestBody: true,+ requestBodyExample: {+ action: "generate_private_link_key",+ },+ },+ ],+ },+ {+ name: "Organizations",+ endpoints: [+ {+ method: "GET",+ path: "/organizations",+ name: "Get My Organizations",+ description: "Returns all organizations the authenticated user is a member of, including all members for each organization",+ hasCommonParams: false,+ },+ {+ method: "GET",+ path: "/organizations/:organizationId/sites",+ name: "Get Organization Sites",+ description: "Returns all sites within an organization with session counts and subscription info",+ hasCommonParams: false,+ pathParams: ["organizationId"],+ },+ {+ method: "POST",+ path: "/organizations/:organizationId/sites",+ name: "Create Site",+ description: "Creates a new site in an organization. Requires admin/owner role.",+ hasCommonParams: false,+ pathParams: ["organizationId"],+ hasRequestBody: true,+ requestBodyExample: {+ domain: "example.com",+ name: "My Website",+ public: false,+ blockBots: true,+ },+ },+ {+ method: "GET",+ path: "/organizations/:organizationId/members",+ name: "Get Organization Members",+ description: "Returns all members of an organization with user details",+ hasCommonParams: false,+ pathParams: ["organizationId"],+ },+ {+ method: "POST",+ path: "/organizations/:organizationId/members",+ name: "Add Organization Member",+ description: "Adds a user to an organization with a specified role",+ hasCommonParams: false,+ pathParams: ["organizationId"],+ hasRequestBody: true,+ requestBodyExample: {+ email: "[email protected]",+ role: "member",+ },+ },+ ],+ },{name: "Overview",endpoints: [@@ -358,119 +478,6 @@ export const endpointCategories: EndpointCategory[] = [},],},- {- name: "Sites",- endpoints: [- {- method: "GET",- path: "/sites/:site",- name: "Get Site",- description: "Returns details for a specific site",- hasCommonParams: false,- },- {- method: "DELETE",- path: "/sites/:site",- name: "Delete Site",- description: "Permanently deletes a site and all its data. Requires admin/owner role.",- hasCommonParams: false,- },- {- method: "PUT",- path: "/sites/:site/config",- name: "Update Site Config",- description: "Updates site configuration settings. Requires admin/owner role.",- hasCommonParams: false,- hasRequestBody: true,- requestBodyExample: {- public: true,- blockBots: true,- excludedCountries: ["CN", "RU"],- },- },- {- method: "GET",- path: "/sites/:site/excluded-ips",- name: "Get Excluded IPs",- description: "Returns the list of excluded IP addresses",- hasCommonParams: false,- },- {- method: "GET",- path: "/sites/:site/excluded-countries",- name: "Get Excluded Countries",- description: "Returns the list of excluded country codes",- hasCommonParams: false,- },- {- method: "GET",- path: "/sites/:site/private-link-config",- name: "Get Private Link Config",- description: "Returns the private link key configuration",- hasCommonParams: false,- },- {- method: "POST",- path: "/sites/:site/private-link-config",- name: "Update Private Link",- description: "Generates or revokes a private link key. Requires admin/owner role.",- hasCommonParams: false,- hasRequestBody: true,- requestBodyExample: {- action: "generate_private_link_key",- },- },- ],- },- {- name: "Organizations",- endpoints: [- {- method: "GET",- path: "/organizations/:organizationId/sites",- name: "Get Organization Sites",- description: "Returns all sites within an organization with session counts and subscription info",- hasCommonParams: false,- pathParams: ["organizationId"],- },- {- method: "POST",- path: "/organizations/:organizationId/sites",- name: "Create Site",- description: "Creates a new site in an organization. Requires admin/owner role.",- hasCommonParams: false,- pathParams: ["organizationId"],- hasRequestBody: true,- requestBodyExample: {- domain: "example.com",- name: "My Website",- public: false,- blockBots: true,- },- },- {- method: "GET",- path: "/organizations/:organizationId/members",- name: "Get Organization Members",- description: "Returns all members of an organization with user details",- hasCommonParams: false,- pathParams: ["organizationId"],- },- {- method: "POST",- path: "/organizations/:organizationId/members",- name: "Add Organization Member",- description: "Adds a user to an organization with a specified role",- hasCommonParams: false,- pathParams: ["organizationId"],- hasRequestBody: true,- requestBodyExample: {- email: "[email protected]",- role: "member",- },- },- ],- },];// Flatten all endpoints for easy lookupdiff --git a/server/src/index.ts b/server/src/index.tsindex 29b158960..02400b108 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -313,7 +313,7 @@ async function sitesRoutes(fastify: FastifyInstance) {async function organizationsRoutes(fastify: FastifyInstance) {// Organizations- fastify.get("/organizations", authOnly, getMyOrganizations);+ fastify.get("/organizations", getMyOrganizations);fastify.get("/organizations/:organizationId/sites", orgMember, getSitesFromOrg);fastify.post("/organizations/:organizationId/sites", orgAdminParams, addSite);fastify.get("/organizations/:organizationId/members", orgMember, listOrganizationMembers);diff --git a/server/src/lib/auth-utils.ts b/server/src/lib/auth-utils.tsindex b7fb64462..0f0a2d943 100644--- a/server/src/lib/auth-utils.ts+++ b/server/src/lib/auth-utils.ts@@ -103,10 +103,7 @@ export async function getSitesUserHasAccessTo(req: FastifyRequest, adminOnly = freturn promise;}-export async function checkApiKey(- req: FastifyRequest,- options: { organizationId?: string; siteId?: string | number }-) {+export async function checkApiKey(req: FastifyRequest, options: { organizationId?: string; siteId?: string | number }) {// Check if a valid API key was provided// Priority: 1. Authorization: Bearer header (recommended), 2. Query parameter (testing only)const authHeader = req.headers["authorization"];