Skip to content

Commit 746ab32

Browse files
committed
Updates jsdocs and reorgs test helper
1 parent 747440a commit 746ab32

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { clientOptionsSchema, validate } from './utils/validation';
66
/**
77
* Fathom Analytics API SDK
88
* A fully typed client for interacting with the Fathom Analytics API
9+
* @link https://github.com/mackenly/fathom-api
10+
* @link https://usefathom.com/docs/api
911
*/
1012
export class FathomApi {
1113
private http: HttpClient;

src/utils/validation.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { z } from 'zod';
22
import { fromZodError } from 'zod-validation-error';
33
import { FathomApiError } from './http';
44

5-
// Common validation schemas
5+
/**
6+
* Pagination schema
7+
* This schema validates the pagination parameters for API requests.
8+
*/
69
export const paginationSchema: z.ZodObject<{
710
limit: z.ZodOptional<z.ZodNumber>;
811
starting_after: z.ZodOptional<z.ZodString>;
@@ -13,7 +16,10 @@ export const paginationSchema: z.ZodObject<{
1316
ending_before: z.string().optional(),
1417
}).strict();
1518

16-
// Site validation schemas
19+
/**
20+
* Site schema
21+
* This schema validates the site data for creating a site.
22+
*/
1723
export const createSiteSchema: z.ZodEffects<z.ZodObject<{
1824
name: z.ZodString;
1925
sharing: z.ZodOptional<z.ZodEnum<["none", "private", "public"]>>;
@@ -32,6 +38,10 @@ export const createSiteSchema: z.ZodEffects<z.ZodObject<{
3238
path: ['share_password'],
3339
});
3440

41+
/**
42+
* Site schema
43+
* This schema validates the optional fields for updating a site.
44+
*/
3545
export const updateSiteSchema: z.ZodEffects<z.ZodObject<{
3646
name: z.ZodOptional<z.ZodString>;
3747
sharing: z.ZodOptional<z.ZodEnum<["none", "private", "public"]>>;
@@ -50,13 +60,20 @@ export const updateSiteSchema: z.ZodEffects<z.ZodObject<{
5060
path: ['share_password'],
5161
});
5262

53-
// Event validation schemas
63+
/**
64+
* Event schema
65+
* This schema validates the event data for creating an event.
66+
*/
5467
export const createEventSchema: z.ZodObject<{
5568
name: z.ZodString;
5669
}> = z.object({
5770
name: z.string().min(1).max(255),
5871
}).strict();
5972

73+
/**
74+
* Update event schema
75+
* This schema validates the event data for updating an event.
76+
*/
6077
export const updateEventSchema: z.ZodObject<{
6178
name: z.ZodString;
6279
}> = z.object({
@@ -76,6 +93,10 @@ const aggregationFilterSchema: z.ZodObject<{
7693
value: z.string(),
7794
}).strict();
7895

96+
/**
97+
* Aggregation report validation schema
98+
* This schema validates the parameters for an aggregation report.
99+
*/
79100
export const aggregationParamsSchema: z.ZodObject<{
80101
entity: z.ZodEnum<["pageview", "event"]>;
81102
entity_id: z.ZodString;
@@ -106,7 +127,10 @@ export const aggregationParamsSchema: z.ZodObject<{
106127
filters: z.array(aggregationFilterSchema).optional(),
107128
}).strict();
108129

109-
// Current visitors validation schema
130+
/**
131+
* Current visitors validation schema
132+
* This schema validates the parameters for retrieving current visitors at a site.
133+
*/
110134
export const currentVisitorsParamsSchema: z.ZodObject<{
111135
site_id: z.ZodString;
112136
detailed: z.ZodOptional<z.ZodBoolean>;
@@ -115,7 +139,10 @@ export const currentVisitorsParamsSchema: z.ZodObject<{
115139
detailed: z.boolean().optional(),
116140
}).strict();
117141

118-
// Client options validation
142+
/**
143+
* Client options schema
144+
* This schema validates the options for creating a client.
145+
*/
119146
export const clientOptionsSchema: z.ZodObject<{
120147
token: z.ZodString;
121148
version: z.ZodOptional<z.ZodEnum<["v1"]>>;
@@ -150,5 +177,14 @@ export function validate<T>(
150177
}
151178

152179
// Rename exports inline to match the names expected by other files
180+
/**
181+
* Aggregation schema
182+
* @alias aggregationParamsSchema
183+
*/
153184
export const aggregationSchema = aggregationParamsSchema;
185+
186+
/**
187+
* Current visitors schema
188+
* @alias currentVisitorsParamsSchema
189+
*/
154190
export const currentVisitorsSchema = currentVisitorsParamsSchema;

tests/http.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect, beforeEach } from 'vitest';
22
import { HttpClient, FathomApiError } from '../src/utils/http';
3-
import { server, createMockHandler } from '../src/utils/test-setup';
3+
import { server, createMockHandler } from './test-setup';
44
import { rest } from 'msw';
55

66
describe('HttpClient', () => {

tests/sites.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, beforeEach } from 'vitest';
22
import { HttpClient } from '../src/utils/http';
33
import { SitesResource } from '../src/api/v1/sites';
4-
import { server, createMockHandler } from '../src/utils/test-setup';
4+
import { server, createMockHandler } from './test-setup';
55
import { rest } from 'msw';
66

77
describe('SitesResource', () => {

0 commit comments

Comments
 (0)