@teardown/schemas 0.1.43 → 0.1.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teardown/schemas",
3
- "version": "0.1.43",
3
+ "version": "0.1.44",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -82,6 +82,11 @@
82
82
  "types": "./src/modules/events/index.ts",
83
83
  "import": "./src/modules/events/index.ts",
84
84
  "default": "./src/modules/events/index.ts"
85
+ },
86
+ "./headers": {
87
+ "types": "./src/modules/headers/index.ts",
88
+ "import": "./src/modules/headers/index.ts",
89
+ "default": "./src/modules/headers/index.ts"
85
90
  }
86
91
  },
87
92
  "scripts": {
@@ -93,11 +98,11 @@
93
98
  },
94
99
  "dependencies": {
95
100
  "@sinclair/typebox": "^0.34.41",
96
- "@teardown/types": "0.1.43"
101
+ "@teardown/types": "0.1.44"
97
102
  },
98
103
  "devDependencies": {
99
104
  "@biomejs/biome": "2.3.8",
100
- "@teardown/tsconfig": "0.1.43",
105
+ "@teardown/tsconfig": "0.1.44",
101
106
  "typescript": "5.9.3"
102
107
  },
103
108
  "peerDependencies": {
@@ -108,6 +108,7 @@ export const ActiveBuildStatsSchema = Type.Object({
108
108
  platform: Type.Union([Type.Literal("IOS"), Type.Literal("ANDROID")]),
109
109
  session_count: Type.Integer({ minimum: 0 }),
110
110
  device_count: Type.Integer({ minimum: 0 }),
111
+ user_count: Type.Integer({ minimum: 0 }),
111
112
  status: Type.Optional(VersionBuildStatusSchema),
112
113
  });
113
114
  export type ActiveBuildStats = Static<typeof ActiveBuildStatsSchema>;
@@ -117,6 +118,7 @@ export const ActiveVersionStatsSchema = Type.Object({
117
118
  version_name: Type.String(),
118
119
  session_count: Type.Integer({ minimum: 0 }),
119
120
  device_count: Type.Integer({ minimum: 0 }),
121
+ user_count: Type.Integer({ minimum: 0 }),
120
122
  ios_count: Type.Integer({ minimum: 0 }),
121
123
  android_count: Type.Integer({ minimum: 0 }),
122
124
  version_status: Type.Optional(VersionBuildStatusSchema),
@@ -0,0 +1 @@
1
+ export * from "./schemas";
@@ -0,0 +1,77 @@
1
+ import { type Static, Type } from "@sinclair/typebox";
2
+
3
+ /**
4
+ * SDK Info schema
5
+ * Represents parsed SDK version header information
6
+ */
7
+ export const SdkInfoSchema = Type.Object({
8
+ sdkName: Type.Union([Type.String(), Type.Null()]),
9
+ sdkVersion: Type.Union([Type.String(), Type.Null()]),
10
+ });
11
+ export type SdkInfo = Static<typeof SdkInfoSchema>;
12
+
13
+ /**
14
+ * Identify headers schema
15
+ * Headers required for the identify endpoint
16
+ */
17
+ export const IdentifyHeadersSchema = Type.Object({
18
+ orgId: Type.String({ error: "orgId is required" }),
19
+ projectId: Type.String({ error: "projectId is required" }),
20
+ environmentSlug: Type.String({ error: "environmentSlug is required" }),
21
+ deviceId: Type.String({ error: "deviceId is required" }),
22
+ sessionId: Type.Union([Type.String(), Type.Null()]),
23
+ sdk: SdkInfoSchema,
24
+ });
25
+ export type IdentifyHeaders = Static<typeof IdentifyHeadersSchema>;
26
+
27
+ /**
28
+ * Events headers schema
29
+ * Headers required for the events endpoint
30
+ */
31
+ export const EventsHeadersSchema = Type.Object({
32
+ orgId: Type.String({ error: "orgId is required" }),
33
+ projectId: Type.String({ error: "projectId is required" }),
34
+ environmentSlug: Type.String({ error: "environmentSlug is required" }),
35
+ deviceId: Type.Union([Type.String(), Type.Null()]),
36
+ sessionId: Type.Union([Type.String(), Type.Null()]),
37
+ });
38
+ export type EventsHeaders = Static<typeof EventsHeadersSchema>;
39
+
40
+ /**
41
+ * Header error codes
42
+ */
43
+ export const HeaderErrorCodeSchema = Type.Union([
44
+ Type.Literal("MISSING_DEVICE_ID"),
45
+ Type.Literal("MISSING_ENVIRONMENT_SLUG"),
46
+ Type.Literal("MISSING_ORG_ID"),
47
+ Type.Literal("MISSING_PROJECT_ID"),
48
+ ]);
49
+ export type HeaderErrorCode = Static<typeof HeaderErrorCodeSchema>;
50
+
51
+ /**
52
+ * Parses SDK version header in format "@package/name@version" or "name@version"
53
+ * @param sdkVersionHeader - The td-sdk-version header value (e.g., "@teardown/sdk@0.0.2")
54
+ * @returns Parsed SDK name and version, or nulls if not provided/parseable
55
+ */
56
+ export function parseSdkVersionHeader(sdkVersionHeader: string | undefined): SdkInfo {
57
+ if (!sdkVersionHeader) {
58
+ return { sdkName: null, sdkVersion: null };
59
+ }
60
+
61
+ // Handle scoped packages like "@teardown/sdk@0.0.2"
62
+ // Find the last @ which separates name from version
63
+ const lastAtIndex = sdkVersionHeader.lastIndexOf("@");
64
+
65
+ // If no @ found or @ is at the start (just scoped name without version), return as-is
66
+ if (lastAtIndex <= 0) {
67
+ return { sdkName: sdkVersionHeader, sdkVersion: null };
68
+ }
69
+
70
+ const sdkName = sdkVersionHeader.slice(0, lastAtIndex);
71
+ const sdkVersion = sdkVersionHeader.slice(lastAtIndex + 1);
72
+
73
+ return {
74
+ sdkName: sdkName || null,
75
+ sdkVersion: sdkVersion || null,
76
+ };
77
+ }
@@ -139,7 +139,7 @@ export type PersonaInfo = UserInfo;
139
139
  */
140
140
  export const IdentifyRequestSchema = Type.Object({
141
141
  device: DeviceInfoSchema,
142
- persona: Type.Optional(UserInfoSchema),
142
+ user: Type.Optional(UserInfoSchema),
143
143
  });
144
144
  export type IdentifyRequest = Static<typeof IdentifyRequestSchema>;
145
145
 
@@ -3,6 +3,7 @@ export * from "./builds/schemas";
3
3
  export * from "./devices/schemas";
4
4
  export * from "./environment/schemas";
5
5
  export * from "./events/schemas";
6
+ export * from "./headers/schemas";
6
7
  export * from "./identify/schemas";
7
8
  export * from "./me/schemas";
8
9
  export * from "./orgs/schemas";