ugcinc 2.16.1 → 2.18.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/dist/base.d.ts CHANGED
@@ -6,9 +6,10 @@ export interface ClientConfig {
6
6
  export declare class BaseClient {
7
7
  protected apiKey: string;
8
8
  protected orgId?: string;
9
- private readonly baseUrl;
9
+ protected readonly baseUrl = "https://api.ugc.inc";
10
10
  constructor(config: ClientConfig);
11
11
  protected request<T>(endpoint: string, options?: RequestInit): Promise<ApiResponse<T>>;
12
12
  protected post<T>(endpoint: string, body?: unknown): Promise<ApiResponse<T>>;
13
13
  protected get<T>(endpoint: string): Promise<ApiResponse<T>>;
14
+ protected postFormData<T>(endpoint: string, formData: FormData): Promise<ApiResponse<T>>;
14
15
  }
package/dist/base.js CHANGED
@@ -67,5 +67,52 @@ class BaseClient {
67
67
  method: 'GET',
68
68
  });
69
69
  }
70
+ async postFormData(endpoint, formData) {
71
+ let url = `${this.baseUrl}${endpoint}`;
72
+ // If orgId is provided, treat apiKey as admin key and add orgId as query param
73
+ if (this.orgId) {
74
+ const separator = endpoint.includes('?') ? '&' : '?';
75
+ url = `${url}${separator}orgId=${encodeURIComponent(this.orgId)}`;
76
+ }
77
+ const headers = {};
78
+ // Use admin key header if orgId is provided, otherwise use Bearer token
79
+ if (this.orgId) {
80
+ headers['x-api-key'] = this.apiKey;
81
+ }
82
+ else {
83
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
84
+ }
85
+ try {
86
+ const response = await fetch(url, {
87
+ method: 'POST',
88
+ headers,
89
+ body: formData,
90
+ });
91
+ const rawData = await response.json();
92
+ const isSuccess = response.ok && rawData.code >= 200 && rawData.code < 300;
93
+ if (isSuccess && rawData.data !== undefined) {
94
+ return {
95
+ ok: true,
96
+ code: rawData.code,
97
+ message: rawData.message ?? 'Success',
98
+ data: rawData.data,
99
+ };
100
+ }
101
+ else {
102
+ return {
103
+ ok: false,
104
+ code: rawData.code,
105
+ message: rawData.message ?? 'Request failed',
106
+ };
107
+ }
108
+ }
109
+ catch (error) {
110
+ return {
111
+ ok: false,
112
+ code: 500,
113
+ message: error instanceof Error ? error.message : 'Unknown error occurred',
114
+ };
115
+ }
116
+ }
70
117
  }
71
118
  exports.BaseClient = BaseClient;
package/dist/client.d.ts CHANGED
@@ -5,6 +5,7 @@ import { StatsClient } from './stats';
5
5
  import { OrganizationClient } from './org';
6
6
  import { RenderClient } from './render';
7
7
  import { AutomationsClient } from './automations';
8
+ import { MediaClient } from './media';
8
9
  import type { ClientConfig } from './base';
9
10
  /**
10
11
  * Main UGC Inc API Client
@@ -60,5 +61,9 @@ export declare class UGCClient {
60
61
  * Client for automation workflow operations
61
62
  */
62
63
  automations: AutomationsClient;
64
+ /**
65
+ * Client for media operations
66
+ */
67
+ media: MediaClient;
63
68
  constructor(config: ClientConfig);
64
69
  }
package/dist/client.js CHANGED
@@ -8,6 +8,7 @@ const stats_1 = require("./stats");
8
8
  const org_1 = require("./org");
9
9
  const render_1 = require("./render");
10
10
  const automations_1 = require("./automations");
11
+ const media_1 = require("./media");
11
12
  /**
12
13
  * Main UGC Inc API Client
13
14
  *
@@ -42,6 +43,7 @@ class UGCClient {
42
43
  this.org = new org_1.OrganizationClient(config);
43
44
  this.render = new render_1.RenderClient(config);
44
45
  this.automations = new automations_1.AutomationsClient(config);
46
+ this.media = new media_1.MediaClient(config);
45
47
  }
46
48
  }
47
49
  exports.UGCClient = UGCClient;
package/dist/index.d.ts CHANGED
@@ -11,5 +11,6 @@ export { StatsClient } from './stats';
11
11
  export { OrganizationClient } from './org';
12
12
  export { RenderClient } from './render';
13
13
  export { AutomationsClient, getAllNodes, getNodeByType } from './automations';
14
+ export { MediaClient } from './media';
14
15
  export type { ClientConfig, } from './base';
15
- export type { SuccessResponse, ErrorResponse, ApiResponse, Account, AccountStat, AccountTask, EditProfileInfo, Task, TaskType, Post, PostType, PostStat, ApiKey, EditorConfig, VideoEditorConfig, ImageEditorConfig, EditorChannel, TimeValue, BaseSegmentProps, VisualSegmentProps, EditorSegment, VideoSegment, AudioSegment, ImageSegment, TextSegment, StaticSegment, RenderJobSubmit, RenderVideoRequest, RenderImageRequest, RenderJobResponse, RenderJobStatus, GetAccountsParams, GetAccountStatsParams, GetAccountStatusParams, UpdateAccountInfoParams, UpdateAccountSocialParams, GetTasksParams, GetPostsParams, CreateSlideshowParams, GetPostStatsParams, GetPostStatusParams, CreateVideoParams, RefreshStatsParams, RefreshStatsResponse, RefreshStatsError, MediaType, NodePort, NodeControlConfig, NodeTypeEnum, WorkflowNodeDefinition, WorkflowDefinition, CanvasState, AutomationTemplate, AutomationRun, NodeRun, OutputSchemaProperty, SelectionMode, ExhaustionBehavior, SelectionConfig, SelectionState, OutputMode, } from './types';
16
+ export type { SuccessResponse, ErrorResponse, ApiResponse, Account, AccountStat, AccountTask, EditProfileInfo, Task, TaskType, Post, PostType, PostStat, ApiKey, EditorConfig, VideoEditorConfig, ImageEditorConfig, EditorChannel, TimeValue, BaseSegmentProps, VisualSegmentProps, EditorSegment, VideoSegment, AudioSegment, ImageSegment, TextSegment, StaticSegment, RenderJobSubmit, RenderVideoRequest, RenderImageRequest, RenderJobResponse, RenderJobStatus, GetAccountsParams, GetAccountStatsParams, GetAccountStatusParams, UpdateAccountInfoParams, UpdateAccountSocialParams, GetTasksParams, GetPostsParams, CreateSlideshowParams, GetPostStatsParams, GetPostStatusParams, CreateVideoParams, RefreshStatsParams, RefreshStatsResponse, RefreshStatsError, MediaType, NodePort, NodeControlConfig, NodeTypeEnum, WorkflowNodeDefinition, WorkflowDefinition, CanvasState, AutomationTemplate, AutomationRun, NodeRun, OutputSchemaProperty, SelectionMode, ExhaustionBehavior, SelectionConfig, SelectionState, OutputMode, UserMedia, SocialAudio, Media, GetMediaParams, UploadMediaParams, UploadMediaResponse, UpdateMediaTagParams, DeleteMediaParams, DeleteMediaResponse, CreateSocialAudioParams, CreateMediaFromUrlParams, } from './types';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * Official TypeScript/JavaScript client for the UGC Inc API
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.getNodeByType = exports.getAllNodes = exports.AutomationsClient = exports.RenderClient = exports.OrganizationClient = exports.StatsClient = exports.PostsClient = exports.TasksClient = exports.AccountsClient = exports.UGCClient = void 0;
8
+ exports.MediaClient = exports.getNodeByType = exports.getAllNodes = exports.AutomationsClient = exports.RenderClient = exports.OrganizationClient = exports.StatsClient = exports.PostsClient = exports.TasksClient = exports.AccountsClient = exports.UGCClient = void 0;
9
9
  var client_1 = require("./client");
10
10
  Object.defineProperty(exports, "UGCClient", { enumerable: true, get: function () { return client_1.UGCClient; } });
11
11
  var accounts_1 = require("./accounts");
@@ -24,3 +24,5 @@ var automations_1 = require("./automations");
24
24
  Object.defineProperty(exports, "AutomationsClient", { enumerable: true, get: function () { return automations_1.AutomationsClient; } });
25
25
  Object.defineProperty(exports, "getAllNodes", { enumerable: true, get: function () { return automations_1.getAllNodes; } });
26
26
  Object.defineProperty(exports, "getNodeByType", { enumerable: true, get: function () { return automations_1.getNodeByType; } });
27
+ var media_1 = require("./media");
28
+ Object.defineProperty(exports, "MediaClient", { enumerable: true, get: function () { return media_1.MediaClient; } });
@@ -0,0 +1,40 @@
1
+ import { BaseClient } from './base';
2
+ import type { Media, UserMedia, SocialAudio, GetMediaParams, UploadMediaResponse, UpdateMediaTagParams, DeleteMediaParams, DeleteMediaResponse, CreateSocialAudioParams, CreateMediaFromUrlParams, ApiResponse } from './types';
3
+ /**
4
+ * Client for managing media files
5
+ */
6
+ export declare class MediaClient extends BaseClient {
7
+ /**
8
+ * Get all media for the organization
9
+ * Returns both user_media and social_audio combined
10
+ */
11
+ getMedia(params?: GetMediaParams): Promise<ApiResponse<Media[]>>;
12
+ /**
13
+ * Create media from URL(s)
14
+ * Downloads files from the provided URLs and uploads them to storage
15
+ * Supports both single url and multiple urls
16
+ */
17
+ create(params: CreateMediaFromUrlParams): Promise<ApiResponse<UploadMediaResponse>>;
18
+ /**
19
+ * Upload media files directly
20
+ * Supports uploading multiple files at once
21
+ * Files are uploaded to Vercel Blob storage
22
+ */
23
+ upload(files: File[], tag?: string): Promise<ApiResponse<UploadMediaResponse>>;
24
+ /**
25
+ * Update the tag on a media item
26
+ * Works for both user_media and social_audio
27
+ */
28
+ updateTag(params: UpdateMediaTagParams): Promise<ApiResponse<UserMedia | SocialAudio>>;
29
+ /**
30
+ * Delete one or more media items
31
+ * Supports both single id and bulk ids
32
+ * Also deletes the files from blob storage
33
+ */
34
+ delete(params: DeleteMediaParams): Promise<ApiResponse<DeleteMediaResponse>>;
35
+ /**
36
+ * Create a social audio from a TikTok URL
37
+ * Extracts audio and cover image from TikTok video or music URL
38
+ */
39
+ createSocialAudio(params: CreateSocialAudioParams): Promise<ApiResponse<SocialAudio>>;
40
+ }
package/dist/media.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaClient = void 0;
4
+ const base_1 = require("./base");
5
+ /**
6
+ * Client for managing media files
7
+ */
8
+ class MediaClient extends base_1.BaseClient {
9
+ /**
10
+ * Get all media for the organization
11
+ * Returns both user_media and social_audio combined
12
+ */
13
+ async getMedia(params) {
14
+ return this.post('/media', params ?? {});
15
+ }
16
+ /**
17
+ * Create media from URL(s)
18
+ * Downloads files from the provided URLs and uploads them to storage
19
+ * Supports both single url and multiple urls
20
+ */
21
+ async create(params) {
22
+ return this.post('/media/create', params);
23
+ }
24
+ /**
25
+ * Upload media files directly
26
+ * Supports uploading multiple files at once
27
+ * Files are uploaded to Vercel Blob storage
28
+ */
29
+ async upload(files, tag) {
30
+ const formData = new FormData();
31
+ for (const file of files) {
32
+ formData.append('file', file);
33
+ }
34
+ if (tag) {
35
+ formData.append('tag', tag);
36
+ }
37
+ return this.postFormData('/media/create/upload', formData);
38
+ }
39
+ /**
40
+ * Update the tag on a media item
41
+ * Works for both user_media and social_audio
42
+ */
43
+ async updateTag(params) {
44
+ return this.post('/media/update-tag', params);
45
+ }
46
+ /**
47
+ * Delete one or more media items
48
+ * Supports both single id and bulk ids
49
+ * Also deletes the files from blob storage
50
+ */
51
+ async delete(params) {
52
+ return this.post('/media/delete', params);
53
+ }
54
+ /**
55
+ * Create a social audio from a TikTok URL
56
+ * Extracts audio and cover image from TikTok video or music URL
57
+ */
58
+ async createSocialAudio(params) {
59
+ return this.post('/media/social-audio', params);
60
+ }
61
+ }
62
+ exports.MediaClient = MediaClient;
package/dist/types.d.ts CHANGED
@@ -639,4 +639,72 @@ export interface NodeRun {
639
639
  created_at: string;
640
640
  completed_at: string | null;
641
641
  }
642
+ /**
643
+ * Media types
644
+ */
645
+ export interface UserMedia {
646
+ id: string;
647
+ org_id: string;
648
+ name: string | null;
649
+ tag: string | null;
650
+ type: 'video' | 'image' | 'audio' | null;
651
+ url: string;
652
+ created_at: string;
653
+ media_type: 'user_media';
654
+ }
655
+ export interface SocialAudio {
656
+ id: string;
657
+ org_id: string;
658
+ name: string | null;
659
+ tag: string | null;
660
+ social_post_link: string | null;
661
+ social_audio_link: string | null;
662
+ platform_type: 'tiktok' | null;
663
+ preview_url: string | null;
664
+ audio_url: string | null;
665
+ created_at: string;
666
+ media_type: 'social_audio';
667
+ type: 'social_audio';
668
+ }
669
+ export type Media = UserMedia | SocialAudio;
670
+ export interface GetMediaParams {
671
+ tag?: string;
672
+ }
673
+ export interface UploadMediaParams {
674
+ files: File[];
675
+ tag?: string;
676
+ }
677
+ export interface UploadMediaResponse {
678
+ data: UserMedia[];
679
+ failed?: Array<{
680
+ name: string;
681
+ error: string;
682
+ }>;
683
+ message: string;
684
+ }
685
+ export interface UpdateMediaTagParams {
686
+ id: string;
687
+ tag: string;
688
+ }
689
+ export interface DeleteMediaParams {
690
+ id?: string;
691
+ ids?: string[];
692
+ }
693
+ export interface DeleteMediaResponse {
694
+ deleted: string[];
695
+ failed?: Array<{
696
+ id: string;
697
+ message: string;
698
+ }>;
699
+ message: string;
700
+ }
701
+ export interface CreateSocialAudioParams {
702
+ url: string;
703
+ tag?: string;
704
+ }
705
+ export interface CreateMediaFromUrlParams {
706
+ url?: string;
707
+ urls?: string[];
708
+ tag?: string;
709
+ }
642
710
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc",
3
- "version": "2.16.1",
3
+ "version": "2.18.0",
4
4
  "description": "TypeScript/JavaScript client for the UGC Inc API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,9 +24,6 @@
24
24
  "@types/node": "^20.0.0",
25
25
  "typescript": "^5.0.0"
26
26
  },
27
- "dependencies": {
28
- "ugcinc": "^1.7.0"
29
- },
30
27
  "files": [
31
28
  "dist",
32
29
  "README.md"