feat: group analytics
* wip * wip * wip * wip * wip * add buffer * wip * wip * fixes * fix * wip * group validation * fix group issues * docs: add groups
This commit is contained in:
committed by
GitHub
parent
88a2d876ce
commit
11e9ecac1a
@@ -540,6 +540,32 @@ export const zCheckout = z.object({
|
||||
});
|
||||
export type ICheckout = z.infer<typeof zCheckout>;
|
||||
|
||||
export const zGroupId = z
|
||||
.string()
|
||||
.min(1)
|
||||
.regex(
|
||||
/^[a-z0-9_-]+$/,
|
||||
'ID must only contain lowercase letters, digits, hyphens, or underscores',
|
||||
);
|
||||
|
||||
export const zCreateGroup = z.object({
|
||||
id: zGroupId,
|
||||
projectId: z.string(),
|
||||
type: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
properties: z.record(z.string()).default({}),
|
||||
});
|
||||
export type ICreateGroup = z.infer<typeof zCreateGroup>;
|
||||
|
||||
export const zUpdateGroup = z.object({
|
||||
id: z.string().min(1),
|
||||
projectId: z.string(),
|
||||
type: z.string().min(1).optional(),
|
||||
name: z.string().min(1).optional(),
|
||||
properties: z.record(z.string()).optional(),
|
||||
});
|
||||
export type IUpdateGroup = z.infer<typeof zUpdateGroup>;
|
||||
|
||||
export const zEditOrganization = z.object({
|
||||
id: z.string().min(2),
|
||||
name: z.string().min(2),
|
||||
|
||||
@@ -2,11 +2,24 @@ import { RESERVED_EVENT_NAMES } from '@openpanel/constants';
|
||||
import { z } from 'zod';
|
||||
import { isBlockedEventName } from './event-blocklist';
|
||||
|
||||
export const zGroupPayload = z.object({
|
||||
id: z.string().min(1),
|
||||
type: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
properties: z.record(z.unknown()).optional(),
|
||||
});
|
||||
|
||||
export const zAssignGroupPayload = z.object({
|
||||
groupIds: z.array(z.string().min(1)),
|
||||
profileId: z.union([z.string().min(1), z.number()]).optional(),
|
||||
});
|
||||
|
||||
export const zTrackPayload = z
|
||||
.object({
|
||||
name: z.string().min(1),
|
||||
properties: z.record(z.string(), z.unknown()).optional(),
|
||||
profileId: z.string().or(z.number()).optional(),
|
||||
profileId: z.union([z.string().min(1), z.number()]).optional(),
|
||||
groups: z.array(z.string().min(1)).optional(),
|
||||
})
|
||||
.refine((data) => !RESERVED_EVENT_NAMES.includes(data.name as any), {
|
||||
message: `Event name cannot be one of the reserved names: ${RESERVED_EVENT_NAMES.join(', ')}`,
|
||||
@@ -97,6 +110,14 @@ export const zTrackHandlerPayload = z.discriminatedUnion('type', [
|
||||
type: z.literal('replay'),
|
||||
payload: zReplayPayload,
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('group'),
|
||||
payload: zGroupPayload,
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('assign_group'),
|
||||
payload: zAssignGroupPayload,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type ITrackPayload = z.infer<typeof zTrackPayload>;
|
||||
@@ -105,6 +126,8 @@ export type IIncrementPayload = z.infer<typeof zIncrementPayload>;
|
||||
export type IDecrementPayload = z.infer<typeof zDecrementPayload>;
|
||||
export type IAliasPayload = z.infer<typeof zAliasPayload>;
|
||||
export type IReplayPayload = z.infer<typeof zReplayPayload>;
|
||||
export type IGroupPayload = z.infer<typeof zGroupPayload>;
|
||||
export type IAssignGroupPayload = z.infer<typeof zAssignGroupPayload>;
|
||||
export type ITrackHandlerPayload = z.infer<typeof zTrackHandlerPayload>;
|
||||
|
||||
// Deprecated types for beta version of the SDKs
|
||||
|
||||
Reference in New Issue
Block a user