@aviaryhq/cloudglue-js 0.3.1 → 0.3.3

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.
@@ -1,6 +1,40 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.CloudGlue = exports.CloudGlueError = void 0;
37
+ exports.convertFileToBase64 = convertFileToBase64;
4
38
  const Files_1 = require("../generated/Files");
5
39
  const Collections_1 = require("../generated/Collections");
6
40
  const Chat_1 = require("../generated/Chat");
@@ -10,6 +44,11 @@ const Segmentations_1 = require("../generated/Segmentations");
10
44
  const Search_1 = require("../generated/Search");
11
45
  const Describe_1 = require("../generated/Describe");
12
46
  const Segments_1 = require("../generated/Segments");
47
+ const Webhooks_1 = require("../generated/Webhooks");
48
+ const Frames_1 = require("../generated/Frames");
49
+ const Face_Detection_1 = require("../generated/Face_Detection");
50
+ const Face_Match_1 = require("../generated/Face_Match");
51
+ const fs = __importStar(require("fs"));
13
52
  class CloudGlueError extends Error {
14
53
  constructor(message, statusCode, data, headers, responseData) {
15
54
  super(message);
@@ -17,9 +56,43 @@ class CloudGlueError extends Error {
17
56
  this.data = data;
18
57
  this.headers = headers;
19
58
  this.responseData = responseData;
59
+ this.name = "CloudGlueError";
20
60
  }
21
61
  }
22
62
  exports.CloudGlueError = CloudGlueError;
63
+ /**
64
+ * Helper function to convert a local file path to base64 encoded string
65
+ * Only supports JPG and PNG image formats
66
+ * @param filePath - Path to the local image file (must be .jpg, .jpeg, or .png)
67
+ * @returns Promise<string> - Base64 encoded string with data URL prefix
68
+ */
69
+ async function convertFileToBase64(filePath) {
70
+ try {
71
+ const fileBuffer = await fs.promises.readFile(filePath);
72
+ const base64String = fileBuffer.toString('base64');
73
+ // Determine MIME type based on file extension (only JPG and PNG supported)
74
+ const extension = filePath.toLowerCase().split('.').pop();
75
+ let mimeType;
76
+ switch (extension) {
77
+ case 'png':
78
+ mimeType = 'image/png';
79
+ break;
80
+ case 'jpg':
81
+ case 'jpeg':
82
+ mimeType = 'image/jpeg';
83
+ break;
84
+ default:
85
+ throw new CloudGlueError(`Unsupported file format: ${extension}. Only JPG and PNG files are supported.`);
86
+ }
87
+ return `data:${mimeType};base64,${base64String}`;
88
+ }
89
+ catch (error) {
90
+ if (error instanceof CloudGlueError) {
91
+ throw error;
92
+ }
93
+ throw new CloudGlueError(`Failed to read file at path "${filePath}": ${error instanceof Error ? error.message : 'Unknown error'}`);
94
+ }
95
+ }
23
96
  // Enhanced API client classes
24
97
  class EnhancedFilesApi {
25
98
  constructor(api) {
@@ -61,7 +134,7 @@ class EnhancedFilesApi {
61
134
  formData.append("enable_segment_thumbnails", params.enable_segment_thumbnails.toString());
62
135
  }
63
136
  // Use axios directly to bypass Zodios validation
64
- return this.api.axios({
137
+ const response = await this.api.axios({
65
138
  method: "post",
66
139
  url: "/files",
67
140
  data: formData,
@@ -69,6 +142,7 @@ class EnhancedFilesApi {
69
142
  "Content-Type": "multipart/form-data",
70
143
  },
71
144
  });
145
+ return response.data;
72
146
  }
73
147
  async getFile(fileId) {
74
148
  return this.api.getFile({ params: { file_id: fileId } });
@@ -109,6 +183,11 @@ class EnhancedFilesApi {
109
183
  body: params,
110
184
  });
111
185
  }
186
+ async createFileFrameExtraction(fileId, params) {
187
+ return this.api.createFileFrameExtraction(params, {
188
+ params: { file_id: fileId }
189
+ });
190
+ }
112
191
  /**
113
192
  * Waits for a file to finish processing by polling the getFile endpoint until the file
114
193
  * reaches a terminal state (completed, failed, or not_applicable) or until maxAttempts is reached.
@@ -155,6 +234,9 @@ class EnhancedCollectionsApi {
155
234
  async deleteCollection(collectionId) {
156
235
  return this.api.deleteCollection(undefined, { params: { collection_id: collectionId } });
157
236
  }
237
+ async updateCollection(collectionId, params) {
238
+ return this.api.updateCollection(params, { params: { collection_id: collectionId } });
239
+ }
158
240
  async addVideoByUrl({ collectionId, url, params }) {
159
241
  return this.api.addVideo({ url, ...params }, { params: { collection_id: collectionId, ...params } });
160
242
  }
@@ -175,9 +257,10 @@ class EnhancedCollectionsApi {
175
257
  async deleteVideo(collectionId, fileId) {
176
258
  return this.api.deleteVideo(undefined, { params: { collection_id: collectionId, file_id: fileId } });
177
259
  }
178
- async getEntities(collectionId, fileId) {
260
+ async getEntities(collectionId, fileId, params = {}) {
179
261
  return this.api.getEntities({
180
- params: { collection_id: collectionId, file_id: fileId }
262
+ params: { collection_id: collectionId, file_id: fileId },
263
+ queries: params
181
264
  });
182
265
  }
183
266
  async getTranscripts(collectionId, fileId, limit, offset, response_format) {
@@ -440,6 +523,9 @@ class EnhancedSegmentsApi {
440
523
  async createSegmentJob(params) {
441
524
  return this.api.createSegments(params);
442
525
  }
526
+ async deleteSegmentJob(jobId) {
527
+ return this.api.deleteSegments(undefined, { params: { job_id: jobId } });
528
+ }
443
529
  async waitForReady(jobId, options = {}) {
444
530
  const { pollingInterval = 5000, maxAttempts = 36, } = options;
445
531
  let attempts = 0;
@@ -459,6 +545,136 @@ class EnhancedSegmentsApi {
459
545
  throw new CloudGlueError(`Timeout waiting for segment job ${jobId} to process after ${maxAttempts} attempts`);
460
546
  }
461
547
  }
548
+ class EnhancedWebhooksApi {
549
+ constructor(api) {
550
+ this.api = api;
551
+ }
552
+ async listWebhooks(params = {}) {
553
+ return this.api.listWebhooks({ queries: params });
554
+ }
555
+ async getWebhook(webhookId) {
556
+ return this.api.getWebhookById({ params: { webhook_id: webhookId } });
557
+ }
558
+ async createWebhook(params) {
559
+ return this.api.createWebhook(params);
560
+ }
561
+ async updateWebhook(webhookId, params) {
562
+ return this.api.updateWebhook(params, { params: { webhook_id: webhookId, } });
563
+ }
564
+ async deleteWebhook(webhookId) {
565
+ return this.api.deleteWebhook(undefined, { params: { webhook_id: webhookId } });
566
+ }
567
+ }
568
+ class EnhancedFramesApi {
569
+ constructor(api) {
570
+ this.api = api;
571
+ }
572
+ async getFrameExtraction(frameExtractionId, params = {}) {
573
+ return this.api.getFrameExtraction({
574
+ params: { frame_extraction_id: frameExtractionId },
575
+ queries: params
576
+ });
577
+ }
578
+ async deleteFrameExtraction(frameExtractionId) {
579
+ return this.api.deleteFrameExtraction(undefined, { params: { frame_extraction_id: frameExtractionId } });
580
+ }
581
+ async waitForReady(frameExtractionId, options = {}) {
582
+ const { pollingInterval = 5000, maxAttempts = 36 } = options;
583
+ let attempts = 0;
584
+ while (attempts < maxAttempts) {
585
+ const job = await this.getFrameExtraction(frameExtractionId);
586
+ if (["completed", "failed"].includes(job.status)) {
587
+ if (job.status === "failed") {
588
+ throw new CloudGlueError(`Frame extraction job failed: ${frameExtractionId}`);
589
+ }
590
+ return job;
591
+ }
592
+ await new Promise(resolve => setTimeout(resolve, pollingInterval));
593
+ attempts++;
594
+ }
595
+ throw new CloudGlueError(`Frame extraction job did not complete within ${maxAttempts * pollingInterval / 1000} seconds: ${frameExtractionId}`);
596
+ }
597
+ }
598
+ class EnhancedFaceDetectionApi {
599
+ constructor(api) {
600
+ this.api = api;
601
+ }
602
+ async createFaceDetection(params) {
603
+ return this.api.createFaceDetection(params);
604
+ }
605
+ async getFaceDetection(faceDetectionId, params = {}) {
606
+ const { limit, offset } = params;
607
+ return this.api.getFaceDetection({
608
+ params: { face_detection_id: faceDetectionId },
609
+ queries: { limit, offset }
610
+ });
611
+ }
612
+ async deleteFaceDetection(faceDetectionId) {
613
+ return this.api.deleteFaceDetection(undefined, { params: { face_detection_id: faceDetectionId } });
614
+ }
615
+ async waitForReady(faceDetectionId, options = {}) {
616
+ const { pollingInterval = 5000, maxAttempts = 36 } = options;
617
+ let attempts = 0;
618
+ while (attempts < maxAttempts) {
619
+ const job = await this.getFaceDetection(faceDetectionId);
620
+ if (["completed", "failed"].includes(job.status)) {
621
+ if (job.status === "failed") {
622
+ throw new CloudGlueError(`Face detection job failed: ${faceDetectionId}`);
623
+ }
624
+ return job;
625
+ }
626
+ await new Promise(resolve => setTimeout(resolve, pollingInterval));
627
+ attempts++;
628
+ }
629
+ throw new CloudGlueError(`Face detection job did not complete within ${maxAttempts * pollingInterval / 1000} seconds: ${faceDetectionId}`);
630
+ }
631
+ }
632
+ class EnhancedFaceMatchApi {
633
+ constructor(api) {
634
+ this.api = api;
635
+ }
636
+ async createFaceMatch(params) {
637
+ // Handle local file path by converting to base64
638
+ if (params.source_image.file_path) {
639
+ const base64Image = await convertFileToBase64(params.source_image.file_path);
640
+ const { file_path, ...restSourceImage } = params.source_image;
641
+ return this.api.createFaceMatch({
642
+ ...params,
643
+ source_image: {
644
+ ...restSourceImage,
645
+ base64_image: base64Image
646
+ }
647
+ });
648
+ }
649
+ return this.api.createFaceMatch(params);
650
+ }
651
+ async getFaceMatch(faceMatchId, params = {}) {
652
+ const { limit, offset } = params;
653
+ return this.api.getFaceMatch({
654
+ params: { face_match_id: faceMatchId },
655
+ queries: { limit, offset }
656
+ });
657
+ }
658
+ async deleteFaceMatch(faceMatchId) {
659
+ return this.api.deleteFaceMatch(undefined, { params: { face_match_id: faceMatchId } });
660
+ }
661
+ async waitForReady(faceMatchId, options = {}) {
662
+ const { pollingInterval = 5000, maxAttempts = 36 } = options;
663
+ let attempts = 0;
664
+ while (attempts < maxAttempts) {
665
+ const job = await this.getFaceMatch(faceMatchId);
666
+ if (["completed", "failed"].includes(job.status)) {
667
+ if (job.status === "failed") {
668
+ throw new CloudGlueError(`Face match job failed: ${faceMatchId}`);
669
+ }
670
+ return job;
671
+ }
672
+ await new Promise(resolve => setTimeout(resolve, pollingInterval));
673
+ attempts++;
674
+ }
675
+ throw new CloudGlueError(`Face match job did not complete within ${maxAttempts * pollingInterval / 1000} seconds: ${faceMatchId}`);
676
+ }
677
+ }
462
678
  /**
463
679
  * Main CloudGlue client class that provides access to all API functionality
464
680
  * through enhanced, user-friendly interfaces
@@ -475,7 +691,7 @@ class CloudGlue {
475
691
  headers: {
476
692
  Authorization: `Bearer ${this.apiKey}`,
477
693
  'x-sdk-client': 'cloudglue-js',
478
- 'x-sdk-version': '0.3.1',
694
+ 'x-sdk-version': '0.3.3',
479
695
  },
480
696
  baseURL: this.baseUrl,
481
697
  timeout: this.timeout,
@@ -496,8 +712,12 @@ class CloudGlue {
496
712
  const searchApi = (0, Search_1.createApiClient)(this.baseUrl, sharedConfig);
497
713
  const describeApi = (0, Describe_1.createApiClient)(this.baseUrl, sharedConfig);
498
714
  const segmentsApi = (0, Segments_1.createApiClient)(this.baseUrl, sharedConfig);
715
+ const framesApi = (0, Frames_1.createApiClient)(this.baseUrl, sharedConfig);
716
+ const faceDetectionApi = (0, Face_Detection_1.createApiClient)(this.baseUrl, sharedConfig);
717
+ const faceMatchApi = (0, Face_Match_1.createApiClient)(this.baseUrl, sharedConfig);
718
+ const webhooksApi = (0, Webhooks_1.createApiClient)(this.baseUrl, sharedConfig);
499
719
  // Configure base URL and axios config for all clients
500
- [filesApi, collectionsApi, chatApi, transcribeApi, extractApi, segmentationsApi, searchApi, describeApi, segmentsApi].forEach((client) => {
720
+ [filesApi, collectionsApi, chatApi, transcribeApi, extractApi, segmentationsApi, searchApi, describeApi, segmentsApi, framesApi, faceDetectionApi, faceMatchApi, webhooksApi].forEach((client) => {
501
721
  Object.assign(client.axios.defaults, axiosConfig);
502
722
  client.axios.interceptors.response.use((response) => {
503
723
  return response;
@@ -522,6 +742,10 @@ class CloudGlue {
522
742
  this.search = new EnhancedSearchApi(searchApi);
523
743
  this.describe = new EnhancedDescribeApi(describeApi);
524
744
  this.segments = new EnhancedSegmentsApi(segmentsApi);
745
+ this.frames = new EnhancedFramesApi(framesApi);
746
+ this.faceDetection = new EnhancedFaceDetectionApi(faceDetectionApi);
747
+ this.faceMatch = new EnhancedFaceMatchApi(faceMatchApi);
748
+ this.webhooks = new EnhancedWebhooksApi(webhooksApi);
525
749
  }
526
750
  }
527
751
  exports.CloudGlue = CloudGlue;
@@ -7,6 +7,10 @@ import { schemas as searchSchemas } from '../generated/Search';
7
7
  import { schemas as describeSchemas } from '../generated/Describe';
8
8
  import { schemas as segmentsSchemas } from '../generated/Segments';
9
9
  import { SegmentationUniformConfig as SegmentationUniformConfigType, SegmentationShotDetectorConfig as SegmentationShotDetectorConfigType, SegmentationConfig as SegmentationConfigType } from '../generated/common';
10
+ import { schemas as webhooksSchemas } from '../generated/Webhooks';
11
+ import { FrameExtraction } from '../generated/common';
12
+ import { schemas as faceDetectionSchemas } from '../generated/Face_Detection';
13
+ import { schemas as faceMatchSchemas } from '../generated/Face_Match';
10
14
  /**
11
15
  * Represents a video file in the Cloudglue system
12
16
  * Contains metadata about the file including its status, size, and video information
@@ -148,3 +152,48 @@ export type CollectionMediaDescription = z.infer<typeof collectionsSchemas.Media
148
152
  export type CollectionMediaDescriptionsList = z.infer<typeof collectionsSchemas.CollectionMediaDescriptionsList>;
149
153
  export type NarrativeConfig = z.infer<typeof segmentsSchemas.NarrativeConfig>;
150
154
  export type ShotConfig = z.infer<typeof segmentsSchemas.ShotConfig>;
155
+ export type WebhookEvents = z.infer<typeof webhooksSchemas['WebhookEvents']>;
156
+ /**
157
+ * Represents a frame extraction job
158
+ */
159
+ export type { FrameExtraction };
160
+ /**
161
+ * Configuration for frame extraction
162
+ */
163
+ export type { FrameExtractionConfig, FrameExtractionUniformConfig, FrameExtractionThumbnailsConfig } from '../generated/common';
164
+ /**
165
+ * Represents a face detection job
166
+ */
167
+ export type FaceDetection = z.infer<typeof faceDetectionSchemas.FaceDetection>;
168
+ /**
169
+ * Represents a face detection request
170
+ */
171
+ export type FaceDetectionRequest = z.infer<typeof faceDetectionSchemas.FaceDetectionRequest>;
172
+ /**
173
+ * Represents a detected face
174
+ */
175
+ export type DetectedFace = z.infer<typeof faceDetectionSchemas.DetectedFace>;
176
+ /**
177
+ * Represents a face match job
178
+ */
179
+ export type FaceMatch = z.infer<typeof faceMatchSchemas.FaceMatch>;
180
+ /**
181
+ * Represents a face match request
182
+ */
183
+ export type FaceMatchRequest = z.infer<typeof faceMatchSchemas.FaceMatchRequest>;
184
+ /**
185
+ * Represents a face match result
186
+ */
187
+ export type FaceMatchResult = z.infer<typeof faceMatchSchemas.FaceMatchResult>;
188
+ /**
189
+ * Represents a source image for face matching
190
+ */
191
+ export type SourceImage = z.infer<typeof faceMatchSchemas.SourceImage>;
192
+ /**
193
+ * Enhanced source image type that supports local file paths
194
+ */
195
+ export type EnhancedSourceImage = {
196
+ url?: string;
197
+ base64_image?: string;
198
+ file_path?: string;
199
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aviaryhq/cloudglue-js",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Cloudglue API client for Node.js",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",