@encatch/api-sdk 0.0.6 → 0.0.7

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/index.cjs CHANGED
@@ -194,15 +194,32 @@ var _EncatchApiSDK = class _EncatchApiSDK {
194
194
  }
195
195
  async refineText(params) {
196
196
  this._log("Refining text with params:", JSON.stringify(params, null, 2));
197
- const result = await this._makeRequest(
198
- _EncatchApiSDK.ENDPOINTS.REFINE_TEXT,
199
- {
200
- method: "POST",
201
- body: params
202
- }
203
- );
204
- this._log("Text refine response: ", result);
205
- return result;
197
+ let convertedPayload;
198
+ const url = `${this.hostUrl}${_EncatchApiSDK.ENDPOINTS.REFINE_TEXT}`;
199
+ const headers = {
200
+ "Content-Type": "application/json",
201
+ "X-Api-Key": this.apiKey,
202
+ Referer: this.appPackageName
203
+ };
204
+ try {
205
+ convertedPayload = (0, import_schema.objectToSnake)(params);
206
+ } catch (error) {
207
+ this._log("Error in snake case transformation: ", error);
208
+ }
209
+ const response = await fetch(url, {
210
+ method: "POST",
211
+ headers,
212
+ body: JSON.stringify(convertedPayload)
213
+ });
214
+ try {
215
+ const jsonResponse = await response.json();
216
+ const convertedResponse = (0, import_schema.objectToCamel)(jsonResponse);
217
+ this._log("Text refine response: ", convertedResponse);
218
+ return convertedResponse;
219
+ } catch (error) {
220
+ this._log("Error parsing response:", error);
221
+ throw new Error("Failed to parse response");
222
+ }
206
223
  }
207
224
  async _makeRequest(endpoint, options) {
208
225
  const url = `${this.hostUrl}${endpoint}`;
package/dist/index.js CHANGED
@@ -160,15 +160,32 @@ var _EncatchApiSDK = class _EncatchApiSDK {
160
160
  }
161
161
  async refineText(params) {
162
162
  this._log("Refining text with params:", JSON.stringify(params, null, 2));
163
- const result = await this._makeRequest(
164
- _EncatchApiSDK.ENDPOINTS.REFINE_TEXT,
165
- {
166
- method: "POST",
167
- body: params
168
- }
169
- );
170
- this._log("Text refine response: ", result);
171
- return result;
163
+ let convertedPayload;
164
+ const url = `${this.hostUrl}${_EncatchApiSDK.ENDPOINTS.REFINE_TEXT}`;
165
+ const headers = {
166
+ "Content-Type": "application/json",
167
+ "X-Api-Key": this.apiKey,
168
+ Referer: this.appPackageName
169
+ };
170
+ try {
171
+ convertedPayload = objectToSnake(params);
172
+ } catch (error) {
173
+ this._log("Error in snake case transformation: ", error);
174
+ }
175
+ const response = await fetch(url, {
176
+ method: "POST",
177
+ headers,
178
+ body: JSON.stringify(convertedPayload)
179
+ });
180
+ try {
181
+ const jsonResponse = await response.json();
182
+ const convertedResponse = objectToCamel(jsonResponse);
183
+ this._log("Text refine response: ", convertedResponse);
184
+ return convertedResponse;
185
+ } catch (error) {
186
+ this._log("Error parsing response:", error);
187
+ throw new Error("Failed to parse response");
188
+ }
172
189
  }
173
190
  async _makeRequest(endpoint, options) {
174
191
  const url = `${this.hostUrl}${endpoint}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@encatch/api-sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",