@revrag-ai/embed-react-native 1.0.13 → 1.0.14
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/commonjs/api/api.error.js +233 -0
- package/dist/commonjs/api/api.error.js.map +1 -0
- package/dist/commonjs/api/api.js +38 -85
- package/dist/commonjs/api/api.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedButton.js +41 -20
- package/dist/commonjs/components/Embed/EmbedButton.js.map +1 -1
- package/dist/commonjs/components/styles/EmbedButton.style.js +181 -63
- package/dist/commonjs/components/styles/EmbedButton.style.js.map +1 -1
- package/dist/commonjs/hooks/initialize.js +2 -2
- package/dist/commonjs/hooks/initialize.js.map +1 -1
- package/dist/commonjs/hooks/voiceagent.js +12 -2
- package/dist/commonjs/hooks/voiceagent.js.map +1 -1
- package/dist/module/api/api.error.js +226 -0
- package/dist/module/api/api.error.js.map +1 -0
- package/dist/module/api/api.js +36 -84
- package/dist/module/api/api.js.map +1 -1
- package/dist/module/components/Embed/EmbedButton.js +41 -20
- package/dist/module/components/Embed/EmbedButton.js.map +1 -1
- package/dist/module/components/styles/EmbedButton.style.js +180 -62
- package/dist/module/components/styles/EmbedButton.style.js.map +1 -1
- package/dist/module/hooks/initialize.js +2 -2
- package/dist/module/hooks/initialize.js.map +1 -1
- package/dist/module/hooks/voiceagent.js +12 -2
- package/dist/module/hooks/voiceagent.js.map +1 -1
- package/dist/typescript/src/api/api.d.ts +6 -0
- package/dist/typescript/src/api/api.d.ts.map +1 -1
- package/dist/typescript/src/api/api.error.d.ts +107 -0
- package/dist/typescript/src/api/api.error.d.ts.map +1 -0
- package/dist/typescript/src/api/types/embed.api.types.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts +7 -0
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts.map +1 -1
- package/dist/typescript/src/components/styles/EmbedButton.style.d.ts +50 -0
- package/dist/typescript/src/components/styles/EmbedButton.style.d.ts.map +1 -1
- package/dist/typescript/src/hooks/initialize.d.ts.map +1 -1
- package/dist/typescript/src/hooks/types/voiceAgent.types.d.ts +1 -0
- package/dist/typescript/src/hooks/types/voiceAgent.types.d.ts.map +1 -1
- package/dist/typescript/src/hooks/voiceagent.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.processApiError = exports.isApiErrorResponse = exports.HTTP_STATUS_CODES = exports.ERROR_TYPES = exports.ApiErrorHandler = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* API Error handling system
|
|
9
|
+
* Centralizes all error handling logic with status codes and definitions
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* HTTP Status Code definitions
|
|
14
|
+
*/
|
|
15
|
+
const HTTP_STATUS_CODES = exports.HTTP_STATUS_CODES = {
|
|
16
|
+
// 2xx Success
|
|
17
|
+
200: 'OK',
|
|
18
|
+
201: 'Created',
|
|
19
|
+
204: 'No Content',
|
|
20
|
+
// 4xx Client Errors
|
|
21
|
+
400: 'Bad Request',
|
|
22
|
+
401: 'Unauthorized',
|
|
23
|
+
403: 'Forbidden',
|
|
24
|
+
404: 'Not Found',
|
|
25
|
+
408: 'Request Timeout',
|
|
26
|
+
422: 'Unprocessable Entity',
|
|
27
|
+
429: 'Too Many Requests',
|
|
28
|
+
// 5xx Server Errors
|
|
29
|
+
500: 'Internal Server Error',
|
|
30
|
+
502: 'Bad Gateway',
|
|
31
|
+
503: 'Service Unavailable',
|
|
32
|
+
504: 'Gateway Timeout'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Predefined error types and their definitions
|
|
37
|
+
*/
|
|
38
|
+
const ERROR_TYPES = exports.ERROR_TYPES = {
|
|
39
|
+
NETWORK: {
|
|
40
|
+
code: 'NETWORK_ERROR',
|
|
41
|
+
message: 'Network request failed. Please check your internet connection and try again.',
|
|
42
|
+
type: 'NETWORK'
|
|
43
|
+
},
|
|
44
|
+
ATS: {
|
|
45
|
+
code: 'ATS_ERROR',
|
|
46
|
+
message: 'Network request blocked by iOS App Transport Security. Please configure ATS exceptions in Info.plist for HTTP endpoints, or use HTTPS instead.',
|
|
47
|
+
type: 'ATS'
|
|
48
|
+
},
|
|
49
|
+
TIMEOUT: {
|
|
50
|
+
code: 'TIMEOUT_ERROR',
|
|
51
|
+
message: 'Request timeout. The API server may be slow to respond or unreachable.',
|
|
52
|
+
type: 'TIMEOUT'
|
|
53
|
+
},
|
|
54
|
+
AUTH: {
|
|
55
|
+
code: 'AUTH_ERROR',
|
|
56
|
+
message: 'Authentication failed. Please check your API credentials.',
|
|
57
|
+
type: 'AUTH'
|
|
58
|
+
},
|
|
59
|
+
SERVER: {
|
|
60
|
+
code: 'SERVER_ERROR',
|
|
61
|
+
message: 'Server error occurred. Please try again later.',
|
|
62
|
+
type: 'SERVER'
|
|
63
|
+
},
|
|
64
|
+
VALIDATION: {
|
|
65
|
+
code: 'VALIDATION_ERROR',
|
|
66
|
+
message: 'Invalid request data. Please check your input.',
|
|
67
|
+
type: 'VALIDATION'
|
|
68
|
+
},
|
|
69
|
+
UNKNOWN: {
|
|
70
|
+
code: 'UNKNOWN_ERROR',
|
|
71
|
+
message: 'An unknown error occurred. Please try again.',
|
|
72
|
+
type: 'UNKNOWN'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Enhanced error handler that categorizes and formats errors
|
|
78
|
+
*/
|
|
79
|
+
class ApiErrorHandler {
|
|
80
|
+
/**
|
|
81
|
+
* Handle HTTP response errors
|
|
82
|
+
*/
|
|
83
|
+
static handleHttpError(response, responseData) {
|
|
84
|
+
const statusCode = response.status;
|
|
85
|
+
const statusText = HTTP_STATUS_CODES[statusCode] || 'Unknown Status';
|
|
86
|
+
|
|
87
|
+
// Extract error message from response data if available
|
|
88
|
+
const serverMessage = responseData?.error || responseData?.message || '';
|
|
89
|
+
|
|
90
|
+
// Determine error type based on status code
|
|
91
|
+
let errorType = 'SERVER';
|
|
92
|
+
let code;
|
|
93
|
+
let baseMessage;
|
|
94
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
95
|
+
if (statusCode === 401 || statusCode === 403) {
|
|
96
|
+
errorType = 'AUTH';
|
|
97
|
+
code = ERROR_TYPES.AUTH.code;
|
|
98
|
+
baseMessage = ERROR_TYPES.AUTH.message;
|
|
99
|
+
} else if (statusCode === 408) {
|
|
100
|
+
errorType = 'TIMEOUT';
|
|
101
|
+
code = ERROR_TYPES.TIMEOUT.code;
|
|
102
|
+
baseMessage = ERROR_TYPES.TIMEOUT.message;
|
|
103
|
+
} else if (statusCode === 422) {
|
|
104
|
+
errorType = 'VALIDATION';
|
|
105
|
+
code = ERROR_TYPES.VALIDATION.code;
|
|
106
|
+
baseMessage = ERROR_TYPES.VALIDATION.message;
|
|
107
|
+
} else {
|
|
108
|
+
errorType = 'VALIDATION';
|
|
109
|
+
code = ERROR_TYPES.VALIDATION.code;
|
|
110
|
+
baseMessage = ERROR_TYPES.VALIDATION.message;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
code = ERROR_TYPES.SERVER.code;
|
|
114
|
+
baseMessage = ERROR_TYPES.SERVER.message;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
code,
|
|
118
|
+
message: serverMessage || `${baseMessage} (${statusCode}: ${statusText})`,
|
|
119
|
+
statusCode,
|
|
120
|
+
details: serverMessage ? `HTTP ${statusCode}: ${statusText}` : undefined,
|
|
121
|
+
type: errorType
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Handle network and other runtime errors
|
|
127
|
+
*/
|
|
128
|
+
static handleRuntimeError(error, apiBaseUrl) {
|
|
129
|
+
const errorMessage = error.message.toLowerCase();
|
|
130
|
+
|
|
131
|
+
// iOS ATS related errors
|
|
132
|
+
if (errorMessage.includes('the resource could not be loaded') || errorMessage.includes('app transport security')) {
|
|
133
|
+
return {
|
|
134
|
+
...ERROR_TYPES.ATS,
|
|
135
|
+
message: `${ERROR_TYPES.ATS.message} Error: ${error.message}`,
|
|
136
|
+
details: `API endpoint: ${apiBaseUrl}`
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Network connectivity errors
|
|
141
|
+
if (errorMessage.includes('network request failed') || errorMessage.includes('failed to fetch') || errorMessage.includes('fetch')) {
|
|
142
|
+
return {
|
|
143
|
+
...ERROR_TYPES.NETWORK,
|
|
144
|
+
message: `${ERROR_TYPES.NETWORK.message} API endpoint: ${apiBaseUrl}. Error: ${error.message}`,
|
|
145
|
+
details: `Endpoint: ${apiBaseUrl}`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Timeout errors
|
|
150
|
+
if (errorMessage.includes('timeout') || errorMessage.includes('aborted')) {
|
|
151
|
+
return {
|
|
152
|
+
...ERROR_TYPES.TIMEOUT,
|
|
153
|
+
message: `${ERROR_TYPES.TIMEOUT.message} Error: ${error.message}`,
|
|
154
|
+
details: `Endpoint: ${apiBaseUrl}`
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Authentication errors
|
|
159
|
+
if (errorMessage.includes('unauthorized') || errorMessage.includes('authentication') || errorMessage.includes('api key')) {
|
|
160
|
+
return {
|
|
161
|
+
...ERROR_TYPES.AUTH,
|
|
162
|
+
message: `${ERROR_TYPES.AUTH.message} Error: ${error.message}`
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Default to unknown error
|
|
167
|
+
return {
|
|
168
|
+
...ERROR_TYPES.UNKNOWN,
|
|
169
|
+
message: `${ERROR_TYPES.UNKNOWN.message} Error: ${error.message}`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Format error for API response
|
|
175
|
+
*/
|
|
176
|
+
static formatErrorResponse(apiError) {
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
error: apiError.message,
|
|
180
|
+
errorCode: apiError.code,
|
|
181
|
+
statusCode: apiError.statusCode,
|
|
182
|
+
type: apiError.type
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Main error processing method
|
|
188
|
+
*/
|
|
189
|
+
static async processApiError(error, response, apiBaseUrl) {
|
|
190
|
+
let apiError;
|
|
191
|
+
if (response && !response.ok) {
|
|
192
|
+
// HTTP error - try to get response data
|
|
193
|
+
let responseData;
|
|
194
|
+
try {
|
|
195
|
+
responseData = await response.json();
|
|
196
|
+
} catch (e) {
|
|
197
|
+
// If JSON parsing fails, use response text or status
|
|
198
|
+
responseData = {
|
|
199
|
+
error: response.statusText
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
apiError = this.handleHttpError(response, responseData);
|
|
203
|
+
} else if (error instanceof Error) {
|
|
204
|
+
// Runtime error
|
|
205
|
+
apiError = this.handleRuntimeError(error, apiBaseUrl);
|
|
206
|
+
} else {
|
|
207
|
+
// Unknown error type
|
|
208
|
+
apiError = {
|
|
209
|
+
...ERROR_TYPES.UNKNOWN,
|
|
210
|
+
message: `${ERROR_TYPES.UNKNOWN.message} Details: ${String(error)}`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return this.formatErrorResponse(apiError);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Convenience function for processing API errors
|
|
219
|
+
*/
|
|
220
|
+
exports.ApiErrorHandler = ApiErrorHandler;
|
|
221
|
+
const processApiError = async (error, response, apiBaseUrl) => {
|
|
222
|
+
return ApiErrorHandler.processApiError(error, response, apiBaseUrl);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Type guard to check if a response is an error response
|
|
227
|
+
*/
|
|
228
|
+
exports.processApiError = processApiError;
|
|
229
|
+
const isApiErrorResponse = response => {
|
|
230
|
+
return response && typeof response === 'object' && response.success === false;
|
|
231
|
+
};
|
|
232
|
+
exports.isApiErrorResponse = isApiErrorResponse;
|
|
233
|
+
//# sourceMappingURL=api.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HTTP_STATUS_CODES","exports","ERROR_TYPES","NETWORK","code","message","type","ATS","TIMEOUT","AUTH","SERVER","VALIDATION","UNKNOWN","ApiErrorHandler","handleHttpError","response","responseData","statusCode","status","statusText","serverMessage","error","errorType","baseMessage","details","undefined","handleRuntimeError","apiBaseUrl","errorMessage","toLowerCase","includes","formatErrorResponse","apiError","success","errorCode","processApiError","ok","json","e","Error","String","isApiErrorResponse"],"sourceRoot":"../../../src","sources":["api/api.error.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;AAyBA;AACA;AACA;AACO,MAAMA,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EAC/B;EACA,GAAG,EAAE,IAAI;EACT,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,YAAY;EAEjB;EACA,GAAG,EAAE,aAAa;EAClB,GAAG,EAAE,cAAc;EACnB,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,iBAAiB;EACtB,GAAG,EAAE,sBAAsB;EAC3B,GAAG,EAAE,mBAAmB;EAExB;EACA,GAAG,EAAE,uBAAuB;EAC5B,GAAG,EAAE,aAAa;EAClB,GAAG,EAAE,qBAAqB;EAC1B,GAAG,EAAE;AACP,CAAU;;AAEV;AACA;AACA;AACO,MAAME,WAAW,GAAAD,OAAA,CAAAC,WAAA,GAAG;EACzBC,OAAO,EAAE;IACPC,IAAI,EAAE,eAAe;IACrBC,OAAO,EACL,8EAA8E;IAChFC,IAAI,EAAE;EACR,CAAC;EACDC,GAAG,EAAE;IACHH,IAAI,EAA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e,CAACd,KAAK,EAAEN,QAAQ,EAAEY,UAAU,CAAC;AACrE,CAAC;;AAED;AACA;AACA;AAFA1B,OAAA,CAAAkC,eAAA,GAAAA,eAAA;AAGO,MAAMM,kBAAkB,GAC7B1B,QAAa,IACoB;EACjC,OAAOA,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAACkB,OAAO,KAAK,KAAK;AAC/E,CAAC;AAAChC,OAAA,CAAAwC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/dist/commonjs/api/api.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.updateUserData = exports.registerOnInitialize = exports.initializeApi = exports.getTokenDetails = exports.APIService = void 0;
|
|
6
|
+
exports.updateUserData = exports.registerOnInitialize = exports.initializeApi = exports.getTokenDetails = exports.getPopupDescription = exports.APIService = void 0;
|
|
7
7
|
var _storeKey = require("../store/store.key.js");
|
|
8
|
+
var _apiError = require("./api.error.js");
|
|
8
9
|
/**
|
|
9
10
|
* APIService class that ensures proper initialization before API calls
|
|
10
11
|
*/
|
|
@@ -69,50 +70,25 @@ class APIService {
|
|
|
69
70
|
* @returns Promise with registration response
|
|
70
71
|
*/
|
|
71
72
|
async registerOnInitialize() {
|
|
73
|
+
let response;
|
|
72
74
|
try {
|
|
73
75
|
await this.ensureInitialized();
|
|
74
76
|
const headers = await this.getHeaders();
|
|
75
|
-
|
|
77
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/initialize`, {
|
|
76
78
|
method: 'GET',
|
|
77
79
|
headers: headers
|
|
78
80
|
});
|
|
79
81
|
const data = await response.json();
|
|
80
|
-
await (0, _storeKey.setAgentData)(data, '@config_data');
|
|
81
82
|
if (!response.ok) {
|
|
82
|
-
|
|
83
|
-
throw new Error(data.error || 'Registration failed');
|
|
83
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
84
84
|
}
|
|
85
|
+
await (0, _storeKey.setAgentData)(data, '@config_data');
|
|
85
86
|
return {
|
|
86
87
|
success: true,
|
|
87
88
|
data: data
|
|
88
89
|
};
|
|
89
90
|
} catch (error) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Enhanced error handling for common iOS network issues
|
|
93
|
-
let errorMessage = 'Unknown error occurred';
|
|
94
|
-
if (error instanceof Error) {
|
|
95
|
-
errorMessage = error.message;
|
|
96
|
-
|
|
97
|
-
// iOS ATS related errors
|
|
98
|
-
if (error.message.includes('The resource could not be loaded') || error.message.includes('App Transport Security')) {
|
|
99
|
-
errorMessage = `Network request blocked by iOS App Transport Security. ` + `Please configure ATS exceptions in Info.plist for HTTP endpoints, ` + `or use HTTPS instead. Error: ${error.message}`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Network connectivity errors
|
|
103
|
-
if (error.message.includes('Network request failed') || error.message.includes('Failed to fetch')) {
|
|
104
|
-
errorMessage = `Network request failed. Please check your internet connection ` + `and ensure the API endpoint (${this.apiBaseUrl}) is accessible. ` + `Error: ${error.message}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Timeout errors
|
|
108
|
-
if (error.message.includes('timeout')) {
|
|
109
|
-
errorMessage = `Request timeout. The API server may be slow to respond or unreachable. ` + `Error: ${error.message}`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
success: false,
|
|
114
|
-
error: errorMessage
|
|
115
|
-
};
|
|
91
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
116
92
|
}
|
|
117
93
|
}
|
|
118
94
|
|
|
@@ -122,50 +98,25 @@ class APIService {
|
|
|
122
98
|
* @returns Promise with update response
|
|
123
99
|
*/
|
|
124
100
|
async updateUserData(params) {
|
|
101
|
+
let response;
|
|
125
102
|
try {
|
|
126
103
|
await this.ensureInitialized();
|
|
127
104
|
const headers = await this.getHeaders();
|
|
128
|
-
|
|
105
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/user-context/update?app_user_id=${params.data.app_user_id}`, {
|
|
129
106
|
method: 'PUT',
|
|
130
107
|
headers,
|
|
131
108
|
body: JSON.stringify({
|
|
132
109
|
[params.eventKey]: params.data
|
|
133
110
|
})
|
|
134
111
|
});
|
|
135
|
-
const data = await response.json();
|
|
136
112
|
if (!response.ok) {
|
|
137
|
-
|
|
113
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
138
114
|
}
|
|
139
115
|
return {
|
|
140
116
|
success: true
|
|
141
117
|
};
|
|
142
118
|
} catch (error) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// Enhanced error handling for common iOS network issues
|
|
146
|
-
let errorMessage = 'Unknown error occurred';
|
|
147
|
-
if (error instanceof Error) {
|
|
148
|
-
errorMessage = error.message;
|
|
149
|
-
|
|
150
|
-
// iOS ATS related errors
|
|
151
|
-
if (error.message.includes('The resource could not be loaded') || error.message.includes('App Transport Security')) {
|
|
152
|
-
errorMessage = `Network request blocked by iOS App Transport Security. ` + `Please configure ATS exceptions in Info.plist for HTTP endpoints, ` + `or use HTTPS instead. Error: ${error.message}`;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Network connectivity errors
|
|
156
|
-
if (error.message.includes('Network request failed') || error.message.includes('Failed to fetch')) {
|
|
157
|
-
errorMessage = `Network request failed. Please check your internet connection ` + `and ensure the API endpoint (${this.apiBaseUrl}) is accessible. ` + `Error: ${error.message}`;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Timeout errors
|
|
161
|
-
if (error.message.includes('timeout')) {
|
|
162
|
-
errorMessage = `Request timeout. The API server may be slow to respond or unreachable. ` + `Error: ${error.message}`;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
success: false,
|
|
167
|
-
error: errorMessage
|
|
168
|
-
};
|
|
119
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
169
120
|
}
|
|
170
121
|
}
|
|
171
122
|
|
|
@@ -175,49 +126,46 @@ class APIService {
|
|
|
175
126
|
* @returns Promise with token details
|
|
176
127
|
*/
|
|
177
128
|
async getTokenDetails(params) {
|
|
129
|
+
let response;
|
|
178
130
|
try {
|
|
179
131
|
await this.ensureInitialized();
|
|
180
132
|
const headers = await this.getHeaders();
|
|
181
|
-
|
|
133
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/token`, {
|
|
182
134
|
method: 'POST',
|
|
183
135
|
headers,
|
|
184
136
|
body: JSON.stringify(params)
|
|
185
137
|
});
|
|
186
138
|
const data = await response.json();
|
|
187
139
|
if (!response.ok) {
|
|
188
|
-
|
|
140
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
189
141
|
}
|
|
190
142
|
return {
|
|
191
143
|
success: true,
|
|
192
144
|
data: data
|
|
193
145
|
};
|
|
194
146
|
} catch (error) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Timeout errors
|
|
213
|
-
if (error.message.includes('timeout')) {
|
|
214
|
-
errorMessage = `Request timeout. The API server may be slow to respond or unreachable. ` + `Error: ${error.message}`;
|
|
215
|
-
}
|
|
147
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async getPopupDescription(params) {
|
|
151
|
+
let response;
|
|
152
|
+
try {
|
|
153
|
+
await this.ensureInitialized();
|
|
154
|
+
const headers = await this.getHeaders();
|
|
155
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/dynamic-popup?app_user_id=${params.app_user_id}`, {
|
|
156
|
+
method: 'GET',
|
|
157
|
+
headers
|
|
158
|
+
});
|
|
159
|
+
const data = await response.json();
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
216
162
|
}
|
|
217
163
|
return {
|
|
218
|
-
success:
|
|
219
|
-
|
|
164
|
+
success: true,
|
|
165
|
+
data: data
|
|
220
166
|
};
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
221
169
|
}
|
|
222
170
|
}
|
|
223
171
|
}
|
|
@@ -244,4 +192,9 @@ const getTokenDetails = async params => {
|
|
|
244
192
|
return await apiService.getTokenDetails(params);
|
|
245
193
|
};
|
|
246
194
|
exports.getTokenDetails = getTokenDetails;
|
|
195
|
+
const getPopupDescription = async params => {
|
|
196
|
+
const apiService = APIService.getInstance();
|
|
197
|
+
return await apiService.getPopupDescription(params);
|
|
198
|
+
};
|
|
199
|
+
exports.getPopupDescription = getPopupDescription;
|
|
247
200
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_storeKey","require","APIService","instance","apiBaseUrl","isInitialized","constructor","getInstance","initialize","AgentData","getAgentData","embedUrl","Error","ensureInitialized","getHeaders","apiKey","registerOnInitialize","
|
|
1
|
+
{"version":3,"names":["_storeKey","require","_apiError","APIService","instance","apiBaseUrl","isInitialized","constructor","getInstance","initialize","AgentData","getAgentData","embedUrl","Error","ensureInitialized","getHeaders","apiKey","registerOnInitialize","response","headers","fetch","method","data","json","ok","processApiError","undefined","setAgentData","success","error","updateUserData","params","app_user_id","body","JSON","stringify","eventKey","getTokenDetails","getPopupDescription","exports","initializeApi","apiService"],"sourceRoot":"../../../src","sources":["api/api.ts"],"mappings":";;;;;;AAKA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACO,MAAME,U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AAA,oBAAA;AAEK,MAAMa,cAAc,GAAG,MAAOC,MAAyB,IAAK;EACjE,MAAMU,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACX,cAAc,CAACC,MAAM,CAAC;AAChD,CAAC;AAACQ,OAAA,CAAAT,cAAA,GAAAA,cAAA;AAEK,MAAMO,eAAe,GAAG,MAAON,MAGrC,IAAK;EACJ,MAAMU,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACJ,eAAe,CAACN,MAAM,CAAC;AACjD,CAAC;AAACQ,OAAA,CAAAF,eAAA,GAAAA,eAAA;AAEK,MAAMC,mBAAmB,GAAG,MAAOP,MAA+B,IAAK;EAC5E,MAAMU,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACH,mBAAmB,CAACP,MAAM,CAAC;AACrD,CAAC;AAACQ,OAAA,CAAAD,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -71,7 +71,10 @@ const defaultStyles = {
|
|
|
71
71
|
spacing: {
|
|
72
72
|
SMALL: 10,
|
|
73
73
|
MEDIUM: 15,
|
|
74
|
-
LARGE: 25
|
|
74
|
+
LARGE: 25,
|
|
75
|
+
EXTRA_SMALL: 5,
|
|
76
|
+
EXTRA_LARGE: 35,
|
|
77
|
+
EXTRA_EXTRA_LARGE: 45
|
|
75
78
|
}
|
|
76
79
|
};
|
|
77
80
|
|
|
@@ -96,6 +99,15 @@ const defaultStyles = {
|
|
|
96
99
|
* />
|
|
97
100
|
* ```
|
|
98
101
|
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Generates random sentences for testing or placeholder content
|
|
105
|
+
* @param count - Number of sentences to generate (default: 1)
|
|
106
|
+
* @param minWords - Minimum words per sentence (default: 5)
|
|
107
|
+
* @param maxWords - Maximum words per sentence (default: 15)
|
|
108
|
+
* @returns Array of random sentences
|
|
109
|
+
*/
|
|
110
|
+
|
|
99
111
|
function EmbedButton() {
|
|
100
112
|
const {
|
|
101
113
|
initializeVoiceAgent,
|
|
@@ -106,10 +118,12 @@ function EmbedButton() {
|
|
|
106
118
|
muteMic,
|
|
107
119
|
unmuteMic,
|
|
108
120
|
connectionState,
|
|
109
|
-
roomRef
|
|
121
|
+
roomRef,
|
|
122
|
+
getPopupDescription
|
|
110
123
|
} = (0, _voiceagent.useVoiceAgent)();
|
|
111
124
|
// State management
|
|
112
125
|
const [configData, setConfigData] = (0, _react.useState)(null);
|
|
126
|
+
const [popupDescription, setPopupDescription] = (0, _react.useState)('');
|
|
113
127
|
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
114
128
|
const [callDuration, setCallDuration] = (0, _react.useState)(0);
|
|
115
129
|
const timerRef = (0, _react.useRef)(null);
|
|
@@ -132,9 +146,16 @@ function EmbedButton() {
|
|
|
132
146
|
const styles = (0, _EmbedButtonStyle.createEmbedButtonStyles)(defaultStyles);
|
|
133
147
|
const [isAutoOpen, setIsAutoOpen] = (0, _react.useState)(false);
|
|
134
148
|
(0, _react.useEffect)(() => {
|
|
135
|
-
const autoOpenTimer = setTimeout(() => {
|
|
149
|
+
const autoOpenTimer = setTimeout(async () => {
|
|
136
150
|
if (!isOpen) {
|
|
137
|
-
|
|
151
|
+
const response = await getPopupDescription();
|
|
152
|
+
if (response) {
|
|
153
|
+
setPopupDescription(response);
|
|
154
|
+
setIsAutoOpen(true);
|
|
155
|
+
} else {
|
|
156
|
+
// todo: handle no popup description found
|
|
157
|
+
console.warn('No popup description found');
|
|
158
|
+
}
|
|
138
159
|
}
|
|
139
160
|
}, 15000); // 15 seconds
|
|
140
161
|
|
|
@@ -152,7 +173,7 @@ function EmbedButton() {
|
|
|
152
173
|
const data = await (0, _storeKey.getAgentData)('@config_data');
|
|
153
174
|
setConfigData(data?.ui_config);
|
|
154
175
|
} catch (error) {
|
|
155
|
-
|
|
176
|
+
// todo: handle error fetching agent data
|
|
156
177
|
}
|
|
157
178
|
};
|
|
158
179
|
fetchAgentData();
|
|
@@ -359,7 +380,7 @@ function EmbedButton() {
|
|
|
359
380
|
style: [animatedTextStyles, styles.popupContainer],
|
|
360
381
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
361
382
|
style: styles.popupText,
|
|
362
|
-
children:
|
|
383
|
+
children: popupDescription || 'Revrag'
|
|
363
384
|
})
|
|
364
385
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
|
|
365
386
|
gesture: gesture,
|
|
@@ -389,13 +410,10 @@ function EmbedButton() {
|
|
|
389
410
|
onDisconnected: handleEndCall,
|
|
390
411
|
roomRef: roomRef,
|
|
391
412
|
onConnected: handleConnected
|
|
392
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
style: styles.pressable,
|
|
397
|
-
children: renderIcon()
|
|
398
|
-
})
|
|
413
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
|
|
414
|
+
onPress: handlePress,
|
|
415
|
+
style: styles.pressable,
|
|
416
|
+
children: renderIcon()
|
|
399
417
|
}), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
400
418
|
style: styles.expandedContentContainer,
|
|
401
419
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
@@ -404,7 +422,7 @@ function EmbedButton() {
|
|
|
404
422
|
style: [styles.agentNameText, styles.leftAlignedText],
|
|
405
423
|
children: configData?.agent_name || 'Revrag'
|
|
406
424
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
407
|
-
style: [styles.
|
|
425
|
+
style: [styles.leftAlignedText, styles.statusText],
|
|
408
426
|
children: getStatusText()
|
|
409
427
|
})]
|
|
410
428
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
@@ -414,12 +432,15 @@ function EmbedButton() {
|
|
|
414
432
|
})
|
|
415
433
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
416
434
|
style: styles.rightContentSection,
|
|
417
|
-
children: [!tokenDetails?.token && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
style: styles.
|
|
422
|
-
children:
|
|
435
|
+
children: [!tokenDetails?.token && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
436
|
+
style: styles.buttonContainer,
|
|
437
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
|
|
438
|
+
onPress: handleStartCall,
|
|
439
|
+
style: styles.startCallButton,
|
|
440
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
441
|
+
style: styles.startCallText,
|
|
442
|
+
children: configData?.start_call_text || 'Start Call'
|
|
443
|
+
})
|
|
423
444
|
})
|
|
424
445
|
}), tokenDetails?.token && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
425
446
|
style: styles.buttonContainer,
|