@revrag-ai/embed-react-native 1.0.16 → 1.0.18
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/README.md +6 -108
- package/android/build.gradle +3 -3
- package/dist/commonjs/api/api.js +6 -5
- package/dist/commonjs/api/api.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedButton.js +138 -345
- package/dist/commonjs/components/Embed/EmbedButton.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedVoice.js +16 -4
- package/dist/commonjs/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/commonjs/context/EmbedProvider.js +638 -0
- package/dist/commonjs/context/EmbedProvider.js.map +1 -0
- package/dist/commonjs/events/agent-event-emitter.js +114 -0
- package/dist/commonjs/events/agent-event-emitter.js.map +1 -0
- package/dist/commonjs/events/embed.event.js +93 -79
- package/dist/commonjs/events/embed.event.js.map +1 -1
- package/dist/commonjs/events/embed.types.js +32 -0
- package/dist/commonjs/events/embed.types.js.map +1 -0
- package/dist/commonjs/events/embed.validators.js +36 -0
- package/dist/commonjs/events/embed.validators.js.map +1 -0
- package/dist/commonjs/events/index.js +47 -0
- package/dist/commonjs/events/index.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.animations.js +181 -0
- package/dist/commonjs/hooks/EmbedButton.animations.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.helpers.js +90 -0
- package/dist/commonjs/hooks/EmbedButton.helpers.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.hooks.js +165 -0
- package/dist/commonjs/hooks/EmbedButton.hooks.js.map +1 -0
- package/dist/commonjs/hooks/initialize.js +65 -25
- package/dist/commonjs/hooks/initialize.js.map +1 -1
- package/dist/commonjs/hooks/voiceagent.js +1 -18
- package/dist/commonjs/hooks/voiceagent.js.map +1 -1
- package/dist/commonjs/index.js +16 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/index.types.js +1 -2
- package/dist/commonjs/index.types.js.map +1 -1
- package/dist/commonjs/utils/constant.js +99 -0
- package/dist/commonjs/utils/constant.js.map +1 -0
- package/dist/commonjs/utils/permision.js +48 -1
- package/dist/commonjs/utils/permision.js.map +1 -1
- package/dist/commonjs/utils/reanimated.helper.js +2 -3
- package/dist/commonjs/utils/reanimated.helper.js.map +1 -1
- package/dist/module/api/api.js +6 -6
- package/dist/module/api/api.js.map +1 -1
- package/dist/module/components/Embed/EmbedButton.js +140 -347
- package/dist/module/components/Embed/EmbedButton.js.map +1 -1
- package/dist/module/components/Embed/EmbedVoice.js +16 -4
- package/dist/module/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/module/context/EmbedProvider.js +626 -0
- package/dist/module/context/EmbedProvider.js.map +1 -0
- package/dist/module/events/agent-event-emitter.js +109 -0
- package/dist/module/events/agent-event-emitter.js.map +1 -0
- package/dist/module/events/embed.event.js +82 -80
- package/dist/module/events/embed.event.js.map +1 -1
- package/dist/module/events/embed.types.js +33 -0
- package/dist/module/events/embed.types.js.map +1 -0
- package/dist/module/events/embed.validators.js +32 -0
- package/dist/module/events/embed.validators.js.map +1 -0
- package/dist/module/events/index.js +12 -0
- package/dist/module/events/index.js.map +1 -0
- package/dist/module/hooks/EmbedButton.animations.js +172 -0
- package/dist/module/hooks/EmbedButton.animations.js.map +1 -0
- package/dist/module/hooks/EmbedButton.helpers.js +80 -0
- package/dist/module/hooks/EmbedButton.helpers.js.map +1 -0
- package/dist/module/hooks/EmbedButton.hooks.js +160 -0
- package/dist/module/hooks/EmbedButton.hooks.js.map +1 -0
- package/dist/module/hooks/initialize.js +66 -26
- package/dist/module/hooks/initialize.js.map +1 -1
- package/dist/module/hooks/voiceagent.js +1 -17
- package/dist/module/hooks/voiceagent.js.map +1 -1
- package/dist/module/index.js +4 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/index.types.js +1 -2
- package/dist/module/index.types.js.map +1 -1
- package/dist/module/utils/constant.js +93 -0
- package/dist/module/utils/constant.js.map +1 -0
- package/dist/module/utils/permision.js +48 -1
- package/dist/module/utils/permision.js.map +1 -1
- package/dist/module/utils/reanimated.helper.js +2 -3
- package/dist/module/utils/reanimated.helper.js.map +1 -1
- package/dist/typescript/src/api/api.d.ts +4 -3
- package/dist/typescript/src/api/api.d.ts.map +1 -1
- package/dist/typescript/src/api/types/embed.api.types.d.ts +1 -1
- package/dist/typescript/src/api/types/embed.api.types.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts +5 -25
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedVoice.d.ts.map +1 -1
- package/dist/typescript/src/context/EmbedProvider.d.ts +306 -0
- package/dist/typescript/src/context/EmbedProvider.d.ts.map +1 -0
- package/dist/typescript/src/events/agent-event-emitter.d.ts +41 -0
- package/dist/typescript/src/events/agent-event-emitter.d.ts.map +1 -0
- package/dist/typescript/src/events/embed.event.d.ts +39 -21
- package/dist/typescript/src/events/embed.event.d.ts.map +1 -1
- package/dist/typescript/src/events/embed.types.d.ts +39 -0
- package/dist/typescript/src/events/embed.types.d.ts.map +1 -0
- package/dist/typescript/src/events/embed.validators.d.ts +17 -0
- package/dist/typescript/src/events/embed.validators.d.ts.map +1 -0
- package/dist/typescript/src/events/index.d.ts +10 -0
- package/dist/typescript/src/events/index.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.animations.d.ts +38 -0
- package/dist/typescript/src/hooks/EmbedButton.animations.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts +49 -0
- package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts +49 -0
- package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts.map +1 -0
- package/dist/typescript/src/hooks/initialize.d.ts.map +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts.map +1 -1
- package/dist/typescript/src/hooks/voiceagent.d.ts.map +1 -1
- package/dist/typescript/src/index.d.ts +10 -4
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/index.types.d.ts +2 -3
- package/dist/typescript/src/index.types.d.ts.map +1 -1
- package/dist/typescript/src/utils/constant.d.ts +46 -0
- package/dist/typescript/src/utils/constant.d.ts.map +1 -0
- package/dist/typescript/src/utils/permision.d.ts.map +1 -1
- package/dist/typescript/src/utils/reanimated.helper.d.ts.map +1 -1
- package/package.json +16 -8
- package/react-native.config.js +1 -0
- package/dist/commonjs/events/eventEmitter.js +0 -43
- package/dist/commonjs/events/eventEmitter.js.map +0 -1
- package/dist/module/events/eventEmitter.js +0 -39
- package/dist/module/events/eventEmitter.js.map +0 -1
- package/dist/typescript/src/events/eventEmitter.d.ts +0 -9
- package/dist/typescript/src/events/eventEmitter.d.ts.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AgentEventEmitter = void 0;
|
|
7
|
+
var _storeKey = require("../store/store.key.js");
|
|
8
|
+
var _api = require("../api/api.js");
|
|
9
|
+
var _constant = require("../utils/constant.js");
|
|
10
|
+
var _embedTypes = require("./embed.types.js");
|
|
11
|
+
/**
|
|
12
|
+
* Agent Event Emitter
|
|
13
|
+
* Handles listening to agent state changes (connection, disconnection, popup visibility)
|
|
14
|
+
* Also sends agent events to the backend API
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class AgentEventEmitter {
|
|
18
|
+
agentListeners = {};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Add an event listener for agent events
|
|
22
|
+
* @param eventKey - The agent event to listen for
|
|
23
|
+
* @param callback - Callback function to execute when event fires
|
|
24
|
+
*/
|
|
25
|
+
on(eventKey, callback) {
|
|
26
|
+
if (!this.agentListeners[eventKey]) {
|
|
27
|
+
this.agentListeners[eventKey] = [];
|
|
28
|
+
}
|
|
29
|
+
this.agentListeners[eventKey]?.push(callback);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Remove an event listener for agent events
|
|
34
|
+
* @param eventKey - The agent event to stop listening to
|
|
35
|
+
* @param callback - The callback function to remove
|
|
36
|
+
*/
|
|
37
|
+
off(eventKey, callback) {
|
|
38
|
+
if (!this.agentListeners[eventKey]) return;
|
|
39
|
+
const index = this.agentListeners[eventKey]?.indexOf(callback);
|
|
40
|
+
if (index !== undefined && index > -1) {
|
|
41
|
+
this.agentListeners[eventKey]?.splice(index, 1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Emit an agent event to all registered listeners AND send to backend
|
|
47
|
+
* @param eventKey - The agent event to emit
|
|
48
|
+
* @param data - Data to pass to listeners
|
|
49
|
+
* @internal - Used internally by the library
|
|
50
|
+
*/
|
|
51
|
+
async emit(eventKey, data) {
|
|
52
|
+
// Trigger local event listeners first
|
|
53
|
+
this.agentListeners[eventKey]?.forEach(callback => {
|
|
54
|
+
try {
|
|
55
|
+
callback(data);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(`Error in agent event listener for ${eventKey}:`, error);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Send to backend API
|
|
62
|
+
await this.sendToBackend(eventKey, data);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Send agent event data to backend API
|
|
67
|
+
* @param eventKey - The agent event type
|
|
68
|
+
* @param data - Event data
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async sendToBackend(eventKey, data) {
|
|
72
|
+
try {
|
|
73
|
+
// Get user identity to include app_user_id
|
|
74
|
+
const userIdentity = await (0, _storeKey.getAgentData)(_embedTypes.EventKeys.USER_DATA);
|
|
75
|
+
if (!userIdentity?.app_user_id) {
|
|
76
|
+
console.warn(`[AgentEvent] Cannot send ${eventKey} to backend: User identity not found`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Prepare payload with app_user_id
|
|
81
|
+
const payload = {
|
|
82
|
+
...data,
|
|
83
|
+
app_user_id: userIdentity.app_user_id,
|
|
84
|
+
eventKey: eventKey,
|
|
85
|
+
eventType: 'agent_event'
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Send to API
|
|
89
|
+
const apiService = _api.APIService.getInstance();
|
|
90
|
+
const paramsData = (0, _constant.buildEventPayload)(payload);
|
|
91
|
+
const response = await apiService.updateUserData(paramsData);
|
|
92
|
+
if (!response.success) {
|
|
93
|
+
console.error(`[AgentEvent] Failed to send ${eventKey} to backend:`, response.error);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(`[AgentEvent] Error sending ${eventKey} to backend:`, error);
|
|
97
|
+
// Fail silently - agent events should not break the app
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Remove all listeners for a specific event
|
|
103
|
+
* @param eventKey - The agent event to clear listeners for
|
|
104
|
+
*/
|
|
105
|
+
removeAllListeners(eventKey) {
|
|
106
|
+
if (eventKey) {
|
|
107
|
+
delete this.agentListeners[eventKey];
|
|
108
|
+
} else {
|
|
109
|
+
this.agentListeners = {};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.AgentEventEmitter = AgentEventEmitter;
|
|
114
|
+
//# sourceMappingURL=agent-event-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_storeKey","require","_api","_constant","_embedTypes","AgentEventEmitter","agentListeners","on","eventKey","callback","push","off","index","indexOf","undefined","splice","emit","data","forEach","error","console","sendToBackend","userIdentity","getAgentData","EventKeys","USER_DATA","app_user_id","warn","payload","eventType","apiService","APIService","getInstance","paramsData","buildEventPayload","response","updateUserData","success","removeAllListeners","exports"],"sourceRoot":"../../../src","sources":["events/agent-event-emitter.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -3,121 +3,135 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
6
|
+
Object.defineProperty(exports, "AgentEvent", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _embedTypes.AgentEvent;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "EventKeys", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _embedTypes.EventKeys;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports.default = void 0;
|
|
7
19
|
var _storeKey = require("../store/store.key.js");
|
|
8
20
|
var _api = require("../api/api.js");
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return EventKeys;
|
|
19
|
-
}({});
|
|
20
|
-
let AgentEvent = exports.AgentEvent = /*#__PURE__*/function (AgentEvent) {
|
|
21
|
-
AgentEvent["AGENT_CONNECTED"] = "agent_connected";
|
|
22
|
-
AgentEvent["AGENT_DISCONNECTED"] = "agent_disconnected";
|
|
23
|
-
AgentEvent["POPUP_MESSAGE_VISIBLE"] = "popup_message_visible";
|
|
24
|
-
return AgentEvent;
|
|
25
|
-
}({}); // // Event data structure for listener events
|
|
26
|
-
// export interface EmbedEventData {
|
|
27
|
-
// timestamp: number; // Unix timestamp when event occurred
|
|
28
|
-
// value: boolean; // Boolean state (connected/visible = true)
|
|
29
|
-
// metadata?: {
|
|
30
|
-
// // Additional context data
|
|
31
|
-
// connectionState?: string; // LiveKit connection state
|
|
32
|
-
// roomId?: string; // Voice room identifier
|
|
33
|
-
// trigger?: 'user_interaction' | 'auto_open' | 'call_ended';
|
|
34
|
-
// previousState?: boolean; // Previous state before change
|
|
35
|
-
// // ... other contextual information
|
|
36
|
-
// [key: string]: any;
|
|
37
|
-
// };
|
|
38
|
-
// }
|
|
39
|
-
// Listener callback type
|
|
40
|
-
// export type EmbedEventListener = (data: EmbedEventData) => void;
|
|
21
|
+
var _constant = require("../utils/constant.js");
|
|
22
|
+
var _agentEventEmitter = require("./agent-event-emitter.js");
|
|
23
|
+
var _embedValidators = require("./embed.validators.js");
|
|
24
|
+
var _embedTypes = require("./embed.types.js");
|
|
25
|
+
/**
|
|
26
|
+
* Embed Event Manager
|
|
27
|
+
* Main class for managing embed events and agent communication
|
|
28
|
+
*/
|
|
29
|
+
|
|
41
30
|
class Embed {
|
|
42
31
|
events = {};
|
|
43
|
-
event = new _eventEmitter.default();
|
|
44
|
-
userDataInitialized = false;
|
|
45
32
|
|
|
46
|
-
//
|
|
47
|
-
// private ensureDefaultListener(eventKey: EventKeys) {
|
|
48
|
-
// if (!this.events[eventKey]) {
|
|
49
|
-
// this.events[eventKey] = [
|
|
50
|
-
// (data: any) => {
|
|
51
|
-
// // todo: handle default event
|
|
52
|
-
// console.log('default event', eventKey, data);
|
|
53
|
-
// },
|
|
54
|
-
// ];
|
|
55
|
-
// }
|
|
56
|
-
// }
|
|
33
|
+
// Agent event emitter for listening to agent state changes
|
|
57
34
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// todo: handle invalid event key
|
|
62
|
-
throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(EventKeys).join(', ')}`);
|
|
63
|
-
}
|
|
64
|
-
const key = eventKey;
|
|
35
|
+
constructor() {
|
|
36
|
+
this.event = new _agentEventEmitter.AgentEventEmitter();
|
|
37
|
+
}
|
|
65
38
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Automatically adds a default listener if none exists
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
ensureDefaultListener(eventKey) {
|
|
44
|
+
if (!this.events[eventKey]) {
|
|
45
|
+
this.events[eventKey] = [_data => {
|
|
46
|
+
// console.i('default event this', _data);
|
|
47
|
+
// todo: handle default event
|
|
48
|
+
}];
|
|
69
49
|
}
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Enriches event data with user identity
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
async enrichEventData(eventKey, data) {
|
|
57
|
+
if (eventKey !== 'user_data') {
|
|
58
|
+
const userIdentity = await (0, _storeKey.getAgentData)('user_data');
|
|
72
59
|
if (userIdentity) {
|
|
73
60
|
data.app_user_id = userIdentity.app_user_id;
|
|
74
61
|
} else {
|
|
75
62
|
throw new Error('User identity not found');
|
|
76
63
|
}
|
|
77
64
|
}
|
|
65
|
+
}
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Sends event data to the backend API
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async sendEventToAPI(eventKey, data, key) {
|
|
83
72
|
try {
|
|
84
73
|
const apiService = _api.APIService.getInstance();
|
|
74
|
+
const paramsData = (0, _constant.buildEventPayload)({
|
|
75
|
+
...data,
|
|
76
|
+
eventKey: key
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Validate analytics events have event_name
|
|
80
|
+
(0, _embedValidators.validateAnalyticsEvent)(paramsData);
|
|
85
81
|
const response = await apiService.updateUserData({
|
|
86
|
-
|
|
87
|
-
data
|
|
82
|
+
...paramsData
|
|
88
83
|
});
|
|
89
84
|
if (!response.success) {
|
|
90
85
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
91
86
|
}
|
|
92
87
|
(0, _storeKey.setAgentData)(data, key);
|
|
93
|
-
|
|
94
|
-
// Mark USER_DATA as initialized after successful processing
|
|
95
|
-
if (key === EventKeys.USER_DATA) {
|
|
96
|
-
this.userDataInitialized = true;
|
|
97
|
-
}
|
|
98
88
|
} catch (error) {
|
|
99
|
-
console.log('data_Event_error', key, data);
|
|
100
89
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
101
|
-
// todo: handle error triggering API
|
|
102
90
|
}
|
|
91
|
+
}
|
|
103
92
|
|
|
104
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Triggers local event listeners
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
triggerEventListeners(key, data) {
|
|
105
98
|
this.events[key]?.forEach(callback => callback(data));
|
|
106
99
|
}
|
|
107
100
|
|
|
108
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Send an event to the AI agent
|
|
103
|
+
* @param eventKey - The event type to send
|
|
104
|
+
* @param data - Event data payload
|
|
105
|
+
*/
|
|
106
|
+
async Event(eventKey, data) {
|
|
107
|
+
// Validate event key
|
|
108
|
+
(0, _embedValidators.validateEventKey)(eventKey);
|
|
109
|
+
const key = eventKey;
|
|
110
|
+
|
|
111
|
+
// Enrich event data with user identity
|
|
112
|
+
await this.enrichEventData(key, data);
|
|
113
|
+
|
|
114
|
+
// Ensure a default listener is registered
|
|
115
|
+
this.ensureDefaultListener(key);
|
|
116
|
+
|
|
117
|
+
// Send event to backend API
|
|
118
|
+
await this.sendEventToAPI(eventKey, data, key);
|
|
119
|
+
|
|
120
|
+
// Trigger local event listeners
|
|
121
|
+
this.triggerEventListeners(key, data);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Add listener for data events (legacy support)
|
|
126
|
+
* @deprecated Use event.on() for agent events instead
|
|
127
|
+
*/
|
|
109
128
|
on(eventKey, callback) {
|
|
110
129
|
if (!this.events[eventKey]) {
|
|
111
130
|
this.events[eventKey] = [];
|
|
112
131
|
}
|
|
113
132
|
this.events[eventKey]?.push(callback);
|
|
114
133
|
}
|
|
115
|
-
|
|
116
|
-
// Check if USER_DATA has been initialized
|
|
117
|
-
isUserDataInitialized() {
|
|
118
|
-
return this.userDataInitialized;
|
|
119
|
-
}
|
|
120
134
|
}
|
|
121
135
|
const embed = new Embed();
|
|
122
|
-
var _default = exports.default = embed;
|
|
136
|
+
var _default = exports.default = embed; // Re-export types and enums for convenience
|
|
123
137
|
//# sourceMappingURL=embed.event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_storeKey","require","_api","
|
|
1
|
+
{"version":3,"names":["_storeKey","require","_api","_constant","_agentEventEmitter","_embedValidators","_embedTypes","Embed","events","constructor","event","AgentEventEmitter","ensureDefaultListener","eventKey","_data","enrichEventData","data","userIdentity","getAgentData","app_user_id","Error","sendEventToAPI","key","apiService","APIService","getInstance","paramsData","buildEventPayload","validateAnalyticsEvent","response","updateUserData","success","setAgentData","error","triggerEventListeners","forEach","callback","Event","validateEventKey","on","push","embed","_default","exports","default"],"sourceRoot":"../../../src","sources":["events/embed.event.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EventKeys = exports.AgentEvent = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Types and interfaces for Embed events
|
|
9
|
+
*/
|
|
10
|
+
// Predefined event keys for sending data to the agent
|
|
11
|
+
let EventKeys = exports.EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
12
|
+
EventKeys["USER_DATA"] = "user_data";
|
|
13
|
+
EventKeys["SCREEN_STATE"] = "screen_state";
|
|
14
|
+
EventKeys["OFFER_STATE"] = "offer_state";
|
|
15
|
+
EventKeys["CUSTOM_EVENT"] = "custom_event";
|
|
16
|
+
EventKeys["FORM_STATE"] = "form_state";
|
|
17
|
+
EventKeys["ANALYTICS_DATA"] = "analytics_data";
|
|
18
|
+
EventKeys["ACTION_STATE"] = "action_state";
|
|
19
|
+
EventKeys["ERROR_STATE"] = "error_state";
|
|
20
|
+
EventKeys["SUCCESS_STATE"] = "success_state";
|
|
21
|
+
EventKeys["WARNING_STATE"] = "warning_state";
|
|
22
|
+
EventKeys["INFO_STATE"] = "info_state";
|
|
23
|
+
EventKeys["DEBUG_STATE"] = "debug_state";
|
|
24
|
+
return EventKeys;
|
|
25
|
+
}({}); // Agent event keys for listening to agent state changes
|
|
26
|
+
let AgentEvent = exports.AgentEvent = /*#__PURE__*/function (AgentEvent) {
|
|
27
|
+
AgentEvent["AGENT_CONNECTED"] = "agent_connected";
|
|
28
|
+
AgentEvent["AGENT_DISCONNECTED"] = "agent_disconnected";
|
|
29
|
+
AgentEvent["POPUP_MESSAGE_VISIBLE"] = "popup_message_visible";
|
|
30
|
+
return AgentEvent;
|
|
31
|
+
}({}); // Event data interfaces
|
|
32
|
+
//# sourceMappingURL=embed.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EventKeys","exports","AgentEvent"],"sourceRoot":"../../../src","sources":["events/embed.types.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AAIA;AAAA,IACYA,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAerB;AAAA,IACYE,UAAU,GAAAD,OAAA,CAAAC,UAAA,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA,OAMtB","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateAnalyticsEvent = validateAnalyticsEvent;
|
|
7
|
+
exports.validateEventKey = validateEventKey;
|
|
8
|
+
var _embedTypes = require("./embed.types.js");
|
|
9
|
+
/**
|
|
10
|
+
* Validation helpers for Embed events
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validates event key is valid
|
|
15
|
+
* @param eventKey - The event key to validate
|
|
16
|
+
* @throws Error if event key is invalid
|
|
17
|
+
*/
|
|
18
|
+
function validateEventKey(eventKey) {
|
|
19
|
+
if (!Object.values(_embedTypes.EventKeys).includes(eventKey)) {
|
|
20
|
+
throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(_embedTypes.EventKeys).join(', ')}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Validates analytics events have required event_name
|
|
26
|
+
* @param paramsData - The event payload to validate
|
|
27
|
+
* @throws Error if analytics event is missing event_name
|
|
28
|
+
*/
|
|
29
|
+
function validateAnalyticsEvent(paramsData) {
|
|
30
|
+
if (paramsData.type === 'analytics_data') {
|
|
31
|
+
if (!paramsData.event_name || paramsData.event_name.trim() === '') {
|
|
32
|
+
throw new Error(`Analytics event requires an event_name. Please provide event_name in the data payload.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=embed.validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_embedTypes","require","validateEventKey","eventKey","Object","values","EventKeys","includes","Error","join","validateAnalyticsEvent","paramsData","type","event_name","trim"],"sourceRoot":"../../../src","sources":["events/embed.validators.ts"],"mappings":";;;;;;;AAKA,IAAAA,WAAA,GAAAC,OAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAACC,QAAgB,EAAQ;EACvD,IAAI,CAACC,MAAM,CAACC,MAAM,CAACC,qBAAS,CAAC,CAACC,QAAQ,CAACJ,QAAqB,CAAC,EAAE;IAC7D,MAAM,IAAIK,KAAK,CACb,sBAAsBL,QAAQ,qBAAqBC,MAAM,CAACC,MAAM,CAACC,qBAAS,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC,EACxF,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,sBAAsBA,CAACC,UAAwB,EAAQ;EACrE,IAAIA,UAAU,CAACC,IAAI,KAAK,gBAAgB,EAAE;IACxC,IAAI,CAACD,UAAU,CAACE,UAAU,IAAIF,UAAU,CAACE,UAAU,CAACC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;MACjE,MAAM,IAAIN,KAAK,CACb,wFACF,CAAC;IACH;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AgentEvent", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _embedTypes.AgentEvent;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "AgentEventEmitter", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _agentEventEmitter.AgentEventEmitter;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "EventKeys", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _embedTypes.EventKeys;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "default", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _embedEvent.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "validateAnalyticsEvent", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _embedValidators.validateAnalyticsEvent;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "validateEventKey", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _embedValidators.validateEventKey;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _embedEvent = _interopRequireDefault(require("./embed.event.js"));
|
|
43
|
+
var _embedTypes = require("./embed.types.js");
|
|
44
|
+
var _agentEventEmitter = require("./agent-event-emitter.js");
|
|
45
|
+
var _embedValidators = require("./embed.validators.js");
|
|
46
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_embedEvent","_interopRequireDefault","require","_embedTypes","_agentEventEmitter","_embedValidators","e","__esModule","default"],"sourceRoot":"../../../src","sources":["events/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAOA,IAAAE,kBAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AAA8E,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePopupAnimatedStyles = exports.useButtonAnimations = exports.useButtonAnimatedStyles = exports.useBreathingAnimation = exports.useAnimationValues = exports.createPanGesture = exports.Animated = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
9
|
+
var _reanimatedHelper = require("../utils/reanimated.helper.js");
|
|
10
|
+
var _EmbedButtonHelpers = require("./EmbedButton.helpers.js");
|
|
11
|
+
/**
|
|
12
|
+
* @file EmbedButton.animations.ts
|
|
13
|
+
* @description Animation logic and hooks for the EmbedButton component
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Get reanimated API with fallbacks
|
|
17
|
+
const {
|
|
18
|
+
useSharedValue,
|
|
19
|
+
useAnimatedStyle,
|
|
20
|
+
withTiming,
|
|
21
|
+
withSpring,
|
|
22
|
+
withRepeat,
|
|
23
|
+
withSequence,
|
|
24
|
+
runOnJS,
|
|
25
|
+
Easing,
|
|
26
|
+
Animated,
|
|
27
|
+
isAvailable: isReanimatedAvailable
|
|
28
|
+
} = (0, _reanimatedHelper.getReanimatedAPI)();
|
|
29
|
+
|
|
30
|
+
// Show warning if reanimated is not available
|
|
31
|
+
exports.Animated = Animated;
|
|
32
|
+
if (!isReanimatedAvailable) {
|
|
33
|
+
(0, _reanimatedHelper.showReanimatedSetupError)();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Export the Animated component for use in the main component
|
|
37
|
+
|
|
38
|
+
// ==================== ANIMATION VALUES HOOK ====================
|
|
39
|
+
/**
|
|
40
|
+
* Hook to initialize and manage all animation shared values
|
|
41
|
+
*/
|
|
42
|
+
const useAnimationValues = () => {
|
|
43
|
+
const isPressed = useSharedValue(false);
|
|
44
|
+
const offset = useSharedValue({
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
});
|
|
48
|
+
const start = useSharedValue({
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0
|
|
51
|
+
});
|
|
52
|
+
const menuAnimation = useSharedValue(0);
|
|
53
|
+
const buttonWidth = useSharedValue(_EmbedButtonHelpers.BUTTON_DIMENSIONS.WIDTH);
|
|
54
|
+
const buttonScale = useSharedValue(1);
|
|
55
|
+
return {
|
|
56
|
+
isPressed,
|
|
57
|
+
offset,
|
|
58
|
+
start,
|
|
59
|
+
menuAnimation,
|
|
60
|
+
buttonWidth,
|
|
61
|
+
buttonScale
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// ==================== BUTTON ANIMATIONS ====================
|
|
66
|
+
/**
|
|
67
|
+
* Hook to handle button expand/collapse animations
|
|
68
|
+
*/
|
|
69
|
+
exports.useAnimationValues = useAnimationValues;
|
|
70
|
+
const useButtonAnimations = (isOpen, menuAnimation, buttonWidth) => {
|
|
71
|
+
(0, _react.useEffect)(() => {
|
|
72
|
+
menuAnimation.value = withTiming(isOpen ? 0.8 : 0, {
|
|
73
|
+
duration: 300
|
|
74
|
+
});
|
|
75
|
+
buttonWidth.value = withTiming(isOpen ? _EmbedButtonHelpers.BUTTON_DIMENSIONS.EXPANDED_WIDTH : _EmbedButtonHelpers.BUTTON_DIMENSIONS.WIDTH);
|
|
76
|
+
}, [isOpen, menuAnimation, buttonWidth]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// ==================== BREATHING ANIMATION ====================
|
|
80
|
+
/**
|
|
81
|
+
* Hook to handle breathing animation when auto-popup is shown
|
|
82
|
+
*/
|
|
83
|
+
exports.useButtonAnimations = useButtonAnimations;
|
|
84
|
+
const useBreathingAnimation = (isOpen, isAutoOpen, buttonScale) => {
|
|
85
|
+
(0, _react.useEffect)(() => {
|
|
86
|
+
if (!isOpen && isAutoOpen) {
|
|
87
|
+
// Start breathing animation
|
|
88
|
+
buttonScale.value = withRepeat(withSequence(withTiming(1.1, {
|
|
89
|
+
duration: 1500,
|
|
90
|
+
easing: Easing.inOut(Easing.ease)
|
|
91
|
+
}), withTiming(1, {
|
|
92
|
+
duration: 1500,
|
|
93
|
+
easing: Easing.inOut(Easing.ease)
|
|
94
|
+
})), -1,
|
|
95
|
+
// Infinite repeat
|
|
96
|
+
false);
|
|
97
|
+
} else {
|
|
98
|
+
// Reset animation
|
|
99
|
+
buttonScale.value = withTiming(1, {
|
|
100
|
+
duration: 300
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}, [buttonScale, isAutoOpen, isOpen]);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// ==================== ANIMATED STYLES ====================
|
|
107
|
+
/**
|
|
108
|
+
* Hook to create animated styles for the button
|
|
109
|
+
*/
|
|
110
|
+
exports.useBreathingAnimation = useBreathingAnimation;
|
|
111
|
+
const useButtonAnimatedStyles = (isOpen, offset, buttonWidth, isPressed, buttonScale) => {
|
|
112
|
+
return useAnimatedStyle(() => {
|
|
113
|
+
const maxX = (0, _EmbedButtonHelpers.calculateMaxX)(isOpen);
|
|
114
|
+
const clampedX = (0, _EmbedButtonHelpers.clamp)(offset.value.x, -maxX, 0);
|
|
115
|
+
return {
|
|
116
|
+
width: buttonWidth.value,
|
|
117
|
+
height: _EmbedButtonHelpers.BUTTON_DIMENSIONS.HEIGHT,
|
|
118
|
+
transform: [{
|
|
119
|
+
translateX: clampedX
|
|
120
|
+
}, {
|
|
121
|
+
translateY: offset.value.y
|
|
122
|
+
}, {
|
|
123
|
+
scale: withSpring(isPressed.value ? 0.95 : buttonScale.value)
|
|
124
|
+
}],
|
|
125
|
+
justifyContent: isOpen ? 'space-between' : 'flex-start',
|
|
126
|
+
overflow: 'hidden'
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Hook to create animated styles for the popup text
|
|
133
|
+
*/
|
|
134
|
+
exports.useButtonAnimatedStyles = useButtonAnimatedStyles;
|
|
135
|
+
const usePopupAnimatedStyles = (offset, isPressed) => {
|
|
136
|
+
return useAnimatedStyle(() => {
|
|
137
|
+
const maxX = _EmbedButtonHelpers.SCREEN_WIDTH;
|
|
138
|
+
const clampedX = (0, _EmbedButtonHelpers.clamp)(offset.value.x, -maxX, 0);
|
|
139
|
+
return {
|
|
140
|
+
transform: [{
|
|
141
|
+
translateX: clampedX
|
|
142
|
+
}, {
|
|
143
|
+
translateY: offset.value.y
|
|
144
|
+
}, {
|
|
145
|
+
scale: withSpring(isPressed.value ? 1 : 1)
|
|
146
|
+
}]
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// ==================== GESTURE HANDLER ====================
|
|
152
|
+
/**
|
|
153
|
+
* Create pan gesture for drag functionality
|
|
154
|
+
*/
|
|
155
|
+
exports.usePopupAnimatedStyles = usePopupAnimatedStyles;
|
|
156
|
+
const createPanGesture = (isPressed, offset, start, isOpen, setIsAutoOpen) => {
|
|
157
|
+
return _reactNativeGestureHandler.Gesture.Pan().onBegin(() => {
|
|
158
|
+
isPressed.value = true;
|
|
159
|
+
if (setIsAutoOpen) {
|
|
160
|
+
runOnJS(setIsAutoOpen)(false);
|
|
161
|
+
}
|
|
162
|
+
}).onUpdate(e => {
|
|
163
|
+
const maxX = (0, _EmbedButtonHelpers.calculateMaxX)(isOpen);
|
|
164
|
+
const maxY = (0, _EmbedButtonHelpers.calculateMaxY)();
|
|
165
|
+
const newX = (0, _EmbedButtonHelpers.clamp)(e.translationX + start.value.x, -maxX, 0);
|
|
166
|
+
const newY = (0, _EmbedButtonHelpers.clamp)(e.translationY + start.value.y, -maxY, 0);
|
|
167
|
+
offset.value = {
|
|
168
|
+
x: newX,
|
|
169
|
+
y: newY
|
|
170
|
+
};
|
|
171
|
+
}).onEnd(() => {
|
|
172
|
+
start.value = {
|
|
173
|
+
x: offset.value.x,
|
|
174
|
+
y: offset.value.y
|
|
175
|
+
};
|
|
176
|
+
}).onFinalize(() => {
|
|
177
|
+
isPressed.value = false;
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
exports.createPanGesture = createPanGesture;
|
|
181
|
+
//# sourceMappingURL=EmbedButton.animations.js.map
|