@encatch/api-sdk 0.0.5 → 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 +26 -9
- package/dist/index.js +26 -9
- package/package.json +1 -1
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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}`;
|