@indreamai/client 0.1.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,219 @@
1
+ type TExportRatio = '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | 'custom';
2
+ type TExportFormat = 'mp4' | 'webm' | 'gif' | 'mp3' | 'wav' | 'aac';
3
+ type TTaskStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'PAUSED' | 'CANCELED';
4
+ type TExportWebhookEventType = 'EXPORT_STARTED' | 'EXPORT_COMPLETED' | 'EXPORT_FAILED';
5
+ interface IApiProblem {
6
+ type: string;
7
+ title: string;
8
+ status: number;
9
+ detail: string;
10
+ errorCode?: string;
11
+ }
12
+ interface IApiEnvelope<T> {
13
+ data: T;
14
+ meta: Record<string, unknown>;
15
+ }
16
+ interface ICreateExportRequest {
17
+ clientTaskId?: string;
18
+ editorState: Record<string, unknown>;
19
+ stateVersion?: string;
20
+ fps: 30 | 60;
21
+ compositionWidth?: number;
22
+ compositionHeight?: number;
23
+ ratio: TExportRatio;
24
+ scale: number;
25
+ format: TExportFormat;
26
+ callbackUrl?: string;
27
+ callbackHeaders?: Record<string, string>;
28
+ }
29
+ interface ICreateExportResponse {
30
+ taskId: string;
31
+ createdAt: string;
32
+ durationSeconds: number;
33
+ billedStandardSeconds: number;
34
+ chargedCredits: string;
35
+ }
36
+ interface IExportTask {
37
+ taskId: string;
38
+ createdByApiKeyId: string | null;
39
+ clientTaskId: string | null;
40
+ status: TTaskStatus;
41
+ progress: number;
42
+ error: string | null;
43
+ outputUrl: string | null;
44
+ durationSeconds: number;
45
+ billedStandardSeconds: number;
46
+ chargedCredits: string;
47
+ callbackUrl: string | null;
48
+ createdAt: string;
49
+ completedAt: string | null;
50
+ }
51
+ interface IListExportsResponse {
52
+ items: IExportTask[];
53
+ nextPageCursor: string | null;
54
+ }
55
+ interface IExportWebhookEvent {
56
+ eventType: TExportWebhookEventType;
57
+ occurredAt: string;
58
+ task: IExportTask;
59
+ }
60
+ interface IEditorCapabilities {
61
+ version: string;
62
+ animations: string[];
63
+ transitions: string[];
64
+ transitionPresets: Array<{
65
+ id: string;
66
+ type: string;
67
+ label: string;
68
+ params?: Record<string, string | number | boolean>;
69
+ }>;
70
+ effects: string[];
71
+ effectPresets: Array<{
72
+ id: string;
73
+ type: string;
74
+ label: string;
75
+ defaultDurationInSeconds?: number;
76
+ defaultIntensity?: number;
77
+ params?: Record<string, string | number | boolean>;
78
+ }>;
79
+ filters: string[];
80
+ filterPresets: Array<{
81
+ id: string;
82
+ type: string;
83
+ label: string;
84
+ defaultDurationInSeconds?: number;
85
+ defaultIntensity?: number;
86
+ params?: Record<string, string | number | boolean>;
87
+ }>;
88
+ shapes: string[];
89
+ backgroundPresets: {
90
+ colors: string[];
91
+ gradients: string[];
92
+ images: string[];
93
+ blurLevels: number[];
94
+ };
95
+ illustrations: string[];
96
+ }
97
+ interface IEditorValidationError {
98
+ code: string;
99
+ path: string;
100
+ message: string;
101
+ }
102
+ interface IEditorValidationResult {
103
+ valid: boolean;
104
+ errors: IEditorValidationError[];
105
+ }
106
+ interface IClientOptions {
107
+ apiKey: string;
108
+ baseURL?: string;
109
+ timeout?: number;
110
+ maxRetries?: number;
111
+ pollIntervalMs?: number;
112
+ fetch?: typeof fetch;
113
+ }
114
+ interface IRequestOptions {
115
+ signal?: AbortSignal;
116
+ }
117
+ interface ICreateRequestOptions extends IRequestOptions {
118
+ idempotencyKey?: string;
119
+ }
120
+ interface IWaitOptions {
121
+ timeoutMs?: number;
122
+ pollIntervalMs?: number;
123
+ signal?: AbortSignal;
124
+ }
125
+
126
+ declare class ExportsResource {
127
+ private readonly client;
128
+ constructor(client: IndreamClient);
129
+ create(payload: ICreateExportRequest, options?: ICreateRequestOptions): Promise<ICreateExportResponse>;
130
+ get(taskId: string, options?: {
131
+ signal?: AbortSignal;
132
+ }): Promise<IExportTask>;
133
+ list(params?: {
134
+ pageSize?: number;
135
+ pageCursor?: string;
136
+ createdByApiKeyId?: string;
137
+ signal?: AbortSignal;
138
+ }): Promise<IListExportsResponse>;
139
+ wait(taskId: string, options?: IWaitOptions): Promise<IExportTask>;
140
+ }
141
+
142
+ declare class EditorResource {
143
+ private readonly client;
144
+ constructor(client: IndreamClient);
145
+ capabilities(options?: IRequestOptions): Promise<IEditorCapabilities>;
146
+ validate(editorState: Record<string, unknown>, options?: IRequestOptions): Promise<IEditorValidationResult>;
147
+ }
148
+
149
+ declare class IndreamClient {
150
+ readonly apiKey: string;
151
+ readonly baseURL: string;
152
+ readonly timeout: number;
153
+ readonly maxRetries: number;
154
+ readonly pollIntervalMs: number;
155
+ readonly fetchImpl: typeof fetch;
156
+ readonly exports: ExportsResource;
157
+ readonly editor: EditorResource;
158
+ constructor(options: IClientOptions);
159
+ request<T>(path: string, init: {
160
+ method: 'GET' | 'POST';
161
+ body?: unknown;
162
+ headers?: Record<string, string>;
163
+ idempotencyKey?: string;
164
+ signal?: AbortSignal;
165
+ skipRetry?: boolean;
166
+ }): Promise<T>;
167
+ requestEnvelope<T>(path: string, init: {
168
+ method: 'GET' | 'POST';
169
+ body?: unknown;
170
+ headers?: Record<string, string>;
171
+ idempotencyKey?: string;
172
+ signal?: AbortSignal;
173
+ skipRetry?: boolean;
174
+ }): Promise<IApiEnvelope<T>>;
175
+ }
176
+
177
+ declare class APIError extends Error {
178
+ readonly status: number;
179
+ readonly type: string;
180
+ readonly detail: string;
181
+ readonly errorCode?: string;
182
+ constructor(problem: IApiProblem);
183
+ }
184
+ declare class AuthError extends APIError {
185
+ constructor(problem: IApiProblem);
186
+ }
187
+ declare class ValidationError extends APIError {
188
+ constructor(problem: IApiProblem);
189
+ }
190
+ declare class RateLimitError extends APIError {
191
+ constructor(problem: IApiProblem);
192
+ }
193
+ declare const toApiProblem: (status: number, payload: unknown) => IApiProblem;
194
+ declare const createApiError: (status: number, payload: unknown) => APIError;
195
+
196
+ type TWebhookHeaderValue = string | string[] | null | undefined;
197
+ type TWebhookHeaders = Headers | Record<string, TWebhookHeaderValue>;
198
+ interface IVerifyExportWebhookSignatureParams {
199
+ webhookSecret: string;
200
+ timestamp: string;
201
+ rawBody: string;
202
+ signature: string;
203
+ }
204
+ interface IVerifyExportWebhookRequestParams {
205
+ webhookSecret: string;
206
+ rawBody: string;
207
+ headers: TWebhookHeaders;
208
+ maxSkewSeconds?: number;
209
+ nowTimestampSeconds?: number;
210
+ }
211
+ declare const isExportWebhookEventType: (value: unknown) => value is TExportWebhookEventType;
212
+ declare const isTaskStatus: (value: unknown) => value is TTaskStatus;
213
+ declare const isExportTaskSnapshot: (value: unknown) => value is IExportTask;
214
+ declare const isExportWebhookEvent: (value: unknown) => value is IExportWebhookEvent;
215
+ declare const parseExportWebhookEvent: (value: unknown) => IExportWebhookEvent;
216
+ declare const verifyExportWebhookSignature: ({ webhookSecret, timestamp, rawBody, signature, }: IVerifyExportWebhookSignatureParams) => Promise<boolean>;
217
+ declare const verifyExportWebhookRequest: ({ webhookSecret, rawBody, headers, maxSkewSeconds, nowTimestampSeconds, }: IVerifyExportWebhookRequestParams) => Promise<boolean>;
218
+
219
+ export { APIError, AuthError, type IApiEnvelope, type IApiProblem, type IClientOptions, type ICreateExportRequest, type ICreateExportResponse, type ICreateRequestOptions, type IEditorCapabilities, type IEditorValidationError, type IEditorValidationResult, type IExportTask, type IExportWebhookEvent, type IListExportsResponse, type IRequestOptions, type IVerifyExportWebhookRequestParams, type IVerifyExportWebhookSignatureParams, type IWaitOptions, IndreamClient, RateLimitError, type TExportFormat, type TExportRatio, type TExportWebhookEventType, type TTaskStatus, type TWebhookHeaders, ValidationError, createApiError, isExportTaskSnapshot, isExportWebhookEvent, isExportWebhookEventType, isTaskStatus, parseExportWebhookEvent, toApiProblem, verifyExportWebhookRequest, verifyExportWebhookSignature };
@@ -0,0 +1,219 @@
1
+ type TExportRatio = '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | 'custom';
2
+ type TExportFormat = 'mp4' | 'webm' | 'gif' | 'mp3' | 'wav' | 'aac';
3
+ type TTaskStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED' | 'PAUSED' | 'CANCELED';
4
+ type TExportWebhookEventType = 'EXPORT_STARTED' | 'EXPORT_COMPLETED' | 'EXPORT_FAILED';
5
+ interface IApiProblem {
6
+ type: string;
7
+ title: string;
8
+ status: number;
9
+ detail: string;
10
+ errorCode?: string;
11
+ }
12
+ interface IApiEnvelope<T> {
13
+ data: T;
14
+ meta: Record<string, unknown>;
15
+ }
16
+ interface ICreateExportRequest {
17
+ clientTaskId?: string;
18
+ editorState: Record<string, unknown>;
19
+ stateVersion?: string;
20
+ fps: 30 | 60;
21
+ compositionWidth?: number;
22
+ compositionHeight?: number;
23
+ ratio: TExportRatio;
24
+ scale: number;
25
+ format: TExportFormat;
26
+ callbackUrl?: string;
27
+ callbackHeaders?: Record<string, string>;
28
+ }
29
+ interface ICreateExportResponse {
30
+ taskId: string;
31
+ createdAt: string;
32
+ durationSeconds: number;
33
+ billedStandardSeconds: number;
34
+ chargedCredits: string;
35
+ }
36
+ interface IExportTask {
37
+ taskId: string;
38
+ createdByApiKeyId: string | null;
39
+ clientTaskId: string | null;
40
+ status: TTaskStatus;
41
+ progress: number;
42
+ error: string | null;
43
+ outputUrl: string | null;
44
+ durationSeconds: number;
45
+ billedStandardSeconds: number;
46
+ chargedCredits: string;
47
+ callbackUrl: string | null;
48
+ createdAt: string;
49
+ completedAt: string | null;
50
+ }
51
+ interface IListExportsResponse {
52
+ items: IExportTask[];
53
+ nextPageCursor: string | null;
54
+ }
55
+ interface IExportWebhookEvent {
56
+ eventType: TExportWebhookEventType;
57
+ occurredAt: string;
58
+ task: IExportTask;
59
+ }
60
+ interface IEditorCapabilities {
61
+ version: string;
62
+ animations: string[];
63
+ transitions: string[];
64
+ transitionPresets: Array<{
65
+ id: string;
66
+ type: string;
67
+ label: string;
68
+ params?: Record<string, string | number | boolean>;
69
+ }>;
70
+ effects: string[];
71
+ effectPresets: Array<{
72
+ id: string;
73
+ type: string;
74
+ label: string;
75
+ defaultDurationInSeconds?: number;
76
+ defaultIntensity?: number;
77
+ params?: Record<string, string | number | boolean>;
78
+ }>;
79
+ filters: string[];
80
+ filterPresets: Array<{
81
+ id: string;
82
+ type: string;
83
+ label: string;
84
+ defaultDurationInSeconds?: number;
85
+ defaultIntensity?: number;
86
+ params?: Record<string, string | number | boolean>;
87
+ }>;
88
+ shapes: string[];
89
+ backgroundPresets: {
90
+ colors: string[];
91
+ gradients: string[];
92
+ images: string[];
93
+ blurLevels: number[];
94
+ };
95
+ illustrations: string[];
96
+ }
97
+ interface IEditorValidationError {
98
+ code: string;
99
+ path: string;
100
+ message: string;
101
+ }
102
+ interface IEditorValidationResult {
103
+ valid: boolean;
104
+ errors: IEditorValidationError[];
105
+ }
106
+ interface IClientOptions {
107
+ apiKey: string;
108
+ baseURL?: string;
109
+ timeout?: number;
110
+ maxRetries?: number;
111
+ pollIntervalMs?: number;
112
+ fetch?: typeof fetch;
113
+ }
114
+ interface IRequestOptions {
115
+ signal?: AbortSignal;
116
+ }
117
+ interface ICreateRequestOptions extends IRequestOptions {
118
+ idempotencyKey?: string;
119
+ }
120
+ interface IWaitOptions {
121
+ timeoutMs?: number;
122
+ pollIntervalMs?: number;
123
+ signal?: AbortSignal;
124
+ }
125
+
126
+ declare class ExportsResource {
127
+ private readonly client;
128
+ constructor(client: IndreamClient);
129
+ create(payload: ICreateExportRequest, options?: ICreateRequestOptions): Promise<ICreateExportResponse>;
130
+ get(taskId: string, options?: {
131
+ signal?: AbortSignal;
132
+ }): Promise<IExportTask>;
133
+ list(params?: {
134
+ pageSize?: number;
135
+ pageCursor?: string;
136
+ createdByApiKeyId?: string;
137
+ signal?: AbortSignal;
138
+ }): Promise<IListExportsResponse>;
139
+ wait(taskId: string, options?: IWaitOptions): Promise<IExportTask>;
140
+ }
141
+
142
+ declare class EditorResource {
143
+ private readonly client;
144
+ constructor(client: IndreamClient);
145
+ capabilities(options?: IRequestOptions): Promise<IEditorCapabilities>;
146
+ validate(editorState: Record<string, unknown>, options?: IRequestOptions): Promise<IEditorValidationResult>;
147
+ }
148
+
149
+ declare class IndreamClient {
150
+ readonly apiKey: string;
151
+ readonly baseURL: string;
152
+ readonly timeout: number;
153
+ readonly maxRetries: number;
154
+ readonly pollIntervalMs: number;
155
+ readonly fetchImpl: typeof fetch;
156
+ readonly exports: ExportsResource;
157
+ readonly editor: EditorResource;
158
+ constructor(options: IClientOptions);
159
+ request<T>(path: string, init: {
160
+ method: 'GET' | 'POST';
161
+ body?: unknown;
162
+ headers?: Record<string, string>;
163
+ idempotencyKey?: string;
164
+ signal?: AbortSignal;
165
+ skipRetry?: boolean;
166
+ }): Promise<T>;
167
+ requestEnvelope<T>(path: string, init: {
168
+ method: 'GET' | 'POST';
169
+ body?: unknown;
170
+ headers?: Record<string, string>;
171
+ idempotencyKey?: string;
172
+ signal?: AbortSignal;
173
+ skipRetry?: boolean;
174
+ }): Promise<IApiEnvelope<T>>;
175
+ }
176
+
177
+ declare class APIError extends Error {
178
+ readonly status: number;
179
+ readonly type: string;
180
+ readonly detail: string;
181
+ readonly errorCode?: string;
182
+ constructor(problem: IApiProblem);
183
+ }
184
+ declare class AuthError extends APIError {
185
+ constructor(problem: IApiProblem);
186
+ }
187
+ declare class ValidationError extends APIError {
188
+ constructor(problem: IApiProblem);
189
+ }
190
+ declare class RateLimitError extends APIError {
191
+ constructor(problem: IApiProblem);
192
+ }
193
+ declare const toApiProblem: (status: number, payload: unknown) => IApiProblem;
194
+ declare const createApiError: (status: number, payload: unknown) => APIError;
195
+
196
+ type TWebhookHeaderValue = string | string[] | null | undefined;
197
+ type TWebhookHeaders = Headers | Record<string, TWebhookHeaderValue>;
198
+ interface IVerifyExportWebhookSignatureParams {
199
+ webhookSecret: string;
200
+ timestamp: string;
201
+ rawBody: string;
202
+ signature: string;
203
+ }
204
+ interface IVerifyExportWebhookRequestParams {
205
+ webhookSecret: string;
206
+ rawBody: string;
207
+ headers: TWebhookHeaders;
208
+ maxSkewSeconds?: number;
209
+ nowTimestampSeconds?: number;
210
+ }
211
+ declare const isExportWebhookEventType: (value: unknown) => value is TExportWebhookEventType;
212
+ declare const isTaskStatus: (value: unknown) => value is TTaskStatus;
213
+ declare const isExportTaskSnapshot: (value: unknown) => value is IExportTask;
214
+ declare const isExportWebhookEvent: (value: unknown) => value is IExportWebhookEvent;
215
+ declare const parseExportWebhookEvent: (value: unknown) => IExportWebhookEvent;
216
+ declare const verifyExportWebhookSignature: ({ webhookSecret, timestamp, rawBody, signature, }: IVerifyExportWebhookSignatureParams) => Promise<boolean>;
217
+ declare const verifyExportWebhookRequest: ({ webhookSecret, rawBody, headers, maxSkewSeconds, nowTimestampSeconds, }: IVerifyExportWebhookRequestParams) => Promise<boolean>;
218
+
219
+ export { APIError, AuthError, type IApiEnvelope, type IApiProblem, type IClientOptions, type ICreateExportRequest, type ICreateExportResponse, type ICreateRequestOptions, type IEditorCapabilities, type IEditorValidationError, type IEditorValidationResult, type IExportTask, type IExportWebhookEvent, type IListExportsResponse, type IRequestOptions, type IVerifyExportWebhookRequestParams, type IVerifyExportWebhookSignatureParams, type IWaitOptions, IndreamClient, RateLimitError, type TExportFormat, type TExportRatio, type TExportWebhookEventType, type TTaskStatus, type TWebhookHeaders, ValidationError, createApiError, isExportTaskSnapshot, isExportWebhookEvent, isExportWebhookEventType, isTaskStatus, parseExportWebhookEvent, toApiProblem, verifyExportWebhookRequest, verifyExportWebhookSignature };