totalum-api-sdk 3.0.4 → 3.0.6

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.
@@ -8,7 +8,7 @@ export interface ErrorResult {
8
8
  }[];
9
9
  }
10
10
  export interface TotalumApiResponse<T> {
11
- data?: T;
11
+ data: T;
12
12
  errors?: ErrorResult | null;
13
13
  metadata?: any;
14
14
  }
@@ -95,6 +95,85 @@ export interface DataProperties {
95
95
  export interface NestedQuery {
96
96
  [tableName: string]: any;
97
97
  }
98
+ /**
99
+ * Query options for sdk.crud.query(tableName, queryOptions).
100
+ * System keys use _ prefix. All other keys are property names (child expansions).
101
+ *
102
+ * Example:
103
+ * ```
104
+ * sdk.crud.query('company', {
105
+ * _filter: { country: "Spain" },
106
+ * _sort: { name: "asc" },
107
+ * _limit: 10,
108
+ * employee: {
109
+ * _has: true,
110
+ * _filter: { status: "active" },
111
+ * _count: true,
112
+ * task: true
113
+ * }
114
+ * })
115
+ * ```
116
+ */
117
+ export interface QueryOptions {
118
+ _filter?: QueryFilter;
119
+ _sort?: {
120
+ [key: string]: 'asc' | 'desc' | 1 | -1;
121
+ };
122
+ _limit?: number;
123
+ _offset?: number;
124
+ _has?: boolean | 'some' | 'none' | 'every';
125
+ _include?: boolean;
126
+ _count?: boolean;
127
+ _aggregate?: QueryAggregateOptions;
128
+ _groupBy?: string | string[];
129
+ _select?: {
130
+ [fieldName: string]: true;
131
+ };
132
+ _omit?: {
133
+ [fieldName: string]: true;
134
+ };
135
+ [propertyName: string]: QueryOptions | boolean | string | string[] | QueryFilter | QueryAggregateOptions | {
136
+ [key: string]: any;
137
+ } | number | undefined;
138
+ }
139
+ /**
140
+ * Object-based filter for query endpoint.
141
+ * Keys are field names, values are exact matches or operator objects.
142
+ * Use _or for OR conditions.
143
+ *
144
+ * Example:
145
+ * ```
146
+ * { name: "Acme", status: { in: ["active", "pending"] }, _or: [{ role: "admin" }, { role: "mod" }] }
147
+ * ```
148
+ */
149
+ export interface QueryFilter {
150
+ _or?: QueryFilter[];
151
+ [fieldName: string]: any;
152
+ }
153
+ /**
154
+ * Aggregation options (Prisma-style).
155
+ * Used with _aggregate in query().
156
+ *
157
+ * Example:
158
+ * ```
159
+ * { _sum: { amount: true }, _avg: { amount: true }, _count: true }
160
+ * ```
161
+ */
162
+ export interface QueryAggregateOptions {
163
+ _sum?: {
164
+ [fieldName: string]: true;
165
+ };
166
+ _avg?: {
167
+ [fieldName: string]: true;
168
+ };
169
+ _min?: {
170
+ [fieldName: string]: true;
171
+ };
172
+ _max?: {
173
+ [fieldName: string]: true;
174
+ };
175
+ _count?: true;
176
+ }
98
177
  export interface AuthOptions {
99
178
  token?: {
100
179
  accessToken: string;
@@ -115,6 +115,7 @@ export interface OpenAIChatCompletionResponse {
115
115
  }
116
116
  export interface ImageGenerationResponse {
117
117
  fileName: string;
118
+ imageUrl: string;
118
119
  }
119
120
  export interface LookupFilterResult {
120
121
  result: DataValues[] | number;
package/dist/index.d.ts CHANGED
@@ -6,10 +6,12 @@ import { CrudService } from './services/CrudService';
6
6
  import { NotificationService } from './services/NotificationService';
7
7
  import { StatisticService } from './services/StatisticService';
8
8
  import { EmailService } from './services/EmailService';
9
+ import { ScrappingService } from './services/ScrappingService';
9
10
  export * from './common/interfaces';
10
11
  export * from './common/response-types';
11
12
  export { EmailPayloadI } from './services/EmailService';
12
13
  export { TotalumError } from './common/fetch-client';
14
+ export { ScrapeRequestBody, ExtractRequestBody, ScreenshotRequestBody, SearchAndExtractRequestBody, ScrapeResponseData, ExtractResponseData, ScreenshotResponseData, SearchAndExtractResponseData, SearchAndExtractResult, ScrapflyPresetName, ScrapflyExtractionModel } from './services/ScrappingService';
13
15
  export declare class TotalumApiSdk {
14
16
  private authOptions;
15
17
  private _baseUrl;
@@ -22,6 +24,7 @@ export declare class TotalumApiSdk {
22
24
  notification: NotificationService;
23
25
  statistic: StatisticService;
24
26
  email: EmailService;
27
+ scrapping: ScrappingService;
25
28
  constructor(authOptions: AuthOptions);
26
29
  changeBaseUrl(newBaseUrl: string): void;
27
30
  private setRequestData;
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ const CrudService_1 = require("./services/CrudService");
23
23
  const NotificationService_1 = require("./services/NotificationService");
24
24
  const StatisticService_1 = require("./services/StatisticService");
25
25
  const EmailService_1 = require("./services/EmailService");
26
+ const ScrappingService_1 = require("./services/ScrappingService");
26
27
  // Export all interfaces and types
27
28
  __exportStar(require("./common/interfaces"), exports);
28
29
  __exportStar(require("./common/response-types"), exports);
@@ -69,6 +70,7 @@ class TotalumApiSdk {
69
70
  this.notification = new NotificationService_1.NotificationService(this.client);
70
71
  this.statistic = new StatisticService_1.StatisticService(this.client);
71
72
  this.email = new EmailService_1.EmailService(this.client);
73
+ this.scrapping = new ScrappingService_1.ScrappingService(this.client);
72
74
  }
73
75
  }
74
76
  exports.TotalumApiSdk = TotalumApiSdk;
@@ -1,4 +1,4 @@
1
- import { FilterSearchQueryI, NestedQuery, TotalumApiResponse } from "../common/interfaces";
1
+ import { FilterSearchQueryI, NestedQuery, QueryOptions, TotalumApiResponse } from "../common/interfaces";
2
2
  import { DataValues, DeleteObjectResponse, UpdatesRecordResponse } from "../common/response-types";
3
3
  import { FetchClient } from "../common/fetch-client";
4
4
  export declare class CrudService {
@@ -10,7 +10,7 @@ export declare class CrudService {
10
10
  * @param {string} id - The ID of the record.
11
11
  * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the record data.
12
12
  */
13
- getRecordById<T = DataValues>(tableName: string, id: string): Promise<TotalumApiResponse<T>>;
13
+ getRecordById<T = DataValues>(tableName: string, id: string): Promise<TotalumApiResponse<any>>;
14
14
  /**
15
15
  * Fetches the historic updates of a record by its ID.
16
16
  * @param {string} recordId - The ID of the record to fetch the historic updates.
@@ -20,18 +20,53 @@ export declare class CrudService {
20
20
  /**
21
21
  * Fetches records with optional filtering, sorting, and pagination.
22
22
  * The response data is an array of records. If returnCount is true, a metadata object with count is also returned.
23
+ * @deprecated Use `query()` instead, which supports nested relations, filtering, sorting, pagination, and more.
23
24
  * @param {string} tableName - The type of the record. (table name)
24
25
  * @param {FilterSearchQueryI} query - Optional query parameters for filtering.
25
26
  * @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to an array of records.
26
27
  */
27
- getRecords<T = DataValues>(tableName: string, query?: FilterSearchQueryI): Promise<TotalumApiResponse<T[]>>;
28
+ getRecords<T = DataValues>(tableName: string, query?: FilterSearchQueryI): Promise<TotalumApiResponse<any[]>>;
28
29
  /**
29
- * Fetches nested data across related tables.
30
+ * Fetches nested data across related tables. The query tree uses table names as keys.
31
+ * @deprecated Use `query()` instead, which supports nested relations, filtering, sorting, pagination, and more.
30
32
  * @param {NestedQuery} nestedQuery - The nested query structure.
31
33
  * @param {any} options - Optional configuration.
32
34
  * @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to nested data array.
33
35
  */
34
- getNestedData<T = DataValues>(nestedQuery: NestedQuery, options?: any): Promise<TotalumApiResponse<T[]>>;
36
+ getNestedData<T extends DataValues = DataValues>(nestedQuery: NestedQuery, options?: any): Promise<TotalumApiResponse<T[]>>;
37
+ /**
38
+ * Powerful query endpoint for fetching records with nested relations, filtering, sorting, pagination,
39
+ * parent filtering by children (_has), child counts (_count), and response shaping (_include).
40
+ *
41
+ * @param {string} tableName - The root table to query.
42
+ * @param {QueryOptions} queryOptions - Query options with _ prefixed system keys and property names as child expansions.
43
+ * @returns {Promise<TotalumApiResponse<T[]>>} - Nested records matching the query.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Simple: get companies with their employees
48
+ * sdk.crud.query('company', { employee: true })
49
+ *
50
+ * // Advanced: companies in Spain with active employees, count tasks
51
+ * sdk.crud.query('company', {
52
+ * _filter: { country: "Spain" },
53
+ * _sort: { name: "asc" },
54
+ * _limit: 10,
55
+ * employee: {
56
+ * _has: true,
57
+ * _filter: { status: { in: ["active", "probation"] } },
58
+ * _count: true,
59
+ * task: { _sort: { createdAt: "desc" }, _limit: 5 }
60
+ * }
61
+ * })
62
+ * ```
63
+ */
64
+ query<T extends DataValues = DataValues>(tableName: string, queryOptions?: QueryOptions): Promise<TotalumApiResponse<T[]>>;
65
+ /**
66
+ * Recursively encodes dots in _sort keys to @ so they survive express-mongo-sanitize.
67
+ * The server restores @ → . before processing.
68
+ */
69
+ private encodeSortKeys;
35
70
  /**
36
71
  * Deletes a record by its ID.
37
72
  * @param {string} tableName - The type of the record. (table name)
@@ -46,14 +81,14 @@ export declare class CrudService {
46
81
  * @param {T} properties - The properties to update.
47
82
  * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the updated record.
48
83
  */
49
- editRecordById<T = DataValues>(tableName: string, id: string, properties: Partial<T>): Promise<TotalumApiResponse<T>>;
84
+ editRecordById<T = DataValues>(tableName: string, id: string, properties: Partial<any>): Promise<TotalumApiResponse<any>>;
50
85
  /**
51
86
  * Creates a new record.
52
87
  * @param {string} tableName - The type of the record. (table name)
53
- * @param {T} record - The record data to create.
88
+ * @param {Partial<DataValues>} record - The record data to create.
54
89
  * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the created record.
55
90
  */
56
- createRecord<T = DataValues>(tableName: string, record: Partial<T>): Promise<TotalumApiResponse<T>>;
91
+ createRecord<T = DataValues>(tableName: string, record: Partial<any>): Promise<TotalumApiResponse<any>>;
57
92
  /**
58
93
  * Adds a many-to-many reference between records.
59
94
  * @param {string} type - The type id of the record (table name)
@@ -76,11 +111,12 @@ export declare class CrudService {
76
111
  dropManyToManyReferenceRecord(type: string, id: string, propertyName: string, referenceId: string): Promise<TotalumApiResponse<DeleteObjectResponse>>;
77
112
  /**
78
113
  * Gets many-to-many reference records with optional filtering.
114
+ * @deprecated Use `query()` instead, which supports nested relations including many-to-many.
79
115
  * @param {string} type - The type id of the record (table name)
80
116
  * @param {string} id - The id of the record that we want to get many to many references
81
117
  * @param {string} propertyName - The property that we want to get many to many references
82
118
  * @param {FilterSearchQueryI} query - The query to filter and sort the results
83
119
  * @returns {Promise<TotalumApiResponse<T[]>>}
84
120
  */
85
- getManyToManyReferencesRecords<T = DataValues>(type: string, id: string, propertyName: string, query?: FilterSearchQueryI): Promise<TotalumApiResponse<T[]>>;
121
+ getManyToManyReferencesRecords<T = DataValues>(type: string, id: string, propertyName: string, query?: FilterSearchQueryI): Promise<TotalumApiResponse<any[]>>;
86
122
  }
@@ -42,6 +42,7 @@ class CrudService {
42
42
  /**
43
43
  * Fetches records with optional filtering, sorting, and pagination.
44
44
  * The response data is an array of records. If returnCount is true, a metadata object with count is also returned.
45
+ * @deprecated Use `query()` instead, which supports nested relations, filtering, sorting, pagination, and more.
45
46
  * @param {string} tableName - The type of the record. (table name)
46
47
  * @param {FilterSearchQueryI} query - Optional query parameters for filtering.
47
48
  * @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to an array of records.
@@ -53,7 +54,8 @@ class CrudService {
53
54
  });
54
55
  }
55
56
  /**
56
- * Fetches nested data across related tables.
57
+ * Fetches nested data across related tables. The query tree uses table names as keys.
58
+ * @deprecated Use `query()` instead, which supports nested relations, filtering, sorting, pagination, and more.
57
59
  * @param {NestedQuery} nestedQuery - The nested query structure.
58
60
  * @param {any} options - Optional configuration.
59
61
  * @returns {Promise<TotalumApiResponse<T[]>>} - A promise that resolves to nested data array.
@@ -64,6 +66,65 @@ class CrudService {
64
66
  return this.client.post(url, { nestedQuery: nestedQuery, options: options });
65
67
  });
66
68
  }
69
+ /**
70
+ * Powerful query endpoint for fetching records with nested relations, filtering, sorting, pagination,
71
+ * parent filtering by children (_has), child counts (_count), and response shaping (_include).
72
+ *
73
+ * @param {string} tableName - The root table to query.
74
+ * @param {QueryOptions} queryOptions - Query options with _ prefixed system keys and property names as child expansions.
75
+ * @returns {Promise<TotalumApiResponse<T[]>>} - Nested records matching the query.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Simple: get companies with their employees
80
+ * sdk.crud.query('company', { employee: true })
81
+ *
82
+ * // Advanced: companies in Spain with active employees, count tasks
83
+ * sdk.crud.query('company', {
84
+ * _filter: { country: "Spain" },
85
+ * _sort: { name: "asc" },
86
+ * _limit: 10,
87
+ * employee: {
88
+ * _has: true,
89
+ * _filter: { status: { in: ["active", "probation"] } },
90
+ * _count: true,
91
+ * task: { _sort: { createdAt: "desc" }, _limit: 5 }
92
+ * }
93
+ * })
94
+ * ```
95
+ */
96
+ query(tableName, queryOptions) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.crud.query);
99
+ const sanitized = queryOptions ? this.encodeSortKeys(queryOptions) : {};
100
+ return this.client.post(url, { tableName, queryOptions: sanitized });
101
+ });
102
+ }
103
+ /**
104
+ * Recursively encodes dots in _sort keys to @ so they survive express-mongo-sanitize.
105
+ * The server restores @ → . before processing.
106
+ */
107
+ encodeSortKeys(options) {
108
+ if (!options || typeof options !== 'object')
109
+ return options;
110
+ const result = {};
111
+ for (const key of Object.keys(options)) {
112
+ if (key === '_sort' && typeof options[key] === 'object') {
113
+ const encoded = {};
114
+ for (const sortKey of Object.keys(options[key])) {
115
+ encoded[sortKey.replace(/\./g, '@')] = options[key][sortKey];
116
+ }
117
+ result[key] = encoded;
118
+ }
119
+ else if (typeof options[key] === 'object' && options[key] !== null && !Array.isArray(options[key])) {
120
+ result[key] = this.encodeSortKeys(options[key]);
121
+ }
122
+ else {
123
+ result[key] = options[key];
124
+ }
125
+ }
126
+ return result;
127
+ }
67
128
  /**
68
129
  * Deletes a record by its ID.
69
130
  * @param {string} tableName - The type of the record. (table name)
@@ -99,7 +160,7 @@ class CrudService {
99
160
  /**
100
161
  * Creates a new record.
101
162
  * @param {string} tableName - The type of the record. (table name)
102
- * @param {T} record - The record data to create.
163
+ * @param {Partial<DataValues>} record - The record data to create.
103
164
  * @returns {Promise<TotalumApiResponse<T>>} - A promise that resolves to the created record.
104
165
  */
105
166
  createRecord(tableName, record) {
@@ -146,6 +207,7 @@ class CrudService {
146
207
  }
147
208
  /**
148
209
  * Gets many-to-many reference records with optional filtering.
210
+ * @deprecated Use `query()` instead, which supports nested relations including many-to-many.
149
211
  * @param {string} type - The type id of the record (table name)
150
212
  * @param {string} id - The id of the record that we want to get many to many references
151
213
  * @param {string} propertyName - The property that we want to get many to many references
@@ -31,7 +31,8 @@ class EmailService {
31
31
  errors: {
32
32
  errorCode: 'TOO_MANY_ATTACHMENTS',
33
33
  errorMessage: `Maximum number of attachments is 10. Received ${emailPayload.attachments.length}.`
34
- }
34
+ },
35
+ data: null
35
36
  };
36
37
  }
37
38
  // Validate attachment URLs
@@ -42,7 +43,8 @@ class EmailService {
42
43
  errors: {
43
44
  errorCode: 'INVALID_ATTACHMENT_URL',
44
45
  errorMessage: `Attachment ${attachment.filename} must have a valid URL`
45
- }
46
+ },
47
+ data: null
46
48
  };
47
49
  }
48
50
  if (!attachment.url.startsWith('http://') && !attachment.url.startsWith('https://')) {
@@ -50,7 +52,8 @@ class EmailService {
50
52
  errors: {
51
53
  errorCode: 'INVALID_ATTACHMENT_URL',
52
54
  errorMessage: `Attachment ${attachment.filename} must have a valid HTTP/HTTPS URL`
53
- }
55
+ },
56
+ data: null
54
57
  };
55
58
  }
56
59
  }
@@ -17,12 +17,13 @@ export declare class FilterService {
17
17
  lookUpFilter(idPage: string, query: FilterLookupSearchQueryI, idsOfMultipleNodesToSearch?: string[], returnCount?: boolean): Promise<TotalumApiResponse<LookupFilterResult>>;
18
18
  /**
19
19
  * Filters data across nested related tables (like a SQL join).
20
+ * @deprecated Use `crud.query()` instead, which supports nested relations with filtering, sorting, _has, and more.
20
21
  * @param {NestedQueryFilterI} nestedQuery - The nested query to filter by
21
22
  * @param {string} tableNameToGetResults - The table that you want to get the results from
22
23
  * @param {filterNestedOptionsI} filterOptions - Extra options for the filter like pagination and sort
23
24
  * @returns {Promise<TotalumApiResponse<T[]>>} - Array of filtered items
24
25
  */
25
- nestedFilter<T = DataValues>(nestedQuery: NestedQueryFilterI, tableNameToGetResults: string, filterOptions?: filterNestedOptionsI): Promise<TotalumApiResponse<T[]>>;
26
+ nestedFilter<T = DataValues>(nestedQuery: NestedQueryFilterI, tableNameToGetResults: string, filterOptions?: filterNestedOptionsI): Promise<TotalumApiResponse<any[]>>;
26
27
  /**
27
28
  * Runs a custom MongoDB aggregation query.
28
29
  * @param {string} type - The table name that will be at the top of the MongoDB aggregation
@@ -40,6 +40,7 @@ class FilterService {
40
40
  }
41
41
  /**
42
42
  * Filters data across nested related tables (like a SQL join).
43
+ * @deprecated Use `crud.query()` instead, which supports nested relations with filtering, sorting, _has, and more.
43
44
  * @param {NestedQueryFilterI} nestedQuery - The nested query to filter by
44
45
  * @param {string} tableNameToGetResults - The table that you want to get the results from
45
46
  * @param {filterNestedOptionsI} filterOptions - Extra options for the filter like pagination and sort
@@ -1,5 +1,5 @@
1
1
  import { TotalumApiResponse } from "../common/interfaces";
2
- import { OpenAICompletionResponse, OpenAIChatCompletionResponse } from "../common/response-types";
2
+ import { OpenAICompletionResponse, OpenAIChatCompletionResponse, ImageGenerationResponse } from "../common/response-types";
3
3
  import { FetchClient } from "../common/fetch-client";
4
4
  import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
5
5
  import { CompletionCreateParamsBase } from "openai/resources/completions";
@@ -20,16 +20,48 @@ export declare class OpenaiService {
20
20
  */
21
21
  createChatCompletion(body: ChatCompletionCreateParamsBase): Promise<TotalumApiResponse<OpenAIChatCompletionResponse>>;
22
22
  /**
23
- * Generates an image using OpenAI DALL·E.
23
+ * Generates an image from scratch using OpenAI gpt-image-1.
24
24
  * @param {object} body - The image generation parameters
25
- * @param {string} body.prompt - The prompt describing the image
26
- * @param {'256x256' | '512x512' | '1024x1024'} body.size - The size of the generated image
27
- * @param {string} body.fileName - The file name to save the image
28
- * @returns {Promise<TotalumApiResponse<string>>} - The generated image filename
25
+ * @param {string} body.prompt - The prompt describing the image to generate
26
+ * @param {string} body.fileName - The file name to save the generated image
27
+ * @param {'1024x1024' | '1536x1024' | '1024x1536' | 'auto'} [body.size] - Image dimensions (default: 'auto')
28
+ * @param {'low' | 'medium' | 'high' | 'auto'} [body.quality] - Rendering quality (default: 'auto')
29
+ * @param {'png' | 'jpeg' | 'webp'} [body.output_format] - Output file format (default: 'png')
30
+ * @param {'transparent' | 'opaque' | 'auto'} [body.background] - Background transparency (default: 'auto')
31
+ * @returns {Promise<TotalumApiResponse<ImageGenerationResponse>>} - The generated image filename and signed URL
29
32
  */
30
33
  generateImage(body: {
31
34
  prompt: string;
32
- size: '256x256' | '512x512' | '1024x1024';
33
35
  fileName: string;
34
- }): Promise<TotalumApiResponse<string>>;
36
+ size?: '1024x1024' | '1536x1024' | '1024x1536' | 'auto';
37
+ quality?: 'low' | 'medium' | 'high' | 'auto';
38
+ output_format?: 'png' | 'jpeg' | 'webp';
39
+ background?: 'transparent' | 'opaque' | 'auto';
40
+ }): Promise<TotalumApiResponse<ImageGenerationResponse>>;
41
+ /**
42
+ * Edits or transforms existing image(s) using OpenAI gpt-image-1.
43
+ * Supports: editing existing images, using images as style reference, combining multiple images, masked editing.
44
+ * @param {object} body - The image edit parameters
45
+ * @param {string} body.prompt - Description of the desired edit or transformation
46
+ * @param {string[]} body.imageUrls - Array of image URLs to edit (1-16 images). Can be signed GCS URLs or external URLs.
47
+ * @param {string} body.fileName - The file name to save the resulting image
48
+ * @param {string} [body.maskUrl] - URL to a PNG mask image with alpha channel. Transparent areas indicate where the first image should be edited.
49
+ * @param {'1024x1024' | '1536x1024' | '1024x1536' | 'auto'} [body.size] - Output image dimensions (default: 'auto')
50
+ * @param {'low' | 'medium' | 'high' | 'auto'} [body.quality] - Rendering quality (default: 'auto')
51
+ * @param {'png' | 'jpeg' | 'webp'} [body.output_format] - Output file format (default: 'png')
52
+ * @param {'transparent' | 'opaque' | 'auto'} [body.background] - Background transparency (default: 'auto')
53
+ * @param {'high' | 'low'} [body.input_fidelity] - How closely to match input images. 'high' preserves details (faces), 'low' allows creative freedom (default: 'low')
54
+ * @returns {Promise<TotalumApiResponse<ImageGenerationResponse>>} - The resulting image filename and signed URL
55
+ */
56
+ editImage(body: {
57
+ prompt: string;
58
+ imageUrls: string[];
59
+ fileName: string;
60
+ maskUrl?: string;
61
+ size?: '1024x1024' | '1536x1024' | '1024x1536' | 'auto';
62
+ quality?: 'low' | 'medium' | 'high' | 'auto';
63
+ output_format?: 'png' | 'jpeg' | 'webp';
64
+ background?: 'transparent' | 'opaque' | 'auto';
65
+ input_fidelity?: 'high' | 'low';
66
+ }): Promise<TotalumApiResponse<ImageGenerationResponse>>;
35
67
  }
@@ -40,12 +40,15 @@ class OpenaiService {
40
40
  });
41
41
  }
42
42
  /**
43
- * Generates an image using OpenAI DALL·E.
43
+ * Generates an image from scratch using OpenAI gpt-image-1.
44
44
  * @param {object} body - The image generation parameters
45
- * @param {string} body.prompt - The prompt describing the image
46
- * @param {'256x256' | '512x512' | '1024x1024'} body.size - The size of the generated image
47
- * @param {string} body.fileName - The file name to save the image
48
- * @returns {Promise<TotalumApiResponse<string>>} - The generated image filename
45
+ * @param {string} body.prompt - The prompt describing the image to generate
46
+ * @param {string} body.fileName - The file name to save the generated image
47
+ * @param {'1024x1024' | '1536x1024' | '1024x1536' | 'auto'} [body.size] - Image dimensions (default: 'auto')
48
+ * @param {'low' | 'medium' | 'high' | 'auto'} [body.quality] - Rendering quality (default: 'auto')
49
+ * @param {'png' | 'jpeg' | 'webp'} [body.output_format] - Output file format (default: 'png')
50
+ * @param {'transparent' | 'opaque' | 'auto'} [body.background] - Background transparency (default: 'auto')
51
+ * @returns {Promise<TotalumApiResponse<ImageGenerationResponse>>} - The generated image filename and signed URL
49
52
  */
50
53
  generateImage(body) {
51
54
  return __awaiter(this, void 0, void 0, function* () {
@@ -53,5 +56,26 @@ class OpenaiService {
53
56
  return this.client.post(url, body);
54
57
  });
55
58
  }
59
+ /**
60
+ * Edits or transforms existing image(s) using OpenAI gpt-image-1.
61
+ * Supports: editing existing images, using images as style reference, combining multiple images, masked editing.
62
+ * @param {object} body - The image edit parameters
63
+ * @param {string} body.prompt - Description of the desired edit or transformation
64
+ * @param {string[]} body.imageUrls - Array of image URLs to edit (1-16 images). Can be signed GCS URLs or external URLs.
65
+ * @param {string} body.fileName - The file name to save the resulting image
66
+ * @param {string} [body.maskUrl] - URL to a PNG mask image with alpha channel. Transparent areas indicate where the first image should be edited.
67
+ * @param {'1024x1024' | '1536x1024' | '1024x1536' | 'auto'} [body.size] - Output image dimensions (default: 'auto')
68
+ * @param {'low' | 'medium' | 'high' | 'auto'} [body.quality] - Rendering quality (default: 'auto')
69
+ * @param {'png' | 'jpeg' | 'webp'} [body.output_format] - Output file format (default: 'png')
70
+ * @param {'transparent' | 'opaque' | 'auto'} [body.background] - Background transparency (default: 'auto')
71
+ * @param {'high' | 'low'} [body.input_fidelity] - How closely to match input images. 'high' preserves details (faces), 'low' allows creative freedom (default: 'low')
72
+ * @returns {Promise<TotalumApiResponse<ImageGenerationResponse>>} - The resulting image filename and signed URL
73
+ */
74
+ editImage(body) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const url = utils_1.UtilsService.getUrl('', endpoints_1.endpoints.openai.editImage);
77
+ return this.client.post(url, body);
78
+ });
79
+ }
56
80
  }
57
81
  exports.OpenaiService = OpenaiService;