@hff-ai/media-processor-client 1.0.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.
- package/README.md +570 -0
- package/dist/MediaProcessor.d.ts +222 -0
- package/dist/MediaProcessor.d.ts.map +1 -0
- package/dist/MediaProcessor.js +731 -0
- package/dist/MediaProcessor.js.map +1 -0
- package/dist/__tests__/integration/mockMediaProcessor.d.ts +80 -0
- package/dist/__tests__/integration/mockMediaProcessor.d.ts.map +1 -0
- package/dist/__tests__/integration/mockMediaProcessor.js +248 -0
- package/dist/__tests__/integration/mockMediaProcessor.js.map +1 -0
- package/dist/__tests__/setup.d.ts +4 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +13 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/errors.d.ts +134 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +173 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error classes for the Media Processor Client
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ProcessingError = exports.RequestError = exports.ConfigurationError = exports.ConnectionError = exports.MediaProcessorError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all media processor errors
|
|
9
|
+
*/
|
|
10
|
+
class MediaProcessorError extends Error {
|
|
11
|
+
constructor(message, code, details) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'MediaProcessorError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.details = details;
|
|
16
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
17
|
+
if (Error.captureStackTrace) {
|
|
18
|
+
Error.captureStackTrace(this, this.constructor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.MediaProcessorError = MediaProcessorError;
|
|
23
|
+
/**
|
|
24
|
+
* Connection-related errors
|
|
25
|
+
*/
|
|
26
|
+
class ConnectionError extends MediaProcessorError {
|
|
27
|
+
constructor(message, code, details) {
|
|
28
|
+
super(message, code, details);
|
|
29
|
+
this.name = 'ConnectionError';
|
|
30
|
+
this.code = code;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a connection failed error
|
|
34
|
+
*/
|
|
35
|
+
static connectionFailed(target, originalError) {
|
|
36
|
+
return new ConnectionError(`Failed to connect to ${target}`, 'CONNECTION_FAILED', { target, originalError: originalError?.message });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a connection lost error
|
|
40
|
+
*/
|
|
41
|
+
static connectionLost(reason) {
|
|
42
|
+
return new ConnectionError(`Connection lost: ${reason}`, 'CONNECTION_LOST', { reason });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create an authentication failed error
|
|
46
|
+
*/
|
|
47
|
+
static authFailed(message) {
|
|
48
|
+
return new ConnectionError(message || 'Authentication failed: Invalid or expired token', 'AUTH_FAILED');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create an AMQP error
|
|
52
|
+
*/
|
|
53
|
+
static amqpError(message, originalError) {
|
|
54
|
+
return new ConnectionError(`AMQP error: ${message}`, 'AMQP_ERROR', { originalError: originalError?.message });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a REST API error
|
|
58
|
+
*/
|
|
59
|
+
static restApiError(message, statusCode, response) {
|
|
60
|
+
return new ConnectionError(`REST API error: ${message}`, 'REST_API_ERROR', { statusCode, response });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a reconnect failed error
|
|
64
|
+
*/
|
|
65
|
+
static reconnectFailed(attempts) {
|
|
66
|
+
return new ConnectionError(`Failed to reconnect after ${attempts} attempts`, 'RECONNECT_FAILED', { attempts });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ConnectionError = ConnectionError;
|
|
70
|
+
/**
|
|
71
|
+
* Configuration errors
|
|
72
|
+
*/
|
|
73
|
+
class ConfigurationError extends MediaProcessorError {
|
|
74
|
+
constructor(message, code, details) {
|
|
75
|
+
super(message, code, details);
|
|
76
|
+
this.name = 'ConfigurationError';
|
|
77
|
+
this.code = code;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create an invalid config error
|
|
81
|
+
*/
|
|
82
|
+
static invalidConfig(reason) {
|
|
83
|
+
return new ConfigurationError(`Invalid configuration: ${reason}`, 'INVALID_CONFIG', { reason });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a missing required field error
|
|
87
|
+
*/
|
|
88
|
+
static missingField(field) {
|
|
89
|
+
return new ConfigurationError(`Missing required configuration field: ${field}`, 'MISSING_REQUIRED_FIELD', { field });
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create an invalid S3 config error
|
|
93
|
+
*/
|
|
94
|
+
static invalidS3Config(reason) {
|
|
95
|
+
return new ConfigurationError(`Invalid S3 configuration: ${reason}`, 'INVALID_S3_CONFIG', { reason });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create an invalid URL error
|
|
99
|
+
*/
|
|
100
|
+
static invalidUrl(field, value) {
|
|
101
|
+
return new ConfigurationError(`Invalid URL for ${field}: ${value}`, 'INVALID_URL', { field, value });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ConfigurationError = ConfigurationError;
|
|
105
|
+
/**
|
|
106
|
+
* Processing request errors (thrown synchronously when submitting requests)
|
|
107
|
+
*/
|
|
108
|
+
class RequestError extends MediaProcessorError {
|
|
109
|
+
constructor(message, code, details) {
|
|
110
|
+
super(message, code, details);
|
|
111
|
+
this.name = 'RequestError';
|
|
112
|
+
this.code = code;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create an invalid S3 key error
|
|
116
|
+
*/
|
|
117
|
+
static invalidS3Key(s3Key, reason) {
|
|
118
|
+
return new RequestError(`Invalid S3 key: ${s3Key}${reason ? ` - ${reason}` : ''}`, 'INVALID_S3_KEY', { s3Key, reason });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a queue publish failed error
|
|
122
|
+
*/
|
|
123
|
+
static queuePublishFailed(queue, originalError) {
|
|
124
|
+
return new RequestError(`Failed to publish message to queue: ${queue}`, 'QUEUE_PUBLISH_FAILED', { queue, originalError: originalError?.message });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a not connected error
|
|
128
|
+
*/
|
|
129
|
+
static notConnected() {
|
|
130
|
+
return new RequestError('Cannot submit request: not connected to media processor', 'NOT_CONNECTED');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create an invalid media type error
|
|
134
|
+
*/
|
|
135
|
+
static invalidMediaType(mediaType) {
|
|
136
|
+
return new RequestError(`Invalid media type: ${mediaType}. Must be 'image', 'video', or 'zip'`, 'INVALID_MEDIA_TYPE', { mediaType });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.RequestError = RequestError;
|
|
140
|
+
/**
|
|
141
|
+
* Processing errors (thrown when async processing fails)
|
|
142
|
+
* Wraps the MediaErrorMessage received from the server
|
|
143
|
+
*/
|
|
144
|
+
class ProcessingError extends MediaProcessorError {
|
|
145
|
+
constructor(message, code, mediaId, mediaType, errorCode, details) {
|
|
146
|
+
super(message, code, details);
|
|
147
|
+
this.name = 'ProcessingError';
|
|
148
|
+
this.code = code;
|
|
149
|
+
this.mediaId = mediaId;
|
|
150
|
+
this.mediaType = mediaType;
|
|
151
|
+
this.errorCode = errorCode;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create from a MediaErrorMessage
|
|
155
|
+
*/
|
|
156
|
+
static fromErrorMessage(msg) {
|
|
157
|
+
return new ProcessingError(msg.error, 'PROCESSING_FAILED', msg.mediaId, msg.mediaType, msg.errorCode, msg.details);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a timeout error
|
|
161
|
+
*/
|
|
162
|
+
static timeout(mediaId, mediaType, timeoutMs) {
|
|
163
|
+
return new ProcessingError(`Processing timed out after ${timeoutMs}ms`, 'PROCESSING_TIMEOUT', mediaId, mediaType, 'PROCESSING_TIMEOUT', { timeoutMs });
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Create a disconnected error
|
|
167
|
+
*/
|
|
168
|
+
static disconnected(mediaId, mediaType) {
|
|
169
|
+
return new ProcessingError('Processing aborted: connection lost', 'DISCONNECTED', mediaId, mediaType, 'DISCONNECTED');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.ProcessingError = ProcessingError;
|
|
173
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAI5C,YAAY,OAAe,EAAE,IAAY,EAAE,OAAiC;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,qFAAqF;QACrF,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AAfD,kDAeC;AAaD;;GAEG;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SAAS,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,GAMvB;QACC,OAAO,IAAI,eAAe,CACxB,GAAG,CAAC,KAAK,EACT,mBAAmB,EACnB,GAAG,CAAC,OAAO,EACX,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,OAAO,CACZ,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAe,EAAE,SAAiB,EAAE,SAAiB;QAClE,OAAO,IAAI,eAAe,CACxB,8BAA8B,SAAS,IAAI,EAC3C,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,oBAAoB,EACpB,EAAE,SAAS,EAAE,CACd,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,OAAe,EAAE,SAAiB;QACpD,OAAO,IAAI,eAAe,CACxB,qCAAqC,EACrC,cAAc,EACd,OAAO,EACP,SAAS,EACT,cAAc,CACf,CAAC;IACJ,CAAC;CACF;AApED,0CAoEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hff-ai/media-processor-client
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for communicating with the HFF Media Processor service.
|
|
5
|
+
* Provides both async/await and event-based APIs for media processing.
|
|
6
|
+
*
|
|
7
|
+
* @example Async/await API (recommended for most use cases)
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { media_processor, MediaResultMessage } from '@hff-ai/media-processor-client';
|
|
10
|
+
*
|
|
11
|
+
* const processor = await media_processor.connect(config);
|
|
12
|
+
*
|
|
13
|
+
* // Process and await the result
|
|
14
|
+
* const result = await processor.processS3Image('uploads/photo.jpg');
|
|
15
|
+
* console.log('Processed:', result.result.s3Key);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Event-based API (for streaming progress or batch processing)
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const processor = await media_processor.connect(config);
|
|
21
|
+
*
|
|
22
|
+
* processor.on('image_completed', (msg) => {
|
|
23
|
+
* console.log('Image processed:', msg.result);
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Queue without waiting
|
|
27
|
+
* const mediaId = processor.queueS3Image('uploads/photo.jpg');
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import { MediaProcessor } from './MediaProcessor';
|
|
31
|
+
import { MediaProcessorConfig } from './types';
|
|
32
|
+
/**
|
|
33
|
+
* Factory object for creating MediaProcessor instances
|
|
34
|
+
*/
|
|
35
|
+
export declare const media_processor: {
|
|
36
|
+
/**
|
|
37
|
+
* Create and connect to a MediaProcessor instance
|
|
38
|
+
*
|
|
39
|
+
* @param config - Configuration for the media processor connection
|
|
40
|
+
* @returns Connected MediaProcessor instance
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const processor = await media_processor.connect({
|
|
45
|
+
* processorUrl: 'https://mp.hff.ai',
|
|
46
|
+
* processorAmqp: 'amqp://user:pass@mp.hff.ai',
|
|
47
|
+
* token: 'your-token',
|
|
48
|
+
* s3Details: { ... },
|
|
49
|
+
* system: 'my-app',
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
connect(config: MediaProcessorConfig): Promise<MediaProcessor>;
|
|
54
|
+
/**
|
|
55
|
+
* Create a MediaProcessor instance without connecting
|
|
56
|
+
*
|
|
57
|
+
* Useful when you want to set up event handlers before connecting.
|
|
58
|
+
*
|
|
59
|
+
* @param config - Configuration for the media processor
|
|
60
|
+
* @returns MediaProcessor instance (not yet connected)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const processor = media_processor.create(config);
|
|
65
|
+
*
|
|
66
|
+
* // Set up handlers first
|
|
67
|
+
* processor.on('connected', () => console.log('Connected!'));
|
|
68
|
+
* processor.on('error', (err) => console.error('Error:', err));
|
|
69
|
+
*
|
|
70
|
+
* // Then connect
|
|
71
|
+
* await processor.connect();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
create(config: MediaProcessorConfig): MediaProcessor;
|
|
75
|
+
};
|
|
76
|
+
export { MediaProcessor };
|
|
77
|
+
export type { MediaProcessorConfig, S3Config, ProcessorOptions, BaseProcessOptions, ImageProcessOptions, VideoProcessOptions, ZipProcessOptions, AsyncProcessOptions, AsyncImageProcessOptions, AsyncVideoProcessOptions, AsyncZipProcessOptions, MediaType, MediaProcessMessage, MediaUpdateMessage, MediaProgressMessage, MediaResultMessage, MediaErrorMessage, ProcessingResult, ImageResult, VideoResult, ZipResult, ImageVersion, VideoVersion, VideoThumbnail, ExtractedMediaItem, SkippedFile, ProcessingStatus, ProcessingStage, MediaProcessorErrorCode, SystemStatus, DisconnectedPayload, ReconnectingPayload, UnhandledMessagePayload, MediaProcessorEvents, } from './types';
|
|
78
|
+
export { isProgressMessage, isResultMessage, isErrorMessage, isImageResult, isVideoResult, isZipResult, } from './types';
|
|
79
|
+
export { MediaProcessorError, ConnectionError, ConfigurationError, RequestError, ProcessingError, } from './errors';
|
|
80
|
+
export type { ConnectionErrorCode, ConfigurationErrorCode, RequestErrorCode, ProcessingErrorCode, } from './errors';
|
|
81
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAM/C;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;;;;;;;;;;;OAgBG;oBACmB,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;IAMpE;;;;;;;;;;;;;;;;;;;OAmBG;mBACY,oBAAoB,GAAG,cAAc;CAGrD,CAAC;AAMF,OAAO,EAAE,cAAc,EAAE,CAAC;AAM1B,YAAY,EAEV,oBAAoB,EACpB,QAAQ,EACR,gBAAgB,EAGhB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EAGjB,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EAGtB,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EAGjB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,WAAW,EAGX,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,YAAY,EAGZ,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,aAAa,EACb,aAAa,EACb,WAAW,GACZ,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,GAChB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @hff-ai/media-processor-client
|
|
4
|
+
*
|
|
5
|
+
* TypeScript client for communicating with the HFF Media Processor service.
|
|
6
|
+
* Provides both async/await and event-based APIs for media processing.
|
|
7
|
+
*
|
|
8
|
+
* @example Async/await API (recommended for most use cases)
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { media_processor, MediaResultMessage } from '@hff-ai/media-processor-client';
|
|
11
|
+
*
|
|
12
|
+
* const processor = await media_processor.connect(config);
|
|
13
|
+
*
|
|
14
|
+
* // Process and await the result
|
|
15
|
+
* const result = await processor.processS3Image('uploads/photo.jpg');
|
|
16
|
+
* console.log('Processed:', result.result.s3Key);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example Event-based API (for streaming progress or batch processing)
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const processor = await media_processor.connect(config);
|
|
22
|
+
*
|
|
23
|
+
* processor.on('image_completed', (msg) => {
|
|
24
|
+
* console.log('Image processed:', msg.result);
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Queue without waiting
|
|
28
|
+
* const mediaId = processor.queueS3Image('uploads/photo.jpg');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ProcessingError = exports.RequestError = exports.ConfigurationError = exports.ConnectionError = exports.MediaProcessorError = exports.isZipResult = exports.isVideoResult = exports.isImageResult = exports.isErrorMessage = exports.isResultMessage = exports.isProgressMessage = exports.MediaProcessor = exports.media_processor = void 0;
|
|
33
|
+
const MediaProcessor_1 = require("./MediaProcessor");
|
|
34
|
+
Object.defineProperty(exports, "MediaProcessor", { enumerable: true, get: function () { return MediaProcessor_1.MediaProcessor; } });
|
|
35
|
+
// =============================================================================
|
|
36
|
+
// Main Export: media_processor factory
|
|
37
|
+
// =============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Factory object for creating MediaProcessor instances
|
|
40
|
+
*/
|
|
41
|
+
exports.media_processor = {
|
|
42
|
+
/**
|
|
43
|
+
* Create and connect to a MediaProcessor instance
|
|
44
|
+
*
|
|
45
|
+
* @param config - Configuration for the media processor connection
|
|
46
|
+
* @returns Connected MediaProcessor instance
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const processor = await media_processor.connect({
|
|
51
|
+
* processorUrl: 'https://mp.hff.ai',
|
|
52
|
+
* processorAmqp: 'amqp://user:pass@mp.hff.ai',
|
|
53
|
+
* token: 'your-token',
|
|
54
|
+
* s3Details: { ... },
|
|
55
|
+
* system: 'my-app',
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
async connect(config) {
|
|
60
|
+
const processor = new MediaProcessor_1.MediaProcessor(config);
|
|
61
|
+
await processor.connect();
|
|
62
|
+
return processor;
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Create a MediaProcessor instance without connecting
|
|
66
|
+
*
|
|
67
|
+
* Useful when you want to set up event handlers before connecting.
|
|
68
|
+
*
|
|
69
|
+
* @param config - Configuration for the media processor
|
|
70
|
+
* @returns MediaProcessor instance (not yet connected)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const processor = media_processor.create(config);
|
|
75
|
+
*
|
|
76
|
+
* // Set up handlers first
|
|
77
|
+
* processor.on('connected', () => console.log('Connected!'));
|
|
78
|
+
* processor.on('error', (err) => console.error('Error:', err));
|
|
79
|
+
*
|
|
80
|
+
* // Then connect
|
|
81
|
+
* await processor.connect();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
create(config) {
|
|
85
|
+
return new MediaProcessor_1.MediaProcessor(config);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
// =============================================================================
|
|
89
|
+
// Type Guard Exports
|
|
90
|
+
// =============================================================================
|
|
91
|
+
var types_1 = require("./types");
|
|
92
|
+
Object.defineProperty(exports, "isProgressMessage", { enumerable: true, get: function () { return types_1.isProgressMessage; } });
|
|
93
|
+
Object.defineProperty(exports, "isResultMessage", { enumerable: true, get: function () { return types_1.isResultMessage; } });
|
|
94
|
+
Object.defineProperty(exports, "isErrorMessage", { enumerable: true, get: function () { return types_1.isErrorMessage; } });
|
|
95
|
+
Object.defineProperty(exports, "isImageResult", { enumerable: true, get: function () { return types_1.isImageResult; } });
|
|
96
|
+
Object.defineProperty(exports, "isVideoResult", { enumerable: true, get: function () { return types_1.isVideoResult; } });
|
|
97
|
+
Object.defineProperty(exports, "isZipResult", { enumerable: true, get: function () { return types_1.isZipResult; } });
|
|
98
|
+
// =============================================================================
|
|
99
|
+
// Error Exports
|
|
100
|
+
// =============================================================================
|
|
101
|
+
var errors_1 = require("./errors");
|
|
102
|
+
Object.defineProperty(exports, "MediaProcessorError", { enumerable: true, get: function () { return errors_1.MediaProcessorError; } });
|
|
103
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_1.ConnectionError; } });
|
|
104
|
+
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return errors_1.ConfigurationError; } });
|
|
105
|
+
Object.defineProperty(exports, "RequestError", { enumerable: true, get: function () { return errors_1.RequestError; } });
|
|
106
|
+
Object.defineProperty(exports, "ProcessingError", { enumerable: true, get: function () { return errors_1.ProcessingError; } });
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAEH,qDAAkD;AA+DzC,+FA/DA,+BAAc,OA+DA;AA5DvB,gFAAgF;AAChF,uCAAuC;AACvC,gFAAgF;AAEhF;;GAEG;AACU,QAAA,eAAe,GAAG;IAC7B;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,OAAO,CAAC,MAA4B;QACxC,MAAM,SAAS,GAAG,IAAI,+BAAc,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,MAA4B;QACjC,OAAO,IAAI,+BAAc,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;CACF,CAAC;AA8DF,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,iCAOiB;AANf,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AACf,uGAAA,cAAc,OAAA;AACd,sGAAA,aAAa,OAAA;AACb,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AAGb,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,mCAMkB;AALhB,6GAAA,mBAAmB,OAAA;AACnB,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,sGAAA,YAAY,OAAA;AACZ,yGAAA,eAAe,OAAA"}
|