@fastpix/fastpix-node 2.0.0 → 2.0.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.
Files changed (40) hide show
  1. package/README.md +219 -167
  2. package/dist/commonjs/funcs/signingKeysGetSigningKeyById.d.ts +2 -2
  3. package/dist/commonjs/funcs/signingKeysGetSigningKeyById.js +2 -2
  4. package/dist/commonjs/models/operations/getdrmconfiguration.d.ts +2 -2
  5. package/dist/commonjs/models/operations/getdrmconfiguration.d.ts.map +1 -1
  6. package/dist/commonjs/models/operations/getdrmconfiguration.js +2 -2
  7. package/dist/commonjs/models/operations/getdrmconfiguration.js.map +1 -1
  8. package/dist/commonjs/sdk/signingkeys.d.ts +2 -2
  9. package/dist/commonjs/sdk/signingkeys.js +2 -2
  10. package/dist/esm/funcs/signingKeysGetSigningKeyById.d.ts +2 -2
  11. package/dist/esm/funcs/signingKeysGetSigningKeyById.js +2 -2
  12. package/dist/esm/models/operations/getdrmconfiguration.d.ts +2 -2
  13. package/dist/esm/models/operations/getdrmconfiguration.d.ts.map +1 -1
  14. package/dist/esm/models/operations/getdrmconfiguration.js +2 -2
  15. package/dist/esm/models/operations/getdrmconfiguration.js.map +1 -1
  16. package/dist/esm/sdk/signingkeys.d.ts +2 -2
  17. package/dist/esm/sdk/signingkeys.js +2 -2
  18. package/package.json +24 -1
  19. package/samples/ai/ai-features.ts +194 -0
  20. package/samples/analytics/dimensions.ts +113 -0
  21. package/samples/analytics/errors.ts +133 -0
  22. package/samples/analytics/metrics.ts +117 -0
  23. package/samples/analytics/views.ts +120 -0
  24. package/samples/common/config.ts +84 -0
  25. package/samples/common/setup.ts +42 -0
  26. package/samples/comprehensive-example.ts +267 -0
  27. package/samples/index.ts +224 -0
  28. package/samples/live/live-playback.ts +104 -0
  29. package/samples/live/manage-live-stream.ts +176 -0
  30. package/samples/live/start-live-stream.ts +91 -0
  31. package/samples/media/input-video.ts +65 -0
  32. package/samples/media/manage-videos.ts +166 -0
  33. package/samples/media/playback.ts +89 -0
  34. package/samples/media/playlist.ts +201 -0
  35. package/samples/package.json +51 -0
  36. package/samples/security/drm-configurations.ts +125 -0
  37. package/samples/security/signing-keys.ts +154 -0
  38. package/src/funcs/signingKeysGetSigningKeyById.ts +2 -2
  39. package/src/models/operations/getdrmconfiguration.ts +4 -4
  40. package/src/sdk/signingkeys.ts +2 -2
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Views API Samples
3
+ *
4
+ * This file demonstrates how to use the Views API to:
5
+ * - List video views
6
+ * - Get video view details
7
+ * - List by top content
8
+ * - Get concurrent viewers timeseries
9
+ * - Get concurrent viewers breakdown
10
+ *
11
+ * Run this sample:
12
+ * npx tsx analytics/views.ts
13
+ */
14
+
15
+ import { createFastpixClient, runSample } from "../common/setup.js";
16
+ import { logResponse } from "../common/config.js";
17
+
18
+ async function listVideoViews() {
19
+ const fastpix = createFastpixClient();
20
+
21
+ const result = await fastpix.views.listVideoViews({
22
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
23
+ limit: 10,
24
+ offset: 0,
25
+ });
26
+
27
+ logResponse("List Video Views", result);
28
+ return result;
29
+ }
30
+
31
+ async function listVideoViewsWithFilters() {
32
+ const fastpix = createFastpixClient();
33
+
34
+ const result = await fastpix.views.listVideoViews({
35
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
36
+ filterby: ["device_type", "browser_name"],
37
+ limit: 5,
38
+ offset: 0,
39
+ orderBy: "timestamp",
40
+ sort: "desc",
41
+ });
42
+
43
+ logResponse("List Video Views with Filters", result);
44
+ return result;
45
+ }
46
+
47
+ async function getVideoViewDetails() {
48
+ const fastpix = createFastpixClient();
49
+
50
+ // First, get a view ID from the list
51
+ const views = await fastpix.views.listVideoViews({
52
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
53
+ limit: 1,
54
+ });
55
+
56
+ const viewId = views.listVideoViewsSuccessResponse?.data?.views?.[0]?.viewId;
57
+
58
+ if (!viewId) {
59
+ console.log("⚠️ No views found. Please ensure you have some video views first.");
60
+ return;
61
+ }
62
+
63
+ const result = await fastpix.views.getVideoViewDetails({
64
+ viewId: viewId,
65
+ });
66
+
67
+ logResponse("Get Video View Details", result);
68
+ return result;
69
+ }
70
+
71
+ async function listByTopContent() {
72
+ const fastpix = createFastpixClient();
73
+
74
+ const result = await fastpix.views.listByTopContent({
75
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
76
+ limit: 5,
77
+ offset: 0,
78
+ });
79
+
80
+ logResponse("List by Top Content", result);
81
+ return result;
82
+ }
83
+
84
+ async function getConcurrentViewersTimeseries() {
85
+ const fastpix = createFastpixClient();
86
+
87
+ const result = await fastpix.views.getDataViewlistCurrentViewsGetTimeseriesViews({
88
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
89
+ interval: "hour",
90
+ });
91
+
92
+ logResponse("Get Concurrent Viewers Timeseries", result);
93
+ return result;
94
+ }
95
+
96
+ async function getConcurrentViewersBreakdown() {
97
+ const fastpix = createFastpixClient();
98
+
99
+ const result = await fastpix.views.getDataViewlistCurrentViewsFilter({
100
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
101
+ filterby: ["device_type", "country"],
102
+ });
103
+
104
+ logResponse("Get Concurrent Viewers Breakdown", result);
105
+ return result;
106
+ }
107
+
108
+ async function main() {
109
+ console.log("📊 Views API Samples");
110
+ console.log("====================");
111
+
112
+ await runSample("List Video Views", listVideoViews);
113
+ await runSample("List Video Views with Filters", listVideoViewsWithFilters);
114
+ await runSample("Get Video View Details", getVideoViewDetails);
115
+ await runSample("List by Top Content", listByTopContent);
116
+ await runSample("Get Concurrent Viewers Timeseries", getConcurrentViewersTimeseries);
117
+ await runSample("Get Concurrent Viewers Breakdown", getConcurrentViewersBreakdown);
118
+ }
119
+
120
+ main().catch(console.error);
@@ -0,0 +1,84 @@
1
+ import dotenv from "dotenv";
2
+ dotenv.config();
3
+
4
+ /**
5
+ * Common configuration for all samples
6
+ *
7
+ * Set your credentials using environment variables:
8
+ * - FASTPIX_USERNAME: Your FastPix access token
9
+ * - FASTPIX_PASSWORD: Your FastPix secret key
10
+ *
11
+ * Or update the values directly below (not recommended for production)
12
+ */
13
+
14
+ export const config = {
15
+ // Use environment variables if available, otherwise fallback to placeholder values
16
+ username: process.env.FASTPIX_USERNAME || "your-access-token",
17
+ password: process.env.FASTPIX_PASSWORD || "your-secret-key",
18
+
19
+ // Sample video URL for testing
20
+ sampleVideoUrl: "https://static.fastpix.io/sample.mp4",
21
+
22
+ // Sample stream configuration
23
+ sampleStreamName: "Sample Live Stream",
24
+ sampleStreamDescription: "A sample live stream created via SDK",
25
+
26
+ // Sample playlist configuration
27
+ samplePlaylistName: "Sample Playlist",
28
+ samplePlaylistDescription: "A sample playlist created via SDK",
29
+ };
30
+
31
+ /**
32
+ * Helper function to validate configuration
33
+ */
34
+ export function validateConfig(): void {
35
+ if (config.username === "your-access-token" || config.password === "your-secret-key") {
36
+ console.warn("⚠️ Warning: Using placeholder credentials. Please set FASTPIX_USERNAME and FASTPIX_PASSWORD environment variables.");
37
+ console.log(" You can create a .env file in the samples directory with:");
38
+ console.log(" FASTPIX_USERNAME=your-actual-token");
39
+ console.log(" FASTPIX_PASSWORD=your-actual-secret");
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Helper function to log API responses
45
+ */
46
+ export function logResponse(operation: string, response: any): void {
47
+ console.log(`\n✅ ${operation} completed successfully:`);
48
+ console.log(JSON.stringify(response, null, 2));
49
+ }
50
+
51
+ /**
52
+ * Helper function to log errors
53
+ */
54
+ export function logError(operation: string, error: any): void {
55
+ console.error(`\n❌ ${operation} failed:`);
56
+ if (error instanceof Error) {
57
+ console.error(` Error: ${error.message}`);
58
+ if (error.stack) {
59
+ console.error(` Stack: ${error.stack.split('\n').slice(0, 3).join('\n')}`);
60
+ }
61
+ } else {
62
+ console.error(` Error: ${JSON.stringify(error, null, 2)}`);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Helper function to check if an error is a specific FastPix error type
68
+ */
69
+ export function isFastPixError(error: any): boolean {
70
+ return error && typeof error === 'object' && 'statusCode' in error;
71
+ }
72
+
73
+ /**
74
+ * Helper function to get user-friendly error message
75
+ */
76
+ export function getErrorMessage(error: any): string {
77
+ if (error instanceof Error) {
78
+ return error.message;
79
+ }
80
+ if (isFastPixError(error)) {
81
+ return `HTTP ${error.statusCode}: ${error.message || 'Unknown error'}`;
82
+ }
83
+ return String(error);
84
+ }
@@ -0,0 +1,42 @@
1
+ import { Fastpix } from "../../dist/esm/index.js";
2
+ import { config, validateConfig } from "./config.js";
3
+
4
+ /**
5
+ * Common setup function for all samples
6
+ * Creates and configures the FastPix SDK instance
7
+ */
8
+ export function createFastpixClient(): Fastpix {
9
+ validateConfig();
10
+
11
+ return new Fastpix({
12
+ security: {
13
+ username: config.username,
14
+ password: config.password,
15
+ },
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Helper function to run samples with error handling
21
+ */
22
+ export async function runSample(
23
+ sampleName: string,
24
+ sampleFunction: () => Promise<void>
25
+ ): Promise<void> {
26
+ try {
27
+ console.log(`\n🚀 Running ${sampleName}...`);
28
+ await sampleFunction();
29
+ console.log(`\n✅ ${sampleName} completed successfully!`);
30
+ } catch (error) {
31
+ console.error(`\n❌ ${sampleName} failed:`);
32
+ if (error instanceof Error) {
33
+ console.error(` Error: ${error.message}`);
34
+ if (error.stack) {
35
+ console.error(` Stack: ${error.stack.split('\n').slice(0, 3).join('\n')}`);
36
+ }
37
+ } else {
38
+ console.error(` Error: ${JSON.stringify(error, null, 2)}`);
39
+ }
40
+ throw error;
41
+ }
42
+ }
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Comprehensive FastPix SDK Example
3
+ *
4
+ * This example demonstrates a complete workflow using multiple FastPix APIs:
5
+ * 1. Create media from URL
6
+ * 2. Create a live stream
7
+ * 3. Create playlists
8
+ * 4. Generate analytics
9
+ * 5. Apply AI features
10
+ * 6. Set up security
11
+ *
12
+ * Run this sample:
13
+ * npx tsx comprehensive-example.ts
14
+ */
15
+
16
+ import { createFastpixClient, runSample } from "./common/setup.js";
17
+ import { config, logResponse, getErrorMessage } from "./common/config.js";
18
+
19
+ interface WorkflowData {
20
+ mediaId?: string;
21
+ streamId?: string;
22
+ playlistId?: string;
23
+ playbackId?: string;
24
+ signingKeyId?: string;
25
+ }
26
+
27
+ async function comprehensiveWorkflow() {
28
+ const fastpix = createFastpixClient();
29
+ const data: WorkflowData = {};
30
+
31
+ console.log("🚀 Starting Comprehensive FastPix SDK Workflow");
32
+ console.log("==============================================");
33
+
34
+ // Step 1: Create Media
35
+ console.log("\n📹 Step 1: Creating Media");
36
+ console.log("-------------------------");
37
+
38
+ const mediaResult = await fastpix.inputVideo.createMedia({
39
+ inputs: [
40
+ {
41
+ type: "video",
42
+ url: config.sampleVideoUrl,
43
+ },
44
+ ],
45
+ metadata: {
46
+ title: "Comprehensive Example Video",
47
+ description: "A video created for the comprehensive SDK example",
48
+ category: "demo",
49
+ tags: ["sdk", "example", "comprehensive"],
50
+ },
51
+ accessPolicy: "public",
52
+ });
53
+
54
+ if (mediaResult.createMediaSuccessResponse?.data?.id) {
55
+ data.mediaId = mediaResult.createMediaSuccessResponse.data.id;
56
+ console.log(`✅ Created media with ID: ${data.mediaId}`);
57
+ }
58
+
59
+ // Step 2: Create Live Stream
60
+ console.log("\n🔴 Step 2: Creating Live Stream");
61
+ console.log("-------------------------------");
62
+
63
+ const streamResult = await fastpix.startLiveStream.createNewStream({
64
+ requestBody: {
65
+ metadata: {
66
+ name: "Comprehensive Example Stream",
67
+ description: "A live stream created for the comprehensive SDK example",
68
+ category: "demo",
69
+ },
70
+ reconnectWindow: 30,
71
+ privacy: "public",
72
+ },
73
+ });
74
+
75
+ if (streamResult.data?.id) {
76
+ data.streamId = streamResult.data.id;
77
+ console.log(`✅ Created stream with ID: ${data.streamId}`);
78
+ console.log(`📡 Stream Key: ${streamResult.data.streamKey || 'N/A'}`);
79
+ }
80
+
81
+ // Step 3: Create Playlist
82
+ console.log("\n📋 Step 3: Creating Playlist");
83
+ console.log("----------------------------");
84
+
85
+ const playlistResult = await fastpix.playlist.createAPlaylist({
86
+ requestBody: {
87
+ name: "Comprehensive Example Playlist",
88
+ description: "A playlist created for the comprehensive SDK example",
89
+ metadata: {
90
+ category: "demo",
91
+ created_by: "sdk_example",
92
+ },
93
+ },
94
+ });
95
+
96
+ if (playlistResult.createAPlaylistSuccessResponse?.data?.id) {
97
+ data.playlistId = playlistResult.createAPlaylistSuccessResponse.data.id;
98
+ console.log(`✅ Created playlist with ID: ${data.playlistId}`);
99
+ }
100
+
101
+ // Step 4: Add Media to Playlist
102
+ if (data.mediaId && data.playlistId) {
103
+ console.log("\n➕ Step 4: Adding Media to Playlist");
104
+ console.log("-----------------------------------");
105
+
106
+ await fastpix.playlist.addMediaToPlaylist({
107
+ playlistId: data.playlistId,
108
+ requestBody: {
109
+ mediaId: data.mediaId,
110
+ },
111
+ });
112
+ console.log("✅ Added media to playlist");
113
+ }
114
+
115
+ // Step 5: Create Playback ID
116
+ if (data.mediaId) {
117
+ console.log("\n▶️ Step 5: Creating Playback ID");
118
+ console.log("--------------------------------");
119
+
120
+ const playbackResult = await fastpix.playback.createMediaPlaybackId({
121
+ mediaId: data.mediaId,
122
+ requestBody: {
123
+ policy: "public",
124
+ },
125
+ });
126
+
127
+ if (playbackResult.createMediaPlaybackIdSuccessResponse?.data?.id) {
128
+ data.playbackId = playbackResult.createMediaPlaybackIdSuccessResponse.data.id;
129
+ console.log(`✅ Created playback ID: ${data.playbackId}`);
130
+ }
131
+ }
132
+
133
+ // Step 6: Apply AI Features
134
+ if (data.mediaId) {
135
+ console.log("\n🤖 Step 6: Applying AI Features");
136
+ console.log("-------------------------------");
137
+
138
+ try {
139
+ // Enable summary generation
140
+ await fastpix.inVideoAIFeatures.updateMediaSummary({
141
+ mediaId: data.mediaId,
142
+ requestBody: { enabled: true },
143
+ });
144
+ console.log("✅ Enabled video summary generation");
145
+
146
+ // Enable chapter generation
147
+ await fastpix.inVideoAIFeatures.updateMediaChapters({
148
+ mediaId: data.mediaId,
149
+ requestBody: { enabled: true },
150
+ });
151
+ console.log("✅ Enabled video chapter generation");
152
+
153
+ // Enable content moderation
154
+ await fastpix.inVideoAIFeatures.updateMediaModeration({
155
+ mediaId: data.mediaId,
156
+ requestBody: {
157
+ enabled: true,
158
+ nsfw: true,
159
+ profanity: true,
160
+ },
161
+ });
162
+ console.log("✅ Enabled content moderation");
163
+ } catch (error) {
164
+ console.log("⚠️ AI features may not be available for this media");
165
+ console.log(` Error: ${getErrorMessage(error)}`);
166
+ }
167
+ }
168
+
169
+ // Step 7: Create Signing Key
170
+ console.log("\n🔐 Step 7: Creating Signing Key");
171
+ console.log("-------------------------------");
172
+
173
+ const signingKeyResult = await fastpix.signingKeys.createSigningKey();
174
+ if (signingKeyResult.data?.id) {
175
+ data.signingKeyId = signingKeyResult.data.id;
176
+ console.log(`✅ Created signing key with ID: ${data.signingKeyId}`);
177
+ console.log("📝 Private key generated (stored securely)");
178
+ }
179
+
180
+ // Step 8: Generate Analytics
181
+ console.log("\n📊 Step 8: Generating Analytics");
182
+ console.log("-------------------------------");
183
+
184
+ try {
185
+ // Get dimensions
186
+ const dimensions = await fastpix.dimensions.listDimensions();
187
+ console.log(`✅ Found ${dimensions.listDimensionsSuccessResponse?.data?.dimensions?.length || 0} dimensions`);
188
+
189
+ // Get metrics
190
+ const metrics = await fastpix.metrics.listOverallValues({
191
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
192
+ metric: "views",
193
+ });
194
+ console.log("✅ Retrieved performance metrics");
195
+
196
+ // Get views
197
+ const views = await fastpix.views.listVideoViews({
198
+ timespan: ["2024-01-01T00:00:00Z", "2024-12-31T23:59:59Z"],
199
+ limit: 5,
200
+ });
201
+ console.log(`✅ Retrieved ${views.listVideoViewsSuccessResponse?.data?.views?.length || 0} video views`);
202
+ } catch (error) {
203
+ console.log("⚠️ Analytics data may not be available yet");
204
+ console.log(` Error: ${getErrorMessage(error)}`);
205
+ }
206
+
207
+ // Step 9: Display Summary
208
+ console.log("\n📋 Workflow Summary");
209
+ console.log("===================");
210
+ console.log(`Media ID: ${data.mediaId || 'Not created'}`);
211
+ console.log(`Stream ID: ${data.streamId || 'Not created'}`);
212
+ console.log(`Playlist ID: ${data.playlistId || 'Not created'}`);
213
+ console.log(`Playback ID: ${data.playbackId || 'Not created'}`);
214
+ console.log(`Signing Key ID: ${data.signingKeyId || 'Not created'}`);
215
+
216
+ // Step 10: Cleanup (Optional)
217
+ console.log("\n🧹 Cleanup Options");
218
+ console.log("==================");
219
+ console.log("To clean up created resources, uncomment the cleanup section below");
220
+
221
+ // Uncomment to clean up resources
222
+ /*
223
+ if (data.signingKeyId) {
224
+ await fastpix.signingKeys.deleteSigningKey({ keyId: data.signingKeyId });
225
+ console.log("🗑️ Deleted signing key");
226
+ }
227
+
228
+ if (data.playbackId) {
229
+ await fastpix.playback.deleteMediaPlaybackId({ playbackId: data.playbackId });
230
+ console.log("🗑️ Deleted playback ID");
231
+ }
232
+
233
+ if (data.playlistId) {
234
+ await fastpix.playlist.deleteAPlaylist({ playlistId: data.playlistId });
235
+ console.log("🗑️ Deleted playlist");
236
+ }
237
+
238
+ if (data.streamId) {
239
+ await fastpix.manageLiveStream.deleteLiveStream({ streamId: data.streamId });
240
+ console.log("🗑️ Deleted stream");
241
+ }
242
+
243
+ if (data.mediaId) {
244
+ await fastpix.manageVideos.deleteMedia({ mediaId: data.mediaId });
245
+ console.log("🗑️ Deleted media");
246
+ }
247
+ */
248
+
249
+ return data;
250
+ }
251
+
252
+ async function main() {
253
+ try {
254
+ await runSample("Comprehensive Workflow", comprehensiveWorkflow);
255
+ console.log("\n🎉 Comprehensive workflow completed successfully!");
256
+ console.log("\n💡 Next Steps:");
257
+ console.log("1. Check your FastPix dashboard to see the created resources");
258
+ console.log("2. Use the stream key to start a live broadcast");
259
+ console.log("3. Use the playback ID to embed videos in your application");
260
+ console.log("4. Monitor analytics and AI features as they process");
261
+ } catch (error) {
262
+ console.error("\n❌ Workflow failed:");
263
+ console.error(` Error: ${getErrorMessage(error)}`);
264
+ }
265
+ }
266
+
267
+ main().catch(console.error);