@middlewr/contracts 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/analytics.schema.d.ts +54 -0
- package/dist/cjs/analytics.schema.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +164 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +293 -250
- package/dist/cjs/workspaces.schema.d.ts +1 -0
- package/dist/cjs/workspaces.schema.d.ts.map +1 -1
- package/dist/esm/analytics.schema.d.ts +54 -0
- package/dist/esm/analytics.schema.d.ts.map +1 -1
- package/dist/esm/index.d.ts +164 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +287 -250
- package/dist/esm/workspaces.schema.d.ts +1 -0
- package/dist/esm/workspaces.schema.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/analytics.schema.ts +30 -0
- package/src/index.ts +15 -0
- package/src/workspaces.schema.ts +1 -0
package/src/analytics.schema.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
export const AnalyticsIntervalSchema = z.enum(['hour', 'day', 'week', 'month']);
|
|
4
|
+
|
|
5
|
+
export const AnalyticsQuerySchema = z.object({
|
|
6
|
+
start_at: z.coerce.date(),
|
|
7
|
+
end_at: z.coerce.date(),
|
|
8
|
+
interval: AnalyticsIntervalSchema,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const TimeSeriesPointSchema = z.object({
|
|
12
|
+
date: z.string(),
|
|
13
|
+
clicks: z.number().int(),
|
|
14
|
+
unique_visitors: z.number().int(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const CountByFieldSchema = z.object({
|
|
18
|
+
name: z.string(),
|
|
19
|
+
count: z.number().int(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const AnalyticsOutputSchema = z.object({
|
|
23
|
+
total_clicks: z.number().int(),
|
|
24
|
+
total_unique_visitors: z.number().int(),
|
|
25
|
+
timeseries: z.array(TimeSeriesPointSchema),
|
|
26
|
+
referrers: z.array(CountByFieldSchema),
|
|
27
|
+
devices: z.array(CountByFieldSchema),
|
|
28
|
+
countries: z.array(CountByFieldSchema),
|
|
29
|
+
browsers: z.array(CountByFieldSchema),
|
|
30
|
+
os: z.array(CountByFieldSchema),
|
|
31
|
+
});
|
|
32
|
+
|
|
3
33
|
export const LinkAnalyticsQuerySchema = z.object({
|
|
4
34
|
link_id: z.string().uuid(),
|
|
5
35
|
from: z.coerce.date(),
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ContractRouterClient } from '@orpc/contract';
|
|
|
2
2
|
import { oc } from '@orpc/contract';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
+
import { AnalyticsOutputSchema, AnalyticsQuerySchema } from './analytics.schema';
|
|
5
6
|
import { ApiKeySchema, CreateApiKeyInputSchema, CreateApiKeyResponseSchema } from './api-keys.schema';
|
|
6
7
|
import { BillingStatusSchema, CheckoutSessionSchema, CreateCheckoutInputSchema, CustomerPortalSchema } from './billing.schema';
|
|
7
8
|
import {
|
|
@@ -42,6 +43,19 @@ export * from './tags.schema';
|
|
|
42
43
|
export * from './users.schema';
|
|
43
44
|
export * from './workspaces.schema';
|
|
44
45
|
|
|
46
|
+
// Analytics contract
|
|
47
|
+
export const analyticsContract = {
|
|
48
|
+
workspace: oc
|
|
49
|
+
.route({ method: 'GET', path: '/api/workspaces/{workspace_id}/analytics' })
|
|
50
|
+
.input(WorkspaceIdParamSchema.merge(AnalyticsQuerySchema))
|
|
51
|
+
.output(AnalyticsOutputSchema),
|
|
52
|
+
|
|
53
|
+
link: oc
|
|
54
|
+
.route({ method: 'GET', path: '/api/workspaces/{workspace_id}/links/{link_id}/analytics' })
|
|
55
|
+
.input(LinkIdParamSchema.merge(AnalyticsQuerySchema))
|
|
56
|
+
.output(AnalyticsOutputSchema),
|
|
57
|
+
};
|
|
58
|
+
|
|
45
59
|
// Users contract
|
|
46
60
|
export const usersContract = {
|
|
47
61
|
me: oc.route({ method: 'GET', path: '/api/users/me' }).output(z.object({ user: UserSchema })),
|
|
@@ -229,6 +243,7 @@ export const billingContract = {
|
|
|
229
243
|
|
|
230
244
|
// Full contract
|
|
231
245
|
export const contract = {
|
|
246
|
+
analytics: analyticsContract,
|
|
232
247
|
users: usersContract,
|
|
233
248
|
apiKeys: apiKeysContract,
|
|
234
249
|
workspaces: workspacesContract,
|
package/src/workspaces.schema.ts
CHANGED
|
@@ -22,6 +22,7 @@ export const CreateWorkspaceInputSchema = z.object({
|
|
|
22
22
|
|
|
23
23
|
export const UpdateWorkspaceInputSchema = z.object({
|
|
24
24
|
name: z.string().min(1).max(100).optional(),
|
|
25
|
+
billing_email: z.string().email().nullish(),
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
export const TransferOwnershipInputSchema = z.object({
|