@boldvideo/bold-js 0.3.5 → 0.4.1

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/index.cjs CHANGED
@@ -72,9 +72,11 @@ __export(src_exports, {
72
72
  module.exports = __toCommonJS(src_exports);
73
73
 
74
74
  // src/lib/client.ts
75
- var import_axios = __toESM(require("axios"), 1);
75
+ var import_axios2 = __toESM(require("axios"), 1);
76
+ var import_js_cookie = __toESM(require("js-cookie"), 1);
76
77
 
77
78
  // src/lib/fetchers.ts
79
+ var import_axios = __toESM(require("axios"), 1);
78
80
  function get(client, url) {
79
81
  return __async(this, null, function* () {
80
82
  try {
@@ -84,7 +86,16 @@ function get(client, url) {
84
86
  }
85
87
  return res.data;
86
88
  } catch (error) {
87
- console.error(`Error fetching data from URL: ${url}`, error);
89
+ if (import_axios.default.isAxiosError(error)) {
90
+ console.error("fetching error details:", {
91
+ message: error.message,
92
+ code: error.code,
93
+ config: error.config,
94
+ response: error.response
95
+ });
96
+ } else {
97
+ console.error(`Error fetching data from URL: ${url}`, error);
98
+ }
88
99
  throw error;
89
100
  }
90
101
  });
@@ -202,14 +213,15 @@ function sendEvent(client, eventName, data, debug) {
202
213
  var [throttledSendEvent] = throttle(sendEvent, 5e3);
203
214
  function trackEvent(client, userId, options) {
204
215
  return (video, event) => {
216
+ var _a;
205
217
  const eventDetails = __spreadProps(__spreadValues({}, basicInfos()), {
206
218
  userId,
207
219
  videoId: video.id,
208
220
  title: video.title,
209
221
  videoDuration: video.duration,
210
- currentTime: event.target.currentTime || 0
222
+ currentTime: ((_a = event.target) == null ? void 0 : _a.currentTime) || 0
211
223
  });
212
- if (event.type == "timeupdate") {
224
+ if (event.type == "timeupdate" || event.type == "time-update") {
213
225
  throttledSendEvent(
214
226
  client,
215
227
  getEventName(event),
@@ -230,14 +242,16 @@ function trackPageView(client, userId, options) {
230
242
  sendEvent(client, "page_view", eventDetails, options.debug);
231
243
  };
232
244
  }
233
- function getEventName({ type }) {
234
- switch (type) {
245
+ function getEventName(event) {
246
+ switch (event.type) {
235
247
  case "pause":
236
248
  return "video_pause";
237
249
  case "play":
238
250
  return "video_resume";
239
251
  case "loadedmetadata":
252
+ case "loaded-metadata":
240
253
  return "video_load";
254
+ case "time-update":
241
255
  case "timeupdate":
242
256
  return "video_progress";
243
257
  default:
@@ -247,7 +261,7 @@ function getEventName({ type }) {
247
261
  function basicInfos() {
248
262
  return {
249
263
  url: location.href,
250
- domain: "localhost:3000",
264
+ domain: location.hostname,
251
265
  referrer: document.referrer || null,
252
266
  deviceWidth: window.innerWidth,
253
267
  userAgent: navigator.userAgent
@@ -255,26 +269,39 @@ function basicInfos() {
255
269
  }
256
270
 
257
271
  // src/lib/client.ts
272
+ var generateUserId = () => {
273
+ return [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
274
+ };
275
+ var getUserId = () => {
276
+ const localStorageKey = "boldvideo_user_id";
277
+ let userId = import_js_cookie.default.get(localStorageKey);
278
+ if (!userId) {
279
+ userId = generateUserId();
280
+ import_js_cookie.default.set(localStorageKey, userId, { expires: 365 });
281
+ }
282
+ return userId;
283
+ };
258
284
  function createClient(apiKey, options = { debug: false }) {
259
285
  var _a;
260
286
  if (!apiKey || typeof apiKey !== "string") {
261
287
  throw new Error("API key is missing or invalid");
262
288
  }
289
+ const userId = getUserId();
263
290
  const { debug } = options;
264
291
  const apiClientOptions = {
265
292
  baseURL: (_a = options.baseURL) != null ? _a : "https://app.boldvideo.io/api/v1/",
266
293
  headers: {
267
- Authorization: apiKey
294
+ Authorization: apiKey,
295
+ "X-User-Id": userId
268
296
  }
269
297
  };
270
298
  let apiClient;
271
299
  try {
272
- apiClient = import_axios.default.create(apiClientOptions);
300
+ apiClient = import_axios2.default.create(apiClientOptions);
273
301
  } catch (error) {
274
302
  console.error("Error creating API client", error);
275
303
  throw error;
276
304
  }
277
- const userId = [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
278
305
  return {
279
306
  settings: fetchSettings(apiClient),
280
307
  videos: {
package/dist/index.js CHANGED
@@ -39,9 +39,11 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
 
41
41
  // src/lib/client.ts
42
- import axios from "axios";
42
+ import axios2 from "axios";
43
+ import Cookies from "js-cookie";
43
44
 
44
45
  // src/lib/fetchers.ts
46
+ import axios from "axios";
45
47
  function get(client, url) {
46
48
  return __async(this, null, function* () {
47
49
  try {
@@ -51,7 +53,16 @@ function get(client, url) {
51
53
  }
52
54
  return res.data;
53
55
  } catch (error) {
54
- console.error(`Error fetching data from URL: ${url}`, error);
56
+ if (axios.isAxiosError(error)) {
57
+ console.error("fetching error details:", {
58
+ message: error.message,
59
+ code: error.code,
60
+ config: error.config,
61
+ response: error.response
62
+ });
63
+ } else {
64
+ console.error(`Error fetching data from URL: ${url}`, error);
65
+ }
55
66
  throw error;
56
67
  }
57
68
  });
@@ -169,14 +180,15 @@ function sendEvent(client, eventName, data, debug) {
169
180
  var [throttledSendEvent] = throttle(sendEvent, 5e3);
170
181
  function trackEvent(client, userId, options) {
171
182
  return (video, event) => {
183
+ var _a;
172
184
  const eventDetails = __spreadProps(__spreadValues({}, basicInfos()), {
173
185
  userId,
174
186
  videoId: video.id,
175
187
  title: video.title,
176
188
  videoDuration: video.duration,
177
- currentTime: event.target.currentTime || 0
189
+ currentTime: ((_a = event.target) == null ? void 0 : _a.currentTime) || 0
178
190
  });
179
- if (event.type == "timeupdate") {
191
+ if (event.type == "timeupdate" || event.type == "time-update") {
180
192
  throttledSendEvent(
181
193
  client,
182
194
  getEventName(event),
@@ -197,14 +209,16 @@ function trackPageView(client, userId, options) {
197
209
  sendEvent(client, "page_view", eventDetails, options.debug);
198
210
  };
199
211
  }
200
- function getEventName({ type }) {
201
- switch (type) {
212
+ function getEventName(event) {
213
+ switch (event.type) {
202
214
  case "pause":
203
215
  return "video_pause";
204
216
  case "play":
205
217
  return "video_resume";
206
218
  case "loadedmetadata":
219
+ case "loaded-metadata":
207
220
  return "video_load";
221
+ case "time-update":
208
222
  case "timeupdate":
209
223
  return "video_progress";
210
224
  default:
@@ -214,7 +228,7 @@ function getEventName({ type }) {
214
228
  function basicInfos() {
215
229
  return {
216
230
  url: location.href,
217
- domain: "localhost:3000",
231
+ domain: location.hostname,
218
232
  referrer: document.referrer || null,
219
233
  deviceWidth: window.innerWidth,
220
234
  userAgent: navigator.userAgent
@@ -222,26 +236,39 @@ function basicInfos() {
222
236
  }
223
237
 
224
238
  // src/lib/client.ts
239
+ var generateUserId = () => {
240
+ return [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
241
+ };
242
+ var getUserId = () => {
243
+ const localStorageKey = "boldvideo_user_id";
244
+ let userId = Cookies.get(localStorageKey);
245
+ if (!userId) {
246
+ userId = generateUserId();
247
+ Cookies.set(localStorageKey, userId, { expires: 365 });
248
+ }
249
+ return userId;
250
+ };
225
251
  function createClient(apiKey, options = { debug: false }) {
226
252
  var _a;
227
253
  if (!apiKey || typeof apiKey !== "string") {
228
254
  throw new Error("API key is missing or invalid");
229
255
  }
256
+ const userId = getUserId();
230
257
  const { debug } = options;
231
258
  const apiClientOptions = {
232
259
  baseURL: (_a = options.baseURL) != null ? _a : "https://app.boldvideo.io/api/v1/",
233
260
  headers: {
234
- Authorization: apiKey
261
+ Authorization: apiKey,
262
+ "X-User-Id": userId
235
263
  }
236
264
  };
237
265
  let apiClient;
238
266
  try {
239
- apiClient = axios.create(apiClientOptions);
267
+ apiClient = axios2.create(apiClientOptions);
240
268
  } catch (error) {
241
269
  console.error("Error creating API client", error);
242
270
  throw error;
243
271
  }
244
- const userId = [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
245
272
  return {
246
273
  settings: fetchSettings(apiClient),
247
274
  videos: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@boldvideo/bold-js",
3
3
  "license": "MIT",
4
- "version": "0.3.5",
4
+ "version": "0.4.1",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/src/lib/types.ts CHANGED
@@ -37,6 +37,8 @@ export type MenuItem = {
37
37
  export type Settings = {
38
38
  featured_playlists: Playlist[];
39
39
  menu_items: MenuItem[];
40
+ ai_avatar: string;
41
+ ai_name: string;
40
42
  meta_data: {
41
43
  channel_name: string;
42
44
  description: string;