@encatch/api-sdk 0.0.1
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 +291 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +260 -0
- package/package.json +34 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
36
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
37
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
38
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
39
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
40
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
41
|
+
mod
|
|
42
|
+
));
|
|
43
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
44
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
45
|
+
|
|
46
|
+
// src/index.ts
|
|
47
|
+
var index_exports = {};
|
|
48
|
+
__export(index_exports, {
|
|
49
|
+
EncatchApiSDK: () => EncatchApiSDK
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(index_exports);
|
|
52
|
+
|
|
53
|
+
// src/feature/encatch-api.ts
|
|
54
|
+
var import_pako = __toESM(require("pako"), 1);
|
|
55
|
+
var import_ts_case_convert = require("ts-case-convert");
|
|
56
|
+
var _EncatchApiSDK = class _EncatchApiSDK {
|
|
57
|
+
constructor(config) {
|
|
58
|
+
__publicField(this, "apiKey");
|
|
59
|
+
__publicField(this, "hostUrl");
|
|
60
|
+
__publicField(this, "appPackageName");
|
|
61
|
+
__publicField(this, "enableLogging");
|
|
62
|
+
// State management
|
|
63
|
+
__publicField(this, "_loading", false);
|
|
64
|
+
__publicField(this, "_error", null);
|
|
65
|
+
var _a, _b;
|
|
66
|
+
this.apiKey = config.apiKey;
|
|
67
|
+
this.hostUrl = ((_a = config.hostUrl) == null ? void 0 : _a.replace(/\/+$/, "")) || "https://app.dev.encatch.com";
|
|
68
|
+
this.enableLogging = (_b = config.enableLogging) != null ? _b : false;
|
|
69
|
+
this.appPackageName = config.appPackageName;
|
|
70
|
+
}
|
|
71
|
+
// Getters
|
|
72
|
+
get loading() {
|
|
73
|
+
return this._loading;
|
|
74
|
+
}
|
|
75
|
+
get error() {
|
|
76
|
+
return this._error;
|
|
77
|
+
}
|
|
78
|
+
async fetchConfiguration(params) {
|
|
79
|
+
this._loading = true;
|
|
80
|
+
this._error = null;
|
|
81
|
+
try {
|
|
82
|
+
this._log("Fetching configuration from server");
|
|
83
|
+
const response = await this._makeRequest(
|
|
84
|
+
_EncatchApiSDK.ENDPOINTS.FETCH_CONFIGURATIONS,
|
|
85
|
+
{
|
|
86
|
+
method: "POST",
|
|
87
|
+
body: {
|
|
88
|
+
sessionInfo: params.sessionInfo,
|
|
89
|
+
deviceInfo: params.deviceInfo,
|
|
90
|
+
userInfo: params.userInfo
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
this._log(
|
|
95
|
+
"Configuration fetched successfully",
|
|
96
|
+
JSON.stringify(response, null, 2)
|
|
97
|
+
);
|
|
98
|
+
return response;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
this._handleError("Error fetching configuration", error);
|
|
101
|
+
throw error;
|
|
102
|
+
} finally {
|
|
103
|
+
this._loading = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async fetchNewDeviceConfiguration(params) {
|
|
107
|
+
this._log("Fetching configuration for new device");
|
|
108
|
+
this._loading = true;
|
|
109
|
+
this._error = null;
|
|
110
|
+
try {
|
|
111
|
+
this._log("Fetching new device configuration from server");
|
|
112
|
+
const response = await this._makeRequest(
|
|
113
|
+
`${_EncatchApiSDK.ENDPOINTS.FETCH_CONFIGURATIONS}?isNewDevice=true`,
|
|
114
|
+
{
|
|
115
|
+
method: "POST",
|
|
116
|
+
body: {
|
|
117
|
+
sessionInfo: params.sessionInfo,
|
|
118
|
+
deviceInfo: params.deviceInfo,
|
|
119
|
+
userInfo: params.userInfo
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
this._log(
|
|
124
|
+
"New device configuration fetched successfully",
|
|
125
|
+
JSON.stringify(response, null, 2)
|
|
126
|
+
);
|
|
127
|
+
return response;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
this._handleError("Error fetching new device configuration", error);
|
|
130
|
+
throw error;
|
|
131
|
+
} finally {
|
|
132
|
+
this._loading = false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async fetchConfigurationDetails(params) {
|
|
136
|
+
this._log("Fetching configuration details");
|
|
137
|
+
try {
|
|
138
|
+
const response = await this._makeRequest(
|
|
139
|
+
`${_EncatchApiSDK.ENDPOINTS.FETCH_CONFIGURATION_DETAILS}/${params.formConfig.feedbackConfigurationId}`,
|
|
140
|
+
{
|
|
141
|
+
method: "POST",
|
|
142
|
+
body: {
|
|
143
|
+
formConfig: params.formConfig,
|
|
144
|
+
deviceInfo: params.deviceInfo,
|
|
145
|
+
sessionInfo: params.sessionInfo,
|
|
146
|
+
userInfo: params.userInfo
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
this._log(
|
|
151
|
+
"Configuration details fetched successfully",
|
|
152
|
+
JSON.stringify(response, null, 2)
|
|
153
|
+
);
|
|
154
|
+
return response;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this._log("Error fetching configuration details:", error);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async submitFeedback(params) {
|
|
161
|
+
this._log(
|
|
162
|
+
`Submitting feedback with userAction: '${params.formConfig.userAction}'`,
|
|
163
|
+
params
|
|
164
|
+
);
|
|
165
|
+
try {
|
|
166
|
+
const result = await this._makeRequest(
|
|
167
|
+
_EncatchApiSDK.ENDPOINTS.SUBMIT_FEEDBACK,
|
|
168
|
+
{
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: {
|
|
171
|
+
"Content-Type": "application/gzip"
|
|
172
|
+
},
|
|
173
|
+
body: params
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
this._log("Feedback submitted successfully", result);
|
|
177
|
+
return { success: true };
|
|
178
|
+
} catch (error) {
|
|
179
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred while submitting feedback";
|
|
180
|
+
this._log("Error submitting feedback:", error);
|
|
181
|
+
return { success: false, error: errorMessage };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async viewFeedback(params) {
|
|
185
|
+
this._log(
|
|
186
|
+
`Viewing feedback with userAction: '${params.formConfig.userAction}'`,
|
|
187
|
+
params
|
|
188
|
+
);
|
|
189
|
+
try {
|
|
190
|
+
const result = await this._makeRequest(
|
|
191
|
+
_EncatchApiSDK.ENDPOINTS.SUBMIT_FEEDBACK,
|
|
192
|
+
{
|
|
193
|
+
method: "POST",
|
|
194
|
+
headers: {
|
|
195
|
+
"Content-Type": "application/gzip"
|
|
196
|
+
},
|
|
197
|
+
body: params
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
this._log("Feedback viewed successfully", result);
|
|
201
|
+
return { success: true };
|
|
202
|
+
} catch (error) {
|
|
203
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred while viewing feedback";
|
|
204
|
+
this._log("Error viewing feedback:", error);
|
|
205
|
+
return { success: false, error: errorMessage };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async refineText(params) {
|
|
209
|
+
this._log("Refining text with params:", JSON.stringify(params, null, 2));
|
|
210
|
+
try {
|
|
211
|
+
const result = await this._makeRequest(
|
|
212
|
+
_EncatchApiSDK.ENDPOINTS.REFINE_TEXT,
|
|
213
|
+
{
|
|
214
|
+
method: "POST",
|
|
215
|
+
body: params
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
this._log("Text refined successfully: ", result);
|
|
219
|
+
return result;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
this._log("Error refining text: ", error);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async _makeRequest(endpoint, options) {
|
|
226
|
+
const url = `${this.hostUrl}${endpoint}`;
|
|
227
|
+
const headers = __spreadValues({
|
|
228
|
+
"Content-Type": "application/json",
|
|
229
|
+
"X-Api-Key": this.apiKey,
|
|
230
|
+
"X-Dev-Debug-Id": "rahul",
|
|
231
|
+
Referer: this.appPackageName
|
|
232
|
+
}, options.headers);
|
|
233
|
+
let convertedPayload;
|
|
234
|
+
let requestBody;
|
|
235
|
+
try {
|
|
236
|
+
convertedPayload = (0, import_ts_case_convert.objectToSnake)(options.body);
|
|
237
|
+
} catch (error) {
|
|
238
|
+
this._log("Error in snake case transformation: ", error);
|
|
239
|
+
}
|
|
240
|
+
if (headers["Content-Type"] === "application/gzip") {
|
|
241
|
+
const payload = JSON.stringify(convertedPayload);
|
|
242
|
+
const payloadBytes = new TextEncoder().encode(payload);
|
|
243
|
+
requestBody = import_pako.default.gzip(payloadBytes);
|
|
244
|
+
} else {
|
|
245
|
+
requestBody = JSON.stringify(convertedPayload);
|
|
246
|
+
}
|
|
247
|
+
const response = await fetch(url, {
|
|
248
|
+
method: options.method,
|
|
249
|
+
headers,
|
|
250
|
+
body: requestBody
|
|
251
|
+
});
|
|
252
|
+
this._log("Request body: ", JSON.stringify(convertedPayload, null, 2));
|
|
253
|
+
if (!response.ok) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
`HTTP error! status ${response.status} with message ${response.statusText}`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const jsonResponse = await response.json();
|
|
260
|
+
const convertedResponse = (0, import_ts_case_convert.objectToCamel)(jsonResponse);
|
|
261
|
+
return convertedResponse;
|
|
262
|
+
} catch (error) {
|
|
263
|
+
this._log("Error parsing response:", error);
|
|
264
|
+
throw new Error("Failed to parse response");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
_handleError(message, error) {
|
|
268
|
+
this._error = error instanceof Error ? error.message : "An unknown error occurred";
|
|
269
|
+
this._log(message, this._error);
|
|
270
|
+
}
|
|
271
|
+
_log(message, data) {
|
|
272
|
+
if (this.enableLogging) {
|
|
273
|
+
if (data) {
|
|
274
|
+
console.log(`[EncatchApiSDK] ${message}`, data);
|
|
275
|
+
} else {
|
|
276
|
+
console.log(`[EncatchApiSDK] ${message}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
// API Endpoints
|
|
282
|
+
__publicField(_EncatchApiSDK, "ENDPOINTS", {
|
|
283
|
+
FETCH_CONFIGURATIONS: "/engage-product/encatch/api/v1/encatch/fetch-configurations",
|
|
284
|
+
FETCH_CONFIGURATION_DETAILS: "/engage-product/encatch/api/v1/encatch/fetch-configurations",
|
|
285
|
+
SUBMIT_FEEDBACK: "/engage-product/encatch/api/v1/encatch/submit-feedback",
|
|
286
|
+
REFINE_TEXT: "/engage-product/encatch/api/v1/encatch/refine-text"
|
|
287
|
+
});
|
|
288
|
+
var EncatchApiSDK = _EncatchApiSDK;
|
|
289
|
+
|
|
290
|
+
// src/index.ts
|
|
291
|
+
__reExport(index_exports, require("@encatch/schema"), module.exports);
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FetchConfigurationListRequest, FetchConfigurationListResponse, FetchFeedbackDetailsRequest, FetchFeedbackDetailsResponse, SubmitFeedback, ViewFeedback, RefineTextParams, RefineTextResponse } from '@encatch/schema';
|
|
2
|
+
export * from '@encatch/schema';
|
|
3
|
+
|
|
4
|
+
interface SDKConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
hostUrl?: string;
|
|
7
|
+
appPackageName: string;
|
|
8
|
+
enableLogging?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare class EncatchApiSDK {
|
|
11
|
+
private static readonly ENDPOINTS;
|
|
12
|
+
private readonly apiKey;
|
|
13
|
+
private readonly hostUrl;
|
|
14
|
+
private readonly appPackageName;
|
|
15
|
+
private readonly enableLogging;
|
|
16
|
+
private _loading;
|
|
17
|
+
private _error;
|
|
18
|
+
constructor(config: SDKConfig);
|
|
19
|
+
get loading(): boolean;
|
|
20
|
+
get error(): string | null;
|
|
21
|
+
fetchConfiguration(params: FetchConfigurationListRequest): Promise<FetchConfigurationListResponse>;
|
|
22
|
+
fetchNewDeviceConfiguration(params: FetchConfigurationListRequest): Promise<FetchConfigurationListResponse>;
|
|
23
|
+
fetchConfigurationDetails(params: FetchFeedbackDetailsRequest): Promise<FetchFeedbackDetailsResponse>;
|
|
24
|
+
submitFeedback(params: SubmitFeedback): Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
}>;
|
|
28
|
+
viewFeedback(params: ViewFeedback): Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
error?: string;
|
|
31
|
+
}>;
|
|
32
|
+
refineText(params: RefineTextParams): Promise<RefineTextResponse>;
|
|
33
|
+
private _makeRequest;
|
|
34
|
+
private _handleError;
|
|
35
|
+
private _log;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { EncatchApiSDK };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FetchConfigurationListRequest, FetchConfigurationListResponse, FetchFeedbackDetailsRequest, FetchFeedbackDetailsResponse, SubmitFeedback, ViewFeedback, RefineTextParams, RefineTextResponse } from '@encatch/schema';
|
|
2
|
+
export * from '@encatch/schema';
|
|
3
|
+
|
|
4
|
+
interface SDKConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
hostUrl?: string;
|
|
7
|
+
appPackageName: string;
|
|
8
|
+
enableLogging?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare class EncatchApiSDK {
|
|
11
|
+
private static readonly ENDPOINTS;
|
|
12
|
+
private readonly apiKey;
|
|
13
|
+
private readonly hostUrl;
|
|
14
|
+
private readonly appPackageName;
|
|
15
|
+
private readonly enableLogging;
|
|
16
|
+
private _loading;
|
|
17
|
+
private _error;
|
|
18
|
+
constructor(config: SDKConfig);
|
|
19
|
+
get loading(): boolean;
|
|
20
|
+
get error(): string | null;
|
|
21
|
+
fetchConfiguration(params: FetchConfigurationListRequest): Promise<FetchConfigurationListResponse>;
|
|
22
|
+
fetchNewDeviceConfiguration(params: FetchConfigurationListRequest): Promise<FetchConfigurationListResponse>;
|
|
23
|
+
fetchConfigurationDetails(params: FetchFeedbackDetailsRequest): Promise<FetchFeedbackDetailsResponse>;
|
|
24
|
+
submitFeedback(params: SubmitFeedback): Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
}>;
|
|
28
|
+
viewFeedback(params: ViewFeedback): Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
error?: string;
|
|
31
|
+
}>;
|
|
32
|
+
refineText(params: RefineTextParams): Promise<RefineTextResponse>;
|
|
33
|
+
private _makeRequest;
|
|
34
|
+
private _handleError;
|
|
35
|
+
private _log;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { EncatchApiSDK };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
|
+
|
|
19
|
+
// src/feature/encatch-api.ts
|
|
20
|
+
import pako from "pako";
|
|
21
|
+
import { objectToSnake, objectToCamel } from "ts-case-convert";
|
|
22
|
+
var _EncatchApiSDK = class _EncatchApiSDK {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
__publicField(this, "apiKey");
|
|
25
|
+
__publicField(this, "hostUrl");
|
|
26
|
+
__publicField(this, "appPackageName");
|
|
27
|
+
__publicField(this, "enableLogging");
|
|
28
|
+
// State management
|
|
29
|
+
__publicField(this, "_loading", false);
|
|
30
|
+
__publicField(this, "_error", null);
|
|
31
|
+
var _a, _b;
|
|
32
|
+
this.apiKey = config.apiKey;
|
|
33
|
+
this.hostUrl = ((_a = config.hostUrl) == null ? void 0 : _a.replace(/\/+$/, "")) || "https://app.dev.encatch.com";
|
|
34
|
+
this.enableLogging = (_b = config.enableLogging) != null ? _b : false;
|
|
35
|
+
this.appPackageName = config.appPackageName;
|
|
36
|
+
}
|
|
37
|
+
// Getters
|
|
38
|
+
get loading() {
|
|
39
|
+
return this._loading;
|
|
40
|
+
}
|
|
41
|
+
get error() {
|
|
42
|
+
return this._error;
|
|
43
|
+
}
|
|
44
|
+
async fetchConfiguration(params) {
|
|
45
|
+
this._loading = true;
|
|
46
|
+
this._error = null;
|
|
47
|
+
try {
|
|
48
|
+
this._log("Fetching configuration from server");
|
|
49
|
+
const response = await this._makeRequest(
|
|
50
|
+
_EncatchApiSDK.ENDPOINTS.FETCH_CONFIGURATIONS,
|
|
51
|
+
{
|
|
52
|
+
method: "POST",
|
|
53
|
+
body: {
|
|
54
|
+
sessionInfo: params.sessionInfo,
|
|
55
|
+
deviceInfo: params.deviceInfo,
|
|
56
|
+
userInfo: params.userInfo
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
this._log(
|
|
61
|
+
"Configuration fetched successfully",
|
|
62
|
+
JSON.stringify(response, null, 2)
|
|
63
|
+
);
|
|
64
|
+
return response;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
this._handleError("Error fetching configuration", error);
|
|
67
|
+
throw error;
|
|
68
|
+
} finally {
|
|
69
|
+
this._loading = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async fetchNewDeviceConfiguration(params) {
|
|
73
|
+
this._log("Fetching configuration for new device");
|
|
74
|
+
this._loading = true;
|
|
75
|
+
this._error = null;
|
|
76
|
+
try {
|
|
77
|
+
this._log("Fetching new device configuration from server");
|
|
78
|
+
const response = await this._makeRequest(
|
|
79
|
+
`${_EncatchApiSDK.ENDPOINTS.FETCH_CONFIGURATIONS}?isNewDevice=true`,
|
|
80
|
+
{
|
|
81
|
+
method: "POST",
|
|
82
|
+
body: {
|
|
83
|
+
sessionInfo: params.sessionInfo,
|
|
84
|
+
deviceInfo: params.deviceInfo,
|
|
85
|
+
userInfo: params.userInfo
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
this._log(
|
|
90
|
+
"New device configuration fetched successfully",
|
|
91
|
+
JSON.stringify(response, null, 2)
|
|
92
|
+
);
|
|
93
|
+
return response;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
this._handleError("Error fetching new device configuration", error);
|
|
96
|
+
throw error;
|
|
97
|
+
} finally {
|
|
98
|
+
this._loading = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async fetchConfigurationDetails(params) {
|
|
102
|
+
this._log("Fetching configuration details");
|
|
103
|
+
try {
|
|
104
|
+
const response = await this._makeRequest(
|
|
105
|
+
`${_EncatchApiSDK.ENDPOINTS.FETCH_CONFIGURATION_DETAILS}/${params.formConfig.feedbackConfigurationId}`,
|
|
106
|
+
{
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: {
|
|
109
|
+
formConfig: params.formConfig,
|
|
110
|
+
deviceInfo: params.deviceInfo,
|
|
111
|
+
sessionInfo: params.sessionInfo,
|
|
112
|
+
userInfo: params.userInfo
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
this._log(
|
|
117
|
+
"Configuration details fetched successfully",
|
|
118
|
+
JSON.stringify(response, null, 2)
|
|
119
|
+
);
|
|
120
|
+
return response;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
this._log("Error fetching configuration details:", error);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async submitFeedback(params) {
|
|
127
|
+
this._log(
|
|
128
|
+
`Submitting feedback with userAction: '${params.formConfig.userAction}'`,
|
|
129
|
+
params
|
|
130
|
+
);
|
|
131
|
+
try {
|
|
132
|
+
const result = await this._makeRequest(
|
|
133
|
+
_EncatchApiSDK.ENDPOINTS.SUBMIT_FEEDBACK,
|
|
134
|
+
{
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: {
|
|
137
|
+
"Content-Type": "application/gzip"
|
|
138
|
+
},
|
|
139
|
+
body: params
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
this._log("Feedback submitted successfully", result);
|
|
143
|
+
return { success: true };
|
|
144
|
+
} catch (error) {
|
|
145
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred while submitting feedback";
|
|
146
|
+
this._log("Error submitting feedback:", error);
|
|
147
|
+
return { success: false, error: errorMessage };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async viewFeedback(params) {
|
|
151
|
+
this._log(
|
|
152
|
+
`Viewing feedback with userAction: '${params.formConfig.userAction}'`,
|
|
153
|
+
params
|
|
154
|
+
);
|
|
155
|
+
try {
|
|
156
|
+
const result = await this._makeRequest(
|
|
157
|
+
_EncatchApiSDK.ENDPOINTS.SUBMIT_FEEDBACK,
|
|
158
|
+
{
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: {
|
|
161
|
+
"Content-Type": "application/gzip"
|
|
162
|
+
},
|
|
163
|
+
body: params
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
this._log("Feedback viewed successfully", result);
|
|
167
|
+
return { success: true };
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred while viewing feedback";
|
|
170
|
+
this._log("Error viewing feedback:", error);
|
|
171
|
+
return { success: false, error: errorMessage };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async refineText(params) {
|
|
175
|
+
this._log("Refining text with params:", JSON.stringify(params, null, 2));
|
|
176
|
+
try {
|
|
177
|
+
const result = await this._makeRequest(
|
|
178
|
+
_EncatchApiSDK.ENDPOINTS.REFINE_TEXT,
|
|
179
|
+
{
|
|
180
|
+
method: "POST",
|
|
181
|
+
body: params
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
this._log("Text refined successfully: ", result);
|
|
185
|
+
return result;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
this._log("Error refining text: ", error);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async _makeRequest(endpoint, options) {
|
|
192
|
+
const url = `${this.hostUrl}${endpoint}`;
|
|
193
|
+
const headers = __spreadValues({
|
|
194
|
+
"Content-Type": "application/json",
|
|
195
|
+
"X-Api-Key": this.apiKey,
|
|
196
|
+
"X-Dev-Debug-Id": "rahul",
|
|
197
|
+
Referer: this.appPackageName
|
|
198
|
+
}, options.headers);
|
|
199
|
+
let convertedPayload;
|
|
200
|
+
let requestBody;
|
|
201
|
+
try {
|
|
202
|
+
convertedPayload = objectToSnake(options.body);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
this._log("Error in snake case transformation: ", error);
|
|
205
|
+
}
|
|
206
|
+
if (headers["Content-Type"] === "application/gzip") {
|
|
207
|
+
const payload = JSON.stringify(convertedPayload);
|
|
208
|
+
const payloadBytes = new TextEncoder().encode(payload);
|
|
209
|
+
requestBody = pako.gzip(payloadBytes);
|
|
210
|
+
} else {
|
|
211
|
+
requestBody = JSON.stringify(convertedPayload);
|
|
212
|
+
}
|
|
213
|
+
const response = await fetch(url, {
|
|
214
|
+
method: options.method,
|
|
215
|
+
headers,
|
|
216
|
+
body: requestBody
|
|
217
|
+
});
|
|
218
|
+
this._log("Request body: ", JSON.stringify(convertedPayload, null, 2));
|
|
219
|
+
if (!response.ok) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`HTTP error! status ${response.status} with message ${response.statusText}`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const jsonResponse = await response.json();
|
|
226
|
+
const convertedResponse = objectToCamel(jsonResponse);
|
|
227
|
+
return convertedResponse;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
this._log("Error parsing response:", error);
|
|
230
|
+
throw new Error("Failed to parse response");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
_handleError(message, error) {
|
|
234
|
+
this._error = error instanceof Error ? error.message : "An unknown error occurred";
|
|
235
|
+
this._log(message, this._error);
|
|
236
|
+
}
|
|
237
|
+
_log(message, data) {
|
|
238
|
+
if (this.enableLogging) {
|
|
239
|
+
if (data) {
|
|
240
|
+
console.log(`[EncatchApiSDK] ${message}`, data);
|
|
241
|
+
} else {
|
|
242
|
+
console.log(`[EncatchApiSDK] ${message}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
// API Endpoints
|
|
248
|
+
__publicField(_EncatchApiSDK, "ENDPOINTS", {
|
|
249
|
+
FETCH_CONFIGURATIONS: "/engage-product/encatch/api/v1/encatch/fetch-configurations",
|
|
250
|
+
FETCH_CONFIGURATION_DETAILS: "/engage-product/encatch/api/v1/encatch/fetch-configurations",
|
|
251
|
+
SUBMIT_FEEDBACK: "/engage-product/encatch/api/v1/encatch/submit-feedback",
|
|
252
|
+
REFINE_TEXT: "/engage-product/encatch/api/v1/encatch/refine-text"
|
|
253
|
+
});
|
|
254
|
+
var EncatchApiSDK = _EncatchApiSDK;
|
|
255
|
+
|
|
256
|
+
// src/index.ts
|
|
257
|
+
export * from "@encatch/schema";
|
|
258
|
+
export {
|
|
259
|
+
EncatchApiSDK
|
|
260
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@encatch/api-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/pako": "^2.0.4",
|
|
13
|
+
"@vitest/ui": "^3.2.4",
|
|
14
|
+
"tsup": "^8.5.0",
|
|
15
|
+
"typescript": "~5.9.2",
|
|
16
|
+
"vite": "^7.1.5",
|
|
17
|
+
"vitest": "^3.2.4"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"pako": "^2.1.0",
|
|
21
|
+
"ts-case-convert": "^2.1.0",
|
|
22
|
+
"zod": "^4.1.8",
|
|
23
|
+
"@encatch/schema": "0.1.25"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"dev": "vite",
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"preview": "vite preview",
|
|
29
|
+
"test": "vitest",
|
|
30
|
+
"test:run": "vitest run",
|
|
31
|
+
"test:ui": "vitest --ui",
|
|
32
|
+
"test:coverage": "vitest --coverage"
|
|
33
|
+
}
|
|
34
|
+
}
|