@boldvideo/bold-js 0.4.2 → 0.5.0

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.
@@ -0,0 +1,11 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ open-pull-requests-limit: 10
8
+ groups:
9
+ dependencies:
10
+ patterns:
11
+ - "*"
@@ -0,0 +1,51 @@
1
+ name: Changeset Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ concurrency: ${{ github.workflow }}-${{ github.ref }}
9
+
10
+ permissions:
11
+ contents: write
12
+ pull-requests: write
13
+ id-token: write # For npm provenance
14
+
15
+ jobs:
16
+ release:
17
+ name: Release
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout code
21
+ uses: actions/checkout@v4
22
+ with:
23
+ fetch-depth: 0
24
+
25
+ - name: Install pnpm
26
+ uses: pnpm/action-setup@v2
27
+ with:
28
+ version: 10.12.2
29
+
30
+ - name: Setup Node.js
31
+ uses: actions/setup-node@v4
32
+ with:
33
+ node-version: 20.x
34
+ cache: 'pnpm'
35
+ registry-url: 'https://registry.npmjs.org'
36
+
37
+ - name: Install dependencies
38
+ run: pnpm install --frozen-lockfile
39
+
40
+ - name: Create Release Pull Request or Publish to npm
41
+ id: changesets
42
+ uses: changesets/action@v1
43
+ with:
44
+ title: "chore: release package"
45
+ commit: "chore: release package"
46
+ publish: pnpm changeset publish
47
+ createGithubReleases: true
48
+ env:
49
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
51
+ NPM_CONFIG_PROVENANCE: true
@@ -0,0 +1,88 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ name: Test on Node ${{ matrix.node-version }}
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [16.x, 18.x, 20.x]
17
+
18
+ steps:
19
+ - name: Checkout code
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Install pnpm
23
+ uses: pnpm/action-setup@v2
24
+ with:
25
+ version: 10.12.2
26
+
27
+ - name: Use Node.js ${{ matrix.node-version }}
28
+ uses: actions/setup-node@v4
29
+ with:
30
+ node-version: ${{ matrix.node-version }}
31
+ cache: 'pnpm'
32
+
33
+ - name: Install dependencies
34
+ run: pnpm install --frozen-lockfile
35
+
36
+ - name: Run linter
37
+ run: pnpm run lint
38
+
39
+ - name: Build package
40
+ run: pnpm run build
41
+
42
+ - name: Check package exports
43
+ run: |
44
+ node -e "const pkg = require('./dist/index.cjs'); console.log('CJS import successful');"
45
+ node -e "import('./dist/index.js').then(() => console.log('ESM import successful'));"
46
+
47
+ - name: Check TypeScript declarations
48
+ run: |
49
+ if [ ! -f "dist/index.d.ts" ]; then
50
+ echo "TypeScript declarations not found!"
51
+ exit 1
52
+ fi
53
+
54
+ size-check:
55
+ name: Bundle Size Check
56
+ runs-on: ubuntu-latest
57
+
58
+ steps:
59
+ - name: Checkout code
60
+ uses: actions/checkout@v4
61
+
62
+ - name: Install pnpm
63
+ uses: pnpm/action-setup@v2
64
+ with:
65
+ version: 10.12.2
66
+
67
+ - name: Use Node.js
68
+ uses: actions/setup-node@v4
69
+ with:
70
+ node-version: 20.x
71
+ cache: 'pnpm'
72
+
73
+ - name: Install dependencies
74
+ run: pnpm install --frozen-lockfile
75
+
76
+ - name: Build package
77
+ run: pnpm run build
78
+
79
+ - name: Check bundle size
80
+ run: |
81
+ echo "Bundle sizes:"
82
+ ls -lh dist/
83
+
84
+ # Warn if bundle exceeds 50KB (adjust threshold as needed)
85
+ size=$(stat -c%s dist/index.js 2>/dev/null || stat -f%z dist/index.js)
86
+ if [ $size -gt 51200 ]; then
87
+ echo "⚠️ Warning: Bundle size exceeds 50KB"
88
+ fi
@@ -0,0 +1,83 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write # For npm provenance
11
+
12
+ jobs:
13
+ release:
14
+ name: Release to npm
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout code
19
+ uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0 # Needed for changelog generation
22
+
23
+ - name: Install pnpm
24
+ uses: pnpm/action-setup@v2
25
+ with:
26
+ version: 10.12.2
27
+
28
+ - name: Setup Node.js
29
+ uses: actions/setup-node@v4
30
+ with:
31
+ node-version: 20.x
32
+ cache: 'pnpm'
33
+ registry-url: 'https://registry.npmjs.org'
34
+
35
+ - name: Install dependencies
36
+ run: pnpm install --frozen-lockfile
37
+
38
+ - name: Run CI checks
39
+ run: |
40
+ pnpm run lint
41
+ pnpm run build
42
+
43
+ - name: Verify version matches tag
44
+ run: |
45
+ PACKAGE_VERSION="v$(node -p "require('./package.json').version")"
46
+ if [ "$PACKAGE_VERSION" != "${{ github.ref_name }}" ]; then
47
+ echo "Error: Package version ($PACKAGE_VERSION) doesn't match tag (${{ github.ref_name }})"
48
+ exit 1
49
+ fi
50
+
51
+ - name: Check npm access
52
+ run: npm whoami
53
+ env:
54
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
55
+
56
+ - name: Publish to npm with provenance
57
+ run: pnpm publish --access public --no-git-checks
58
+ env:
59
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
60
+ NPM_CONFIG_PROVENANCE: true
61
+
62
+ - name: Create GitHub Release
63
+ uses: softprops/action-gh-release@v1
64
+ with:
65
+ generate_release_notes: true
66
+ body: |
67
+ ## What's Changed
68
+
69
+ See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details.
70
+
71
+ ## Installation
72
+
73
+ ```bash
74
+ npm install @boldvideo/bold-js@${{ github.ref_name }}
75
+ ```
76
+
77
+ ```bash
78
+ pnpm add @boldvideo/bold-js@${{ github.ref_name }}
79
+ ```
80
+
81
+ ```bash
82
+ yarn add @boldvideo/bold-js@${{ github.ref_name }}
83
+ ```
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @boldvideo/bold-js
2
+
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 111cb8f: feat: add ai_greeting property to Settings type
8
+
9
+ Added optional ai_greeting property to the Settings type to allow customization of the AI assistant's greeting message. This maintains backward compatibility while enabling users to override the default greeting.
10
+
11
+ Resolves #2
12
+
13
+ ## 0.4.3
14
+
15
+ ### Patch Changes
16
+
17
+ - New `has_ai` field to settings
package/CLAUDE.md ADDED
@@ -0,0 +1,76 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ This is the Bold JavaScript SDK (`@boldvideo/bold-js`) - a TypeScript client library for interacting with the Bold Video API. The SDK provides methods for fetching videos, playlists, channel settings, and tracking analytics events.
8
+
9
+ ## Common Development Commands
10
+
11
+ ```bash
12
+ # Install dependencies
13
+ pnpm install
14
+
15
+ # Build the project (outputs to dist/)
16
+ pnpm run build
17
+
18
+ # Run type checking/linting
19
+ pnpm run lint
20
+
21
+ # Publish new version (uses changesets)
22
+ pnpm changeset
23
+ pnpm changeset version
24
+ pnpm changeset publish
25
+ ```
26
+
27
+ ## Architecture & Key Components
28
+
29
+ ### Client Structure
30
+ The SDK uses a factory pattern where `createClient(apiKey)` returns an object with namespaced methods:
31
+ - `bold.settings()` - Fetch channel settings
32
+ - `bold.videos.list()` / `.get(id)` / `.search(query)` - Video operations
33
+ - `bold.playlists.list()` / `.get(id)` - Playlist operations
34
+ - `bold.trackEvent()` / `bold.trackPageView()` - Analytics tracking
35
+
36
+ ### Core Files
37
+ - `/src/index.ts` - Main entry point, exports `createClient` and all types
38
+ - `/src/lib/client.ts` - Client factory that creates the Bold instance with API key auth
39
+ - `/src/lib/fetchers.ts` - Individual API endpoint implementations
40
+ - `/src/lib/tracking.ts` - Analytics event tracking with throttling
41
+ - `/src/lib/types.ts` - TypeScript interfaces for Video, Playlist, Settings, etc.
42
+ - `/src/util/throttle.ts` - Throttling utility for rate-limiting event tracking
43
+
44
+ ### Build Configuration
45
+ - Uses `tsup` for building TypeScript to both ESM and CommonJS formats
46
+ - Outputs to `/dist/` with type declarations
47
+ - TypeScript strict mode enabled
48
+ - Target: ES2016
49
+
50
+ ## Development Workflow
51
+
52
+ 1. The project uses GitHub Actions for CI/CD:
53
+ - All branches run lint and build checks
54
+ - Main branch can publish to npm using changesets
55
+
56
+ 2. When making changes:
57
+ - Ensure TypeScript types are properly defined
58
+ - Run `pnpm run lint` before committing
59
+ - The SDK supports both ESM and CommonJS consumers
60
+
61
+ 3. API Integration:
62
+ - Default base URL: `https://app.boldvideo.io/api/v1/`
63
+ - Authentication via API key in Authorization header
64
+ - All API methods return promises
65
+
66
+ 4. Analytics Tracking:
67
+ - Events are throttled to prevent API rate limiting
68
+ - User IDs are auto-generated for each client instance
69
+ - Debug mode available for development
70
+
71
+ ## Important Notes
72
+
73
+ - No test framework is currently configured
74
+ - The SDK is designed to be lightweight with minimal dependencies (only axios)
75
+ - All API responses follow the type definitions in `/src/lib/types.ts`
76
+ - The tracking system includes automatic throttling to handle high-frequency events like video progress updates
@@ -0,0 +1,103 @@
1
+ # Contributing to @boldvideo/bold-js
2
+
3
+ First off, thank you for considering contributing to Bold JS! It's people like you that make Bold JS such a great tool.
4
+
5
+ ## Code of Conduct
6
+
7
+ By participating in this project, you are expected to uphold our Code of Conduct:
8
+ - Be respectful and inclusive
9
+ - Welcome newcomers and help them get started
10
+ - Focus on what is best for the community
11
+ - Show empathy towards other community members
12
+
13
+ ## How Can I Contribute?
14
+
15
+ ### Reporting Bugs
16
+
17
+ Before creating bug reports, please check existing issues to avoid duplicates. When you create a bug report, include as many details as possible:
18
+
19
+ - Use a clear and descriptive title
20
+ - Describe the exact steps to reproduce the problem
21
+ - Provide specific examples to demonstrate the steps
22
+ - Describe the behavior you observed and what behavior you expected
23
+ - Include your environment details (Node.js version, OS, etc.)
24
+
25
+ ### Suggesting Enhancements
26
+
27
+ Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion:
28
+
29
+ - Use a clear and descriptive title
30
+ - Provide a step-by-step description of the suggested enhancement
31
+ - Provide specific examples to demonstrate the use case
32
+ - Explain why this enhancement would be useful to most users
33
+
34
+ ### Pull Requests
35
+
36
+ 1. Fork the repo and create your branch from `main`
37
+ 2. If you've added code that should be tested, add tests
38
+ 3. Ensure the test suite passes (`pnpm run lint && pnpm run build`)
39
+ 4. Make sure your code follows the existing code style
40
+ 5. Create a changeset for your changes:
41
+ ```bash
42
+ pnpm changeset
43
+ ```
44
+ 6. Push your branch and submit a pull request
45
+
46
+ ## Development Setup
47
+
48
+ 1. Fork and clone the repo:
49
+ ```bash
50
+ git clone https://github.com/YOUR_USERNAME/bold-js.git
51
+ cd bold-js
52
+ ```
53
+
54
+ 2. Install dependencies:
55
+ ```bash
56
+ pnpm install
57
+ ```
58
+
59
+ 3. Make your changes and run the build:
60
+ ```bash
61
+ pnpm run build
62
+ pnpm run lint
63
+ ```
64
+
65
+ ## Changesets
66
+
67
+ We use [changesets](https://github.com/changesets/changesets) to manage versions and changelogs. When you make a change:
68
+
69
+ 1. Run `pnpm changeset`
70
+ 2. Select the type of change (patch/minor/major)
71
+ 3. Describe your changes for the changelog
72
+ 4. Commit the generated changeset file along with your changes
73
+
74
+ ## Style Guide
75
+
76
+ - Use TypeScript for all new code
77
+ - Follow the existing code style (enforced by TypeScript compiler)
78
+ - Write clear, self-documenting code
79
+ - Add comments only when necessary to explain "why" not "what"
80
+ - Keep functions small and focused
81
+ - Use meaningful variable and function names
82
+
83
+ ## Commit Messages
84
+
85
+ - Use the present tense ("Add feature" not "Added feature")
86
+ - Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
87
+ - Limit the first line to 72 characters or less
88
+ - Reference issues and pull requests liberally after the first line
89
+
90
+ ## Release Process (Maintainers Only)
91
+
92
+ Releases are automated through GitHub Actions:
93
+
94
+ 1. When PRs with changesets are merged to main, a "Version Packages" PR is created
95
+ 2. Review and merge the version PR to trigger a release
96
+ 3. The workflow will automatically:
97
+ - Publish to npm
98
+ - Create a GitHub release
99
+ - Update the changelog
100
+
101
+ ## Questions?
102
+
103
+ Feel free to open an issue with your question or reach out to the maintainers directly.
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  <div align="center">
2
- <a href="https://wearebold.af?utm_source=github.com&utm_medium=readme&utm_campaign=bold-js" align="center">
3
- <img src="https://wearebold.af/bold-js-github-header.svg" alt="Bold Logo">
2
+ <a href="https://boldvideo.com?utm_source=github.com&utm_medium=readme&utm_campaign=bold-js" align="center">
3
+ <img src="https://boldvideo.com/bold-js-github-header.svg" alt="Bold Logo">
4
4
  </a>
5
5
  <h1 align="center rainbow">@boldvideo/bold-js</h1>
6
6
  <p align="center">
7
- The JavaScript SDK for interacting with the <a href="http://wearebold.af?utm_source=github.com&utm_medium=readme&utm_campaign=bold-js" target="_blank">Bold API</a>, to power your own business video platform.
7
+ The JavaScript SDK for interacting with the <a href="https://boldvideo.com?utm_source=github.com&utm_medium=readme&utm_campaign=bold-js" target="_blank">Bold API</a>, to power your own business video platform.
8
8
  </p>
9
9
  </div>
10
10
 
@@ -58,6 +58,29 @@ const playlists = await bold.playlists.list();
58
58
 
59
59
  - **[Bold API Documentation](https://docs.boldvideo.io/docs/api)**
60
60
 
61
+ ## Contributing
62
+
63
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this project.
64
+
65
+ ## Security
66
+
67
+ ### For Maintainers
68
+
69
+ The automated release process is secure by default:
70
+ - NPM_TOKEN is only accessible to workflows on the main branch
71
+ - External contributors' PRs cannot access secrets
72
+ - Only maintainers with write access can merge to main
73
+ - The changeset-release workflow only runs after merge to main
74
+
75
+ ### Recommended Branch Protection
76
+
77
+ For additional security, enable these branch protection rules for `main`:
78
+ - Require pull request reviews before merging
79
+ - Dismiss stale pull request approvals when new commits are pushed
80
+ - Require status checks to pass (CI workflow)
81
+ - Require branches to be up to date before merging
82
+ - Include administrators in these restrictions
83
+
61
84
  ## More Resources
62
85
 
63
86
  ### Support
package/SECURITY.md ADDED
@@ -0,0 +1,66 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ We release patches for security vulnerabilities for the following versions:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 0.x.x | :white_check_mark: |
10
+
11
+ ## Reporting a Vulnerability
12
+
13
+ If you discover a security vulnerability within Bold JS, please send an email to security@boldvideo.com. All security vulnerabilities will be promptly addressed.
14
+
15
+ Please do not report security vulnerabilities through public GitHub issues.
16
+
17
+ When reporting a vulnerability, please include:
18
+
19
+ - The version of @boldvideo/bold-js you're using
20
+ - A description of the vulnerability
21
+ - Steps to reproduce the issue
22
+ - Potential impact of the vulnerability
23
+ - Any suggested fixes (if applicable)
24
+
25
+ ## Security Measures
26
+
27
+ ### NPM Publishing
28
+
29
+ - Releases are automated through GitHub Actions
30
+ - NPM tokens are stored as encrypted GitHub secrets
31
+ - Only maintainers with write access can trigger releases
32
+ - All releases include npm provenance for supply chain security
33
+
34
+ ### Dependencies
35
+
36
+ - Dependencies are regularly updated via Dependabot
37
+ - Security advisories are monitored through GitHub's security features
38
+ - Minimal dependencies to reduce attack surface (only axios as runtime dependency)
39
+
40
+ ### Code Review
41
+
42
+ - All changes require pull request reviews
43
+ - CI checks must pass before merging
44
+ - Type safety enforced through TypeScript
45
+
46
+ ## Best Practices for Users
47
+
48
+ When using @boldvideo/bold-js:
49
+
50
+ 1. **Keep your API keys secure**
51
+ - Never commit API keys to version control
52
+ - Use environment variables for API keys
53
+ - Rotate keys regularly
54
+
55
+ 2. **Stay updated**
56
+ - Regularly update to the latest version
57
+ - Monitor security advisories
58
+ - Review the changelog for security updates
59
+
60
+ 3. **Validate input**
61
+ - Always validate and sanitize user input before passing to the SDK
62
+ - Be cautious with data from external sources
63
+
64
+ ## Acknowledgments
65
+
66
+ We appreciate responsible disclosure of security vulnerabilities and will acknowledge researchers who report issues (with their permission).
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@boldvideo/bold-js",
3
3
  "license": "MIT",
4
- "version": "0.4.2",
4
+ "version": "0.5.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
- "scripts": {
10
- "build": "tsup src/index.ts --format cjs,esm --dts",
11
- "lint": "tsc"
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/boldvideo/bold-js"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
12
15
  },
13
16
  "devDependencies": {
14
17
  "@changesets/cli": "^2.26.0",
@@ -17,5 +20,9 @@
17
20
  },
18
21
  "dependencies": {
19
22
  "axios": "^1.3.6"
23
+ },
24
+ "scripts": {
25
+ "build": "tsup src/index.ts --format cjs,esm --dts",
26
+ "lint": "tsc"
20
27
  }
21
- }
28
+ }
package/src/lib/types.ts CHANGED
@@ -39,6 +39,8 @@ export type Settings = {
39
39
  menu_items: MenuItem[];
40
40
  ai_avatar: string;
41
41
  ai_name: string;
42
+ ai_greeting?: string;
43
+ has_ai: boolean;
42
44
  meta_data: {
43
45
  channel_name: string;
44
46
  description: string;
package/dist/index.cjs DELETED
@@ -1,299 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __export = (target, all) => {
26
- for (var name in all)
27
- __defProp(target, name, { get: all[name], enumerable: true });
28
- };
29
- var __copyProps = (to, from, except, desc) => {
30
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
36
- };
37
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
- // If the importer is in node compatibility mode or this is not an ESM
39
- // file that has been converted to a CommonJS file using a Babel-
40
- // compatible transform (i.e. "__esModule" has not been set), then set
41
- // "default" to the CommonJS "module.exports" for node compatibility.
42
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
- mod
44
- ));
45
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
- var __async = (__this, __arguments, generator) => {
47
- return new Promise((resolve, reject) => {
48
- var fulfilled = (value) => {
49
- try {
50
- step(generator.next(value));
51
- } catch (e) {
52
- reject(e);
53
- }
54
- };
55
- var rejected = (value) => {
56
- try {
57
- step(generator.throw(value));
58
- } catch (e) {
59
- reject(e);
60
- }
61
- };
62
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
- step((generator = generator.apply(__this, __arguments)).next());
64
- });
65
- };
66
-
67
- // src/index.ts
68
- var src_exports = {};
69
- __export(src_exports, {
70
- createClient: () => createClient
71
- });
72
- module.exports = __toCommonJS(src_exports);
73
-
74
- // src/lib/client.ts
75
- var import_axios = __toESM(require("axios"), 1);
76
-
77
- // src/lib/fetchers.ts
78
- function get(client, url) {
79
- return __async(this, null, function* () {
80
- try {
81
- const res = yield client.get(url);
82
- if (res.status !== 200) {
83
- throw new Error(`Unexpected response status: ${res.status}`);
84
- }
85
- return res.data;
86
- } catch (error) {
87
- console.error(`Error fetching data from URL: ${url}`, error);
88
- throw error;
89
- }
90
- });
91
- }
92
- function fetchSettings(client) {
93
- return (videoLimit = 12) => __async(this, null, function* () {
94
- try {
95
- return yield get(
96
- client,
97
- `settings?limit=${videoLimit}`
98
- );
99
- } catch (error) {
100
- console.error(`Error fetching settings with limit: ${videoLimit}`, error);
101
- throw error;
102
- }
103
- });
104
- }
105
- function fetchVideos(client) {
106
- return (videoLimit = 12) => __async(this, null, function* () {
107
- try {
108
- return yield get(
109
- client,
110
- `videos/latest?limit=${videoLimit}`
111
- );
112
- } catch (error) {
113
- console.error(`Error fetching videos with limit: ${videoLimit}`, error);
114
- throw error;
115
- }
116
- });
117
- }
118
- function searchVideos(client) {
119
- return (term) => __async(this, null, function* () {
120
- try {
121
- return yield get(client, `videos?query=${term}`);
122
- } catch (error) {
123
- console.error(`Error searching for videos with term: ${term}`, error);
124
- throw error;
125
- }
126
- });
127
- }
128
- function fetchVideo(client) {
129
- return (id) => __async(this, null, function* () {
130
- try {
131
- return yield get(client, `videos/${id}`);
132
- } catch (error) {
133
- console.error(`Error fetching video with ID: ${id}`, error);
134
- throw error;
135
- }
136
- });
137
- }
138
- function fetchPlaylists(client) {
139
- return () => __async(this, null, function* () {
140
- try {
141
- return yield get(client, "playlists");
142
- } catch (error) {
143
- console.error("Error fetching playlists", error);
144
- throw error;
145
- }
146
- });
147
- }
148
- function fetchPlaylist(client) {
149
- return (id) => __async(this, null, function* () {
150
- try {
151
- return yield get(client, `playlists/${id}`);
152
- } catch (error) {
153
- console.error(`Error fetching playlist with ID: ${id}`, error);
154
- throw error;
155
- }
156
- });
157
- }
158
-
159
- // src/util/throttle.ts
160
- var throttle = (fn, delay) => {
161
- let wait = false;
162
- let timeout;
163
- let cancelled = false;
164
- return [
165
- (...args) => {
166
- if (cancelled)
167
- return void 0;
168
- if (wait)
169
- return void 0;
170
- const val = fn(...args);
171
- wait = true;
172
- timeout = window.setTimeout(() => {
173
- wait = false;
174
- }, delay);
175
- return val;
176
- },
177
- () => {
178
- cancelled = true;
179
- clearTimeout(timeout);
180
- }
181
- ];
182
- };
183
-
184
- // src/lib/tracking.ts
185
- function sendEvent(client, eventName, data, debug) {
186
- const payload = {
187
- n: eventName,
188
- u: data.url,
189
- usr: data.userId,
190
- d: data.domain,
191
- ua: data.userAgent,
192
- w: data.deviceWidth,
193
- vid: (data == null ? void 0 : data.videoId) || void 0,
194
- vt: data.title,
195
- vdur: (data == null ? void 0 : data.videoDuration) || void 0,
196
- time: (data == null ? void 0 : data.currentTime) || void 0
197
- };
198
- if (debug)
199
- console.log(`Bold SDK - Logging event '${eventName}'`, payload);
200
- client.post("/event", payload);
201
- }
202
- var [throttledSendEvent] = throttle(sendEvent, 5e3);
203
- function trackEvent(client, userId, options) {
204
- return (video, event) => {
205
- var _a;
206
- const eventDetails = __spreadProps(__spreadValues({}, basicInfos()), {
207
- userId,
208
- videoId: video.id,
209
- title: video.title,
210
- videoDuration: video.duration,
211
- currentTime: ((_a = event.target) == null ? void 0 : _a.currentTime) || 0
212
- });
213
- if (event.type == "timeupdate" || event.type == "time-update") {
214
- throttledSendEvent(
215
- client,
216
- getEventName(event),
217
- eventDetails,
218
- options.debug
219
- );
220
- } else {
221
- sendEvent(client, getEventName(event), eventDetails, options.debug);
222
- }
223
- };
224
- }
225
- function trackPageView(client, userId, options) {
226
- return (title) => {
227
- const eventDetails = __spreadProps(__spreadValues({}, basicInfos()), {
228
- userId,
229
- title
230
- });
231
- sendEvent(client, "page_view", eventDetails, options.debug);
232
- };
233
- }
234
- function getEventName(event) {
235
- switch (event.type) {
236
- case "pause":
237
- return "video_pause";
238
- case "play":
239
- return "video_resume";
240
- case "loadedmetadata":
241
- case "loaded-metadata":
242
- return "video_load";
243
- case "time-update":
244
- case "timeupdate":
245
- return "video_progress";
246
- default:
247
- return "unknown_event";
248
- }
249
- }
250
- function basicInfos() {
251
- return {
252
- url: location.href,
253
- domain: location.hostname,
254
- referrer: document.referrer || null,
255
- deviceWidth: window.innerWidth,
256
- userAgent: navigator.userAgent
257
- };
258
- }
259
-
260
- // src/lib/client.ts
261
- function createClient(apiKey, options = { debug: false }) {
262
- var _a;
263
- if (!apiKey || typeof apiKey !== "string") {
264
- throw new Error("API key is missing or invalid");
265
- }
266
- const { debug } = options;
267
- const apiClientOptions = {
268
- baseURL: (_a = options.baseURL) != null ? _a : "https://app.boldvideo.io/api/v1/",
269
- headers: {
270
- Authorization: apiKey
271
- }
272
- };
273
- let apiClient;
274
- try {
275
- apiClient = import_axios.default.create(apiClientOptions);
276
- } catch (error) {
277
- console.error("Error creating API client", error);
278
- throw error;
279
- }
280
- const userId = [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
281
- return {
282
- settings: fetchSettings(apiClient),
283
- videos: {
284
- list: fetchVideos(apiClient),
285
- get: fetchVideo(apiClient),
286
- search: searchVideos(apiClient)
287
- },
288
- playlists: {
289
- list: fetchPlaylists(apiClient),
290
- get: fetchPlaylist(apiClient)
291
- },
292
- trackEvent: trackEvent(apiClient, userId, { debug }),
293
- trackPageView: trackPageView(apiClient, userId, { debug })
294
- };
295
- }
296
- // Annotate the CommonJS export names for ESM import in node:
297
- 0 && (module.exports = {
298
- createClient
299
- });
package/dist/index.d.ts DELETED
@@ -1,80 +0,0 @@
1
- type Video = {
2
- captions: string;
3
- captions_label: string;
4
- captions_lang: string;
5
- description: string | null;
6
- duration: number;
7
- id: string;
8
- imported_from: string | null;
9
- legacy_video_url: null | null;
10
- meta_data: [];
11
- playback_id: string;
12
- published_at: string;
13
- stream_url: string;
14
- teaser: string | null;
15
- thumbnail: string;
16
- title: string;
17
- transcription: string;
18
- type: string;
19
- };
20
- type Playlist = {
21
- description?: string;
22
- id: string;
23
- is_private: boolean;
24
- title: string;
25
- type: string;
26
- videos: Video[];
27
- };
28
- type MenuItem = {
29
- icon: string;
30
- is_ext: boolean;
31
- label: string;
32
- url: string;
33
- };
34
- type Settings = {
35
- featured_playlists: Playlist[];
36
- menu_items: MenuItem[];
37
- ai_avatar: string;
38
- ai_name: string;
39
- meta_data: {
40
- channel_name: string;
41
- description: string;
42
- image: string;
43
- no_seo: boolean;
44
- title: string;
45
- title_suffix: string;
46
- };
47
- };
48
-
49
- type ClientOptions = {
50
- baseURL?: string;
51
- debug: boolean;
52
- };
53
- declare function createClient(apiKey: string, options?: ClientOptions): {
54
- settings: (videoLimit?: number) => Promise<{
55
- data: Settings;
56
- }>;
57
- videos: {
58
- list: (videoLimit?: number) => Promise<{
59
- data: Video[];
60
- }>;
61
- get: (id: string) => Promise<{
62
- data: Video;
63
- }>;
64
- search: (term: string) => Promise<{
65
- data: Video[];
66
- }>;
67
- };
68
- playlists: {
69
- list: () => Promise<{
70
- data: Playlist[];
71
- }>;
72
- get: (id: string) => Promise<{
73
- data: Playlist;
74
- }>;
75
- };
76
- trackEvent: (video: any, event: Event) => void;
77
- trackPageView: (title: string) => void;
78
- };
79
-
80
- export { MenuItem, Playlist, Settings, Video, createClient };
package/dist/index.js DELETED
@@ -1,265 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
-
41
- // src/lib/client.ts
42
- import axios from "axios";
43
-
44
- // src/lib/fetchers.ts
45
- function get(client, url) {
46
- return __async(this, null, function* () {
47
- try {
48
- const res = yield client.get(url);
49
- if (res.status !== 200) {
50
- throw new Error(`Unexpected response status: ${res.status}`);
51
- }
52
- return res.data;
53
- } catch (error) {
54
- console.error(`Error fetching data from URL: ${url}`, error);
55
- throw error;
56
- }
57
- });
58
- }
59
- function fetchSettings(client) {
60
- return (videoLimit = 12) => __async(this, null, function* () {
61
- try {
62
- return yield get(
63
- client,
64
- `settings?limit=${videoLimit}`
65
- );
66
- } catch (error) {
67
- console.error(`Error fetching settings with limit: ${videoLimit}`, error);
68
- throw error;
69
- }
70
- });
71
- }
72
- function fetchVideos(client) {
73
- return (videoLimit = 12) => __async(this, null, function* () {
74
- try {
75
- return yield get(
76
- client,
77
- `videos/latest?limit=${videoLimit}`
78
- );
79
- } catch (error) {
80
- console.error(`Error fetching videos with limit: ${videoLimit}`, error);
81
- throw error;
82
- }
83
- });
84
- }
85
- function searchVideos(client) {
86
- return (term) => __async(this, null, function* () {
87
- try {
88
- return yield get(client, `videos?query=${term}`);
89
- } catch (error) {
90
- console.error(`Error searching for videos with term: ${term}`, error);
91
- throw error;
92
- }
93
- });
94
- }
95
- function fetchVideo(client) {
96
- return (id) => __async(this, null, function* () {
97
- try {
98
- return yield get(client, `videos/${id}`);
99
- } catch (error) {
100
- console.error(`Error fetching video with ID: ${id}`, error);
101
- throw error;
102
- }
103
- });
104
- }
105
- function fetchPlaylists(client) {
106
- return () => __async(this, null, function* () {
107
- try {
108
- return yield get(client, "playlists");
109
- } catch (error) {
110
- console.error("Error fetching playlists", error);
111
- throw error;
112
- }
113
- });
114
- }
115
- function fetchPlaylist(client) {
116
- return (id) => __async(this, null, function* () {
117
- try {
118
- return yield get(client, `playlists/${id}`);
119
- } catch (error) {
120
- console.error(`Error fetching playlist with ID: ${id}`, error);
121
- throw error;
122
- }
123
- });
124
- }
125
-
126
- // src/util/throttle.ts
127
- var throttle = (fn, delay) => {
128
- let wait = false;
129
- let timeout;
130
- let cancelled = false;
131
- return [
132
- (...args) => {
133
- if (cancelled)
134
- return void 0;
135
- if (wait)
136
- return void 0;
137
- const val = fn(...args);
138
- wait = true;
139
- timeout = window.setTimeout(() => {
140
- wait = false;
141
- }, delay);
142
- return val;
143
- },
144
- () => {
145
- cancelled = true;
146
- clearTimeout(timeout);
147
- }
148
- ];
149
- };
150
-
151
- // src/lib/tracking.ts
152
- function sendEvent(client, eventName, data, debug) {
153
- const payload = {
154
- n: eventName,
155
- u: data.url,
156
- usr: data.userId,
157
- d: data.domain,
158
- ua: data.userAgent,
159
- w: data.deviceWidth,
160
- vid: (data == null ? void 0 : data.videoId) || void 0,
161
- vt: data.title,
162
- vdur: (data == null ? void 0 : data.videoDuration) || void 0,
163
- time: (data == null ? void 0 : data.currentTime) || void 0
164
- };
165
- if (debug)
166
- console.log(`Bold SDK - Logging event '${eventName}'`, payload);
167
- client.post("/event", payload);
168
- }
169
- var [throttledSendEvent] = throttle(sendEvent, 5e3);
170
- function trackEvent(client, userId, options) {
171
- return (video, event) => {
172
- var _a;
173
- const eventDetails = __spreadProps(__spreadValues({}, basicInfos()), {
174
- userId,
175
- videoId: video.id,
176
- title: video.title,
177
- videoDuration: video.duration,
178
- currentTime: ((_a = event.target) == null ? void 0 : _a.currentTime) || 0
179
- });
180
- if (event.type == "timeupdate" || event.type == "time-update") {
181
- throttledSendEvent(
182
- client,
183
- getEventName(event),
184
- eventDetails,
185
- options.debug
186
- );
187
- } else {
188
- sendEvent(client, getEventName(event), eventDetails, options.debug);
189
- }
190
- };
191
- }
192
- function trackPageView(client, userId, options) {
193
- return (title) => {
194
- const eventDetails = __spreadProps(__spreadValues({}, basicInfos()), {
195
- userId,
196
- title
197
- });
198
- sendEvent(client, "page_view", eventDetails, options.debug);
199
- };
200
- }
201
- function getEventName(event) {
202
- switch (event.type) {
203
- case "pause":
204
- return "video_pause";
205
- case "play":
206
- return "video_resume";
207
- case "loadedmetadata":
208
- case "loaded-metadata":
209
- return "video_load";
210
- case "time-update":
211
- case "timeupdate":
212
- return "video_progress";
213
- default:
214
- return "unknown_event";
215
- }
216
- }
217
- function basicInfos() {
218
- return {
219
- url: location.href,
220
- domain: location.hostname,
221
- referrer: document.referrer || null,
222
- deviceWidth: window.innerWidth,
223
- userAgent: navigator.userAgent
224
- };
225
- }
226
-
227
- // src/lib/client.ts
228
- function createClient(apiKey, options = { debug: false }) {
229
- var _a;
230
- if (!apiKey || typeof apiKey !== "string") {
231
- throw new Error("API key is missing or invalid");
232
- }
233
- const { debug } = options;
234
- const apiClientOptions = {
235
- baseURL: (_a = options.baseURL) != null ? _a : "https://app.boldvideo.io/api/v1/",
236
- headers: {
237
- Authorization: apiKey
238
- }
239
- };
240
- let apiClient;
241
- try {
242
- apiClient = axios.create(apiClientOptions);
243
- } catch (error) {
244
- console.error("Error creating API client", error);
245
- throw error;
246
- }
247
- const userId = [...Array(30)].map(() => Math.random().toString(36)[2]).join("");
248
- return {
249
- settings: fetchSettings(apiClient),
250
- videos: {
251
- list: fetchVideos(apiClient),
252
- get: fetchVideo(apiClient),
253
- search: searchVideos(apiClient)
254
- },
255
- playlists: {
256
- list: fetchPlaylists(apiClient),
257
- get: fetchPlaylist(apiClient)
258
- },
259
- trackEvent: trackEvent(apiClient, userId, { debug }),
260
- trackPageView: trackPageView(apiClient, userId, { debug })
261
- };
262
- }
263
- export {
264
- createClient
265
- };