clarity-analytics-sdk 1.0.4 → 1.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +43 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-analytics-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A lightweight JavaScript SDK for tracking events and analytics with Clarity Analytics",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -17,8 +17,8 @@
17
17
  }
18
18
  // Configuration
19
19
  this.config = {
20
- apiUrl: 'http://10.40.9.62:9030/api/v1/events/publish-event',
21
- fetchUserIdUrl: 'http://10.40.9.62:9030/api/v1/projects?id=',
20
+ apiUrl: 'https://apps.helo.ai/api/v1/sdk/clarity/events/publish-event',
21
+ fetchUserIdUrl: 'https://apps.helo.ai/api/v1/sdk/clarity/projects?id=',
22
22
  projectId: config.projectId,
23
23
  projectName: config.projectName || '',
24
24
  apiKey: config.apiKey || null,
@@ -138,7 +138,8 @@
138
138
  * @param {Object} properties - Event properties
139
139
  * @param {Object} options - Additional options
140
140
  */
141
- async track (eventName, properties = {}, options = {}) { // Wait for SDK to be initialized
141
+ async track (eventName, properties = {}, options = {}) {
142
+ // Wait for SDK to be initialized
142
143
  if (!this._isInitialized) {
143
144
  try {
144
145
  await this._initializationPromise
@@ -156,6 +157,44 @@
156
157
  throw new Error('Event name is required')
157
158
  }
158
159
 
160
+ // Validate event name length
161
+ if (typeof eventName !== 'string') {
162
+ throw new Error('Event name must be a string')
163
+ }
164
+
165
+ const eventNameLength = eventName.trim().length
166
+ if (eventNameLength < 5 || eventNameLength > 50) {
167
+ throw new Error('Event name must be between 5 and 50 characters')
168
+ }
169
+
170
+ // Validate properties is an object
171
+ if (properties !== null && (typeof properties !== 'object' || Array.isArray(properties))) {
172
+ throw new Error('Properties must be an object')
173
+ }
174
+
175
+ // Validate properties size (max 16KB)
176
+ if (properties && typeof properties === 'object') {
177
+ const propertiesJson = JSON.stringify(properties)
178
+ let propertiesSize
179
+
180
+ // Calculate size in bytes (works in both browser and Node.js)
181
+ if (typeof Blob !== 'undefined') {
182
+ propertiesSize = new Blob([propertiesJson]).size
183
+ } else if (typeof TextEncoder !== 'undefined') {
184
+ propertiesSize = new TextEncoder().encode(propertiesJson).length
185
+ } else if (typeof Buffer !== 'undefined') {
186
+ propertiesSize = Buffer.byteLength(propertiesJson, 'utf8')
187
+ } else {
188
+ // Fallback: approximate size using string length (UTF-8)
189
+ propertiesSize = propertiesJson.length
190
+ }
191
+
192
+ const maxSize = 16 * 1024 // 16KB in bytes
193
+ if (propertiesSize > maxSize) {
194
+ throw new Error(`Properties object size (${propertiesSize} bytes) exceeds maximum allowed size of 16KB`)
195
+ }
196
+ }
197
+
159
198
  const eventData = this._buildEventPayload({
160
199
  eventType: options.eventType || 'custom',
161
200
  eventName,
@@ -190,7 +229,7 @@
190
229
  event_id: eventId,
191
230
  request_id: requestId,
192
231
  event_name: data.eventName || 'Unnamed Event',
193
- timestamp: timestamp,
232
+ timestamp,
194
233
 
195
234
  // User and session
196
235
  user_id: finalUserId,