@boldvideo/bold-js 0.4.0 → 0.4.2
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 +5 -29
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -29
- package/package.json +1 -1
- package/src/lib/client.ts +12 -39
- package/src/lib/fetchers.ts +1 -11
package/dist/index.cjs
CHANGED
|
@@ -72,11 +72,9 @@ __export(src_exports, {
|
|
|
72
72
|
module.exports = __toCommonJS(src_exports);
|
|
73
73
|
|
|
74
74
|
// src/lib/client.ts
|
|
75
|
-
var
|
|
76
|
-
var import_js_cookie = __toESM(require("js-cookie"), 1);
|
|
75
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
77
76
|
|
|
78
77
|
// src/lib/fetchers.ts
|
|
79
|
-
var import_axios = __toESM(require("axios"), 1);
|
|
80
78
|
function get(client, url) {
|
|
81
79
|
return __async(this, null, function* () {
|
|
82
80
|
try {
|
|
@@ -86,16 +84,7 @@ function get(client, url) {
|
|
|
86
84
|
}
|
|
87
85
|
return res.data;
|
|
88
86
|
} catch (error) {
|
|
89
|
-
|
|
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
|
-
}
|
|
87
|
+
console.error(`Error fetching data from URL: ${url}`, error);
|
|
99
88
|
throw error;
|
|
100
89
|
}
|
|
101
90
|
});
|
|
@@ -269,39 +258,26 @@ function basicInfos() {
|
|
|
269
258
|
}
|
|
270
259
|
|
|
271
260
|
// 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
|
-
};
|
|
284
261
|
function createClient(apiKey, options = { debug: false }) {
|
|
285
262
|
var _a;
|
|
286
263
|
if (!apiKey || typeof apiKey !== "string") {
|
|
287
264
|
throw new Error("API key is missing or invalid");
|
|
288
265
|
}
|
|
289
|
-
const userId = getUserId();
|
|
290
266
|
const { debug } = options;
|
|
291
267
|
const apiClientOptions = {
|
|
292
268
|
baseURL: (_a = options.baseURL) != null ? _a : "https://app.boldvideo.io/api/v1/",
|
|
293
269
|
headers: {
|
|
294
|
-
Authorization: apiKey
|
|
295
|
-
"X-User-Id": userId
|
|
270
|
+
Authorization: apiKey
|
|
296
271
|
}
|
|
297
272
|
};
|
|
298
273
|
let apiClient;
|
|
299
274
|
try {
|
|
300
|
-
apiClient =
|
|
275
|
+
apiClient = import_axios.default.create(apiClientOptions);
|
|
301
276
|
} catch (error) {
|
|
302
277
|
console.error("Error creating API client", error);
|
|
303
278
|
throw error;
|
|
304
279
|
}
|
|
280
|
+
const userId = [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
|
|
305
281
|
return {
|
|
306
282
|
settings: fetchSettings(apiClient),
|
|
307
283
|
videos: {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -39,11 +39,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// src/lib/client.ts
|
|
42
|
-
import
|
|
43
|
-
import Cookies from "js-cookie";
|
|
42
|
+
import axios from "axios";
|
|
44
43
|
|
|
45
44
|
// src/lib/fetchers.ts
|
|
46
|
-
import axios from "axios";
|
|
47
45
|
function get(client, url) {
|
|
48
46
|
return __async(this, null, function* () {
|
|
49
47
|
try {
|
|
@@ -53,16 +51,7 @@ function get(client, url) {
|
|
|
53
51
|
}
|
|
54
52
|
return res.data;
|
|
55
53
|
} catch (error) {
|
|
56
|
-
|
|
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
|
-
}
|
|
54
|
+
console.error(`Error fetching data from URL: ${url}`, error);
|
|
66
55
|
throw error;
|
|
67
56
|
}
|
|
68
57
|
});
|
|
@@ -236,39 +225,26 @@ function basicInfos() {
|
|
|
236
225
|
}
|
|
237
226
|
|
|
238
227
|
// 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
|
-
};
|
|
251
228
|
function createClient(apiKey, options = { debug: false }) {
|
|
252
229
|
var _a;
|
|
253
230
|
if (!apiKey || typeof apiKey !== "string") {
|
|
254
231
|
throw new Error("API key is missing or invalid");
|
|
255
232
|
}
|
|
256
|
-
const userId = getUserId();
|
|
257
233
|
const { debug } = options;
|
|
258
234
|
const apiClientOptions = {
|
|
259
235
|
baseURL: (_a = options.baseURL) != null ? _a : "https://app.boldvideo.io/api/v1/",
|
|
260
236
|
headers: {
|
|
261
|
-
Authorization: apiKey
|
|
262
|
-
"X-User-Id": userId
|
|
237
|
+
Authorization: apiKey
|
|
263
238
|
}
|
|
264
239
|
};
|
|
265
240
|
let apiClient;
|
|
266
241
|
try {
|
|
267
|
-
apiClient =
|
|
242
|
+
apiClient = axios.create(apiClientOptions);
|
|
268
243
|
} catch (error) {
|
|
269
244
|
console.error("Error creating API client", error);
|
|
270
245
|
throw error;
|
|
271
246
|
}
|
|
247
|
+
const userId = [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
|
|
272
248
|
return {
|
|
273
249
|
settings: fetchSettings(apiClient),
|
|
274
250
|
videos: {
|
package/package.json
CHANGED
package/src/lib/client.ts
CHANGED
|
@@ -1,54 +1,23 @@
|
|
|
1
1
|
import axios, { AxiosInstance } from "axios";
|
|
2
|
-
import Cookies from "js-cookie";
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
fetchVideos,
|
|
7
|
-
searchVideos,
|
|
8
|
-
fetchSettings,
|
|
9
|
-
fetchPlaylist,
|
|
10
|
-
fetchPlaylists,
|
|
11
|
-
} from "./fetchers";
|
|
12
|
-
import { trackEvent, trackPageView } from "./tracking";
|
|
3
|
+
import { fetchVideo, fetchVideos, searchVideos, fetchSettings, fetchPlaylist, fetchPlaylists } from './fetchers'
|
|
4
|
+
import { trackEvent, trackPageView } from './tracking'
|
|
13
5
|
|
|
14
6
|
type ClientOptions = {
|
|
15
|
-
baseURL?: string
|
|
16
|
-
debug: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const generateUserId = (): string => {
|
|
20
|
-
return [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const getUserId = (): string => {
|
|
24
|
-
const localStorageKey = "boldvideo_user_id";
|
|
25
|
-
|
|
26
|
-
let userId = Cookies.get(localStorageKey);
|
|
27
|
-
|
|
28
|
-
if (!userId) {
|
|
29
|
-
userId = generateUserId();
|
|
30
|
-
Cookies.set(localStorageKey, userId, { expires: 365 }); // 1-year expiration
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return userId;
|
|
34
|
-
};
|
|
7
|
+
baseURL?: string
|
|
8
|
+
debug: boolean
|
|
9
|
+
}
|
|
35
10
|
|
|
36
|
-
function createClient(
|
|
37
|
-
apiKey
|
|
38
|
-
|
|
39
|
-
) {
|
|
40
|
-
if (!apiKey || typeof apiKey !== "string") {
|
|
41
|
-
throw new Error("API key is missing or invalid");
|
|
11
|
+
function createClient(apiKey: string, options: ClientOptions = {debug: false}) {
|
|
12
|
+
if (!apiKey || typeof apiKey !== 'string') {
|
|
13
|
+
throw new Error('API key is missing or invalid');
|
|
42
14
|
}
|
|
43
15
|
|
|
44
|
-
const userId = getUserId();
|
|
45
|
-
|
|
46
16
|
const { debug } = options;
|
|
47
17
|
const apiClientOptions = {
|
|
48
18
|
baseURL: options.baseURL ?? "https://app.boldvideo.io/api/v1/",
|
|
49
19
|
headers: {
|
|
50
20
|
Authorization: apiKey,
|
|
51
|
-
"X-User-Id": userId,
|
|
52
21
|
},
|
|
53
22
|
};
|
|
54
23
|
|
|
@@ -61,6 +30,10 @@ function createClient(
|
|
|
61
30
|
throw error;
|
|
62
31
|
}
|
|
63
32
|
|
|
33
|
+
const userId = [...Array(30)]
|
|
34
|
+
.map(() => Math.random().toString(36)[2])
|
|
35
|
+
.join("");
|
|
36
|
+
|
|
64
37
|
return {
|
|
65
38
|
settings: fetchSettings(apiClient),
|
|
66
39
|
videos: {
|
package/src/lib/fetchers.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { Video, Playlist, Settings } from "./types";
|
|
3
2
|
import { AxiosInstance } from "axios";
|
|
4
3
|
|
|
@@ -19,16 +18,7 @@ async function get<TResponse>(
|
|
|
19
18
|
}
|
|
20
19
|
return res.data as TResponse;
|
|
21
20
|
} catch (error) {
|
|
22
|
-
|
|
23
|
-
console.error("fetching error details:", {
|
|
24
|
-
message: error.message,
|
|
25
|
-
code: error.code,
|
|
26
|
-
config: error.config,
|
|
27
|
-
response: error.response,
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
console.error(`Error fetching data from URL: ${url}`, error);
|
|
31
|
-
}
|
|
21
|
+
console.error(`Error fetching data from URL: ${url}`, error);
|
|
32
22
|
throw error;
|
|
33
23
|
}
|
|
34
24
|
}
|