@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,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent Event Emitter
|
|
5
|
+
* Handles listening to agent state changes (connection, disconnection, popup visibility)
|
|
6
|
+
* Also sends agent events to the backend API
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getAgentData } from "../store/store.key.js";
|
|
10
|
+
import { APIService } from "../api/api.js";
|
|
11
|
+
import { buildEventPayload } from "../utils/constant.js";
|
|
12
|
+
import { EventKeys } from "./embed.types.js";
|
|
13
|
+
export class AgentEventEmitter {
|
|
14
|
+
agentListeners = {};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Add an event listener for agent events
|
|
18
|
+
* @param eventKey - The agent event to listen for
|
|
19
|
+
* @param callback - Callback function to execute when event fires
|
|
20
|
+
*/
|
|
21
|
+
on(eventKey, callback) {
|
|
22
|
+
if (!this.agentListeners[eventKey]) {
|
|
23
|
+
this.agentListeners[eventKey] = [];
|
|
24
|
+
}
|
|
25
|
+
this.agentListeners[eventKey]?.push(callback);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Remove an event listener for agent events
|
|
30
|
+
* @param eventKey - The agent event to stop listening to
|
|
31
|
+
* @param callback - The callback function to remove
|
|
32
|
+
*/
|
|
33
|
+
off(eventKey, callback) {
|
|
34
|
+
if (!this.agentListeners[eventKey]) return;
|
|
35
|
+
const index = this.agentListeners[eventKey]?.indexOf(callback);
|
|
36
|
+
if (index !== undefined && index > -1) {
|
|
37
|
+
this.agentListeners[eventKey]?.splice(index, 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Emit an agent event to all registered listeners AND send to backend
|
|
43
|
+
* @param eventKey - The agent event to emit
|
|
44
|
+
* @param data - Data to pass to listeners
|
|
45
|
+
* @internal - Used internally by the library
|
|
46
|
+
*/
|
|
47
|
+
async emit(eventKey, data) {
|
|
48
|
+
// Trigger local event listeners first
|
|
49
|
+
this.agentListeners[eventKey]?.forEach(callback => {
|
|
50
|
+
try {
|
|
51
|
+
callback(data);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(`Error in agent event listener for ${eventKey}:`, error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Send to backend API
|
|
58
|
+
await this.sendToBackend(eventKey, data);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Send agent event data to backend API
|
|
63
|
+
* @param eventKey - The agent event type
|
|
64
|
+
* @param data - Event data
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
async sendToBackend(eventKey, data) {
|
|
68
|
+
try {
|
|
69
|
+
// Get user identity to include app_user_id
|
|
70
|
+
const userIdentity = await getAgentData(EventKeys.USER_DATA);
|
|
71
|
+
if (!userIdentity?.app_user_id) {
|
|
72
|
+
console.warn(`[AgentEvent] Cannot send ${eventKey} to backend: User identity not found`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Prepare payload with app_user_id
|
|
77
|
+
const payload = {
|
|
78
|
+
...data,
|
|
79
|
+
app_user_id: userIdentity.app_user_id,
|
|
80
|
+
eventKey: eventKey,
|
|
81
|
+
eventType: 'agent_event'
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Send to API
|
|
85
|
+
const apiService = APIService.getInstance();
|
|
86
|
+
const paramsData = buildEventPayload(payload);
|
|
87
|
+
const response = await apiService.updateUserData(paramsData);
|
|
88
|
+
if (!response.success) {
|
|
89
|
+
console.error(`[AgentEvent] Failed to send ${eventKey} to backend:`, response.error);
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error(`[AgentEvent] Error sending ${eventKey} to backend:`, error);
|
|
93
|
+
// Fail silently - agent events should not break the app
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Remove all listeners for a specific event
|
|
99
|
+
* @param eventKey - The agent event to clear listeners for
|
|
100
|
+
*/
|
|
101
|
+
removeAllListeners(eventKey) {
|
|
102
|
+
if (eventKey) {
|
|
103
|
+
delete this.agentListeners[eventKey];
|
|
104
|
+
} else {
|
|
105
|
+
this.agentListeners = {};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=agent-event-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getAgentData","APIService","buildEventPayload","EventKeys","AgentEventEmitter","agentListeners","on","eventKey","callback","push","off","index","indexOf","undefined","splice","emit","data","forEach","error","console","sendToBackend","userIdentity","USER_DATA","app_user_id","warn","payload","eventType","apiService","getInstance","paramsData","response","updateUserData","success","removeAllListeners"],"sourceRoot":"../../../src","sources":["events/agent-event-emitter.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,uBAAoB;AACjD,SAASC,UAAU,QAAQ,eAAY;AACvC,SAASC,iBAAiB,QAAQ,sBAAmB;AAErD,SA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aAAaA,CAACb,QAAoB,EAAES,IAAS,EAAiB;IAC1E,IAAI;MACF;MACA,MAAMK,YAAY,GAAG,MAAMrB,YAAY,CAACG,SAAS,CAACmB,SAAS,CAAC;MAC5D,IAAI,CAACD,YAAY,EAAEE,WAAW,EAAE;QAC9BJ,OAAO,CAACK,IAAI,CACV,4BAA4BjB,QAAQ,sCACtC,CAAC;QACD;MACF;;MAEA;MACA,MAAMkB,OAAO,GAAG;QACd,GAAGT,IAAI;QACPO,WAAW,EAAEF,YAAY,CAACE,WAAW;QACrChB,QAAQ,EAAEA,QAAQ;QAClBmB,SAAS,EAAE;MACb,CAAC;;MAED;MACA,MAAMC,UAAU,GAAG1B,UAAU,CAAC2B,WAAW,CAAC,CAAC;MAC3C,MAAMC,UAAU,GAAG3B,iBAAiB,CAACuB,OAAO,CAAC;MAC7C,MAAMK,QAAQ,GAAG,MAAMH,UAAU,CAACI,cAAc,CAACF,UAAU,CAAC;MAE5D,IAAI,CAACC,QAAQ,CAACE,OAAO,EAAE;QACrBb,OAAO,CAACD,KAAK,CACX,+BAA+BX,QAAQ,cAAc,EACrDuB,QAAQ,CAACZ,KACX,CAAC;MACH;IACF,CAAC,CAAC,OAAOA,KAAK,EAAE;MACdC,OAAO,CAACD,KAAK,CACX,8BAA8BX,QAAQ,cAAc,EACpDW,KACF,CAAC;MACD;IACF;EACF;;EAEA;AACF;AACA;AACA;EACEe,kBAAkBA,CAAC1B,QAAqB,EAAQ;IAC9C,IAAIA,QAAQ,EAAE;MACZ,OAAO,IAAI,CAACF,cAAc,CAACE,QAAQ,CAAC;IACtC,CAAC,MAAM;MACL,IAAI,CAACF,cAAc,GAAG,CAAC,CAAC;IAC1B;EACF;AACF","ignoreList":[]}
|
|
@@ -1,121 +1,123 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Embed Event Manager
|
|
5
|
+
* Main class for managing embed events and agent communication
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
import { getAgentData, setAgentData } from "../store/store.key.js";
|
|
4
9
|
import { APIService } from "../api/api.js";
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
EventKeys["USER_DATA"] = "user_data";
|
|
9
|
-
EventKeys["SCREEN_STATE"] = "screen_state";
|
|
10
|
-
EventKeys["OFFER_STATE"] = "offer_state";
|
|
11
|
-
EventKeys["SCREEN_VIEW"] = "screen_view";
|
|
12
|
-
EventKeys["FORM_STATE"] = "form_state";
|
|
13
|
-
return EventKeys;
|
|
14
|
-
}({});
|
|
15
|
-
export let AgentEvent = /*#__PURE__*/function (AgentEvent) {
|
|
16
|
-
AgentEvent["AGENT_CONNECTED"] = "agent_connected";
|
|
17
|
-
AgentEvent["AGENT_DISCONNECTED"] = "agent_disconnected";
|
|
18
|
-
AgentEvent["POPUP_MESSAGE_VISIBLE"] = "popup_message_visible";
|
|
19
|
-
return AgentEvent;
|
|
20
|
-
}({});
|
|
21
|
-
// // Event data structure for listener events
|
|
22
|
-
// export interface EmbedEventData {
|
|
23
|
-
// timestamp: number; // Unix timestamp when event occurred
|
|
24
|
-
// value: boolean; // Boolean state (connected/visible = true)
|
|
25
|
-
// metadata?: {
|
|
26
|
-
// // Additional context data
|
|
27
|
-
// connectionState?: string; // LiveKit connection state
|
|
28
|
-
// roomId?: string; // Voice room identifier
|
|
29
|
-
// trigger?: 'user_interaction' | 'auto_open' | 'call_ended';
|
|
30
|
-
// previousState?: boolean; // Previous state before change
|
|
31
|
-
// // ... other contextual information
|
|
32
|
-
// [key: string]: any;
|
|
33
|
-
// };
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
// Listener callback type
|
|
37
|
-
// export type EmbedEventListener = (data: EmbedEventData) => void;
|
|
38
|
-
|
|
10
|
+
import { buildEventPayload } from "../utils/constant.js";
|
|
11
|
+
import { AgentEventEmitter } from "./agent-event-emitter.js";
|
|
12
|
+
import { validateEventKey, validateAnalyticsEvent } from "./embed.validators.js";
|
|
39
13
|
class Embed {
|
|
40
14
|
events = {};
|
|
41
|
-
event = new TypedEventEmitter();
|
|
42
|
-
userDataInitialized = false;
|
|
43
|
-
|
|
44
|
-
// Automatically adds a default listener if none exists
|
|
45
|
-
// private ensureDefaultListener(eventKey: EventKeys) {
|
|
46
|
-
// if (!this.events[eventKey]) {
|
|
47
|
-
// this.events[eventKey] = [
|
|
48
|
-
// (data: any) => {
|
|
49
|
-
// // todo: handle default event
|
|
50
|
-
// console.log('default event', eventKey, data);
|
|
51
|
-
// },
|
|
52
|
-
// ];
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
55
15
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
const key = eventKey;
|
|
16
|
+
// Agent event emitter for listening to agent state changes
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
this.event = new AgentEventEmitter();
|
|
20
|
+
}
|
|
63
21
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Automatically adds a default listener if none exists
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
ensureDefaultListener(eventKey) {
|
|
27
|
+
if (!this.events[eventKey]) {
|
|
28
|
+
this.events[eventKey] = [_data => {
|
|
29
|
+
// console.i('default event this', _data);
|
|
30
|
+
// todo: handle default event
|
|
31
|
+
}];
|
|
67
32
|
}
|
|
68
|
-
|
|
69
|
-
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Enriches event data with user identity
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
async enrichEventData(eventKey, data) {
|
|
40
|
+
if (eventKey !== 'user_data') {
|
|
41
|
+
const userIdentity = await getAgentData('user_data');
|
|
70
42
|
if (userIdentity) {
|
|
71
43
|
data.app_user_id = userIdentity.app_user_id;
|
|
72
44
|
} else {
|
|
73
45
|
throw new Error('User identity not found');
|
|
74
46
|
}
|
|
75
47
|
}
|
|
48
|
+
}
|
|
76
49
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Sends event data to the backend API
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
async sendEventToAPI(eventKey, data, key) {
|
|
81
55
|
try {
|
|
82
56
|
const apiService = APIService.getInstance();
|
|
57
|
+
const paramsData = buildEventPayload({
|
|
58
|
+
...data,
|
|
59
|
+
eventKey: key
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Validate analytics events have event_name
|
|
63
|
+
validateAnalyticsEvent(paramsData);
|
|
83
64
|
const response = await apiService.updateUserData({
|
|
84
|
-
|
|
85
|
-
data
|
|
65
|
+
...paramsData
|
|
86
66
|
});
|
|
87
67
|
if (!response.success) {
|
|
88
68
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
89
69
|
}
|
|
90
70
|
setAgentData(data, key);
|
|
91
|
-
|
|
92
|
-
// Mark USER_DATA as initialized after successful processing
|
|
93
|
-
if (key === EventKeys.USER_DATA) {
|
|
94
|
-
this.userDataInitialized = true;
|
|
95
|
-
}
|
|
96
71
|
} catch (error) {
|
|
97
|
-
console.log('data_Event_error', key, data);
|
|
98
72
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
99
|
-
// todo: handle error triggering API
|
|
100
73
|
}
|
|
74
|
+
}
|
|
101
75
|
|
|
102
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Triggers local event listeners
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
triggerEventListeners(key, data) {
|
|
103
81
|
this.events[key]?.forEach(callback => callback(data));
|
|
104
82
|
}
|
|
105
83
|
|
|
106
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Send an event to the AI agent
|
|
86
|
+
* @param eventKey - The event type to send
|
|
87
|
+
* @param data - Event data payload
|
|
88
|
+
*/
|
|
89
|
+
async Event(eventKey, data) {
|
|
90
|
+
// Validate event key
|
|
91
|
+
validateEventKey(eventKey);
|
|
92
|
+
const key = eventKey;
|
|
93
|
+
|
|
94
|
+
// Enrich event data with user identity
|
|
95
|
+
await this.enrichEventData(key, data);
|
|
96
|
+
|
|
97
|
+
// Ensure a default listener is registered
|
|
98
|
+
this.ensureDefaultListener(key);
|
|
99
|
+
|
|
100
|
+
// Send event to backend API
|
|
101
|
+
await this.sendEventToAPI(eventKey, data, key);
|
|
102
|
+
|
|
103
|
+
// Trigger local event listeners
|
|
104
|
+
this.triggerEventListeners(key, data);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Add listener for data events (legacy support)
|
|
109
|
+
* @deprecated Use event.on() for agent events instead
|
|
110
|
+
*/
|
|
107
111
|
on(eventKey, callback) {
|
|
108
112
|
if (!this.events[eventKey]) {
|
|
109
113
|
this.events[eventKey] = [];
|
|
110
114
|
}
|
|
111
115
|
this.events[eventKey]?.push(callback);
|
|
112
116
|
}
|
|
113
|
-
|
|
114
|
-
// Check if USER_DATA has been initialized
|
|
115
|
-
isUserDataInitialized() {
|
|
116
|
-
return this.userDataInitialized;
|
|
117
|
-
}
|
|
118
117
|
}
|
|
119
118
|
const embed = new Embed();
|
|
120
119
|
export default embed;
|
|
120
|
+
|
|
121
|
+
// Re-export types and enums for convenience
|
|
122
|
+
export { EventKeys, AgentEvent } from "./embed.types.js";
|
|
121
123
|
//# sourceMappingURL=embed.event.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getAgentData","setAgentData","APIService","
|
|
1
|
+
{"version":3,"names":["getAgentData","setAgentData","APIService","buildEventPayload","AgentEventEmitter","validateEventKey","validateAnalyticsEvent","Embed","events","constructor","event","ensureDefaultListener","eventKey","_data","enrichEventData","data","userIdentity","app_user_id","Error","sendEventToAPI","key","apiService","getInstance","paramsData","response","updateUserData","success","error","triggerEventListeners","forEach","callback","Event","on","push","embed","EventKeys","AgentEvent"],"sourceRoot":"../../../src","sources":["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AAQ,CAAC,EAAEqB,IAAI,CAACH,QAAQ,CAAC;EACvC;AACF;AAEA,MAAMI,KAAK,GAAG,IAAI3B,KAAK,CAAC,CAAC;AACzB,eAAe2B,KAAK;;AAEpB;AACA,SAASC,SAAS,EAAEC,UAAU,QAAQ,kBAAe","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Types and interfaces for Embed events
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Predefined event keys for sending data to the agent
|
|
8
|
+
export let EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
9
|
+
EventKeys["USER_DATA"] = "user_data";
|
|
10
|
+
EventKeys["SCREEN_STATE"] = "screen_state";
|
|
11
|
+
EventKeys["OFFER_STATE"] = "offer_state";
|
|
12
|
+
EventKeys["CUSTOM_EVENT"] = "custom_event";
|
|
13
|
+
EventKeys["FORM_STATE"] = "form_state";
|
|
14
|
+
EventKeys["ANALYTICS_DATA"] = "analytics_data";
|
|
15
|
+
EventKeys["ACTION_STATE"] = "action_state";
|
|
16
|
+
EventKeys["ERROR_STATE"] = "error_state";
|
|
17
|
+
EventKeys["SUCCESS_STATE"] = "success_state";
|
|
18
|
+
EventKeys["WARNING_STATE"] = "warning_state";
|
|
19
|
+
EventKeys["INFO_STATE"] = "info_state";
|
|
20
|
+
EventKeys["DEBUG_STATE"] = "debug_state";
|
|
21
|
+
return EventKeys;
|
|
22
|
+
}({});
|
|
23
|
+
|
|
24
|
+
// Agent event keys for listening to agent state changes
|
|
25
|
+
export let AgentEvent = /*#__PURE__*/function (AgentEvent) {
|
|
26
|
+
AgentEvent["AGENT_CONNECTED"] = "agent_connected";
|
|
27
|
+
AgentEvent["AGENT_DISCONNECTED"] = "agent_disconnected";
|
|
28
|
+
AgentEvent["POPUP_MESSAGE_VISIBLE"] = "popup_message_visible";
|
|
29
|
+
return AgentEvent;
|
|
30
|
+
}({});
|
|
31
|
+
|
|
32
|
+
// Event data interfaces
|
|
33
|
+
//# sourceMappingURL=embed.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EventKeys","AgentEvent"],"sourceRoot":"../../../src","sources":["events/embed.types.ts"],"mappings":";;AAAA;AACA;AACA;;AAIA;AACA,WAAYA,SAAS,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;;AAerB;AACA,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;;AAMtB","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validation helpers for Embed events
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { EventKeys } from "./embed.types.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Validates event key is valid
|
|
11
|
+
* @param eventKey - The event key to validate
|
|
12
|
+
* @throws Error if event key is invalid
|
|
13
|
+
*/
|
|
14
|
+
export function validateEventKey(eventKey) {
|
|
15
|
+
if (!Object.values(EventKeys).includes(eventKey)) {
|
|
16
|
+
throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(EventKeys).join(', ')}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Validates analytics events have required event_name
|
|
22
|
+
* @param paramsData - The event payload to validate
|
|
23
|
+
* @throws Error if analytics event is missing event_name
|
|
24
|
+
*/
|
|
25
|
+
export function validateAnalyticsEvent(paramsData) {
|
|
26
|
+
if (paramsData.type === 'analytics_data') {
|
|
27
|
+
if (!paramsData.event_name || paramsData.event_name.trim() === '') {
|
|
28
|
+
throw new Error(`Analytics event requires an event_name. Please provide event_name in the data payload.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=embed.validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EventKeys","validateEventKey","eventKey","Object","values","includes","Error","join","validateAnalyticsEvent","paramsData","type","event_name","trim"],"sourceRoot":"../../../src","sources":["events/embed.validators.ts"],"mappings":";;AAAA;AACA;AACA;;AAGA,SAASA,SAAS,QAAQ,kBAAe;;AAEzC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,QAAgB,EAAQ;EACvD,IAAI,CAACC,MAAM,CAACC,MAAM,CAACJ,SAAS,CAAC,CAACK,QAAQ,CAACH,QAAqB,CAAC,EAAE;IAC7D,MAAM,IAAII,KAAK,CACb,sBAAsBJ,QAAQ,qBAAqBC,MAAM,CAACC,MAAM,CAACJ,SAAS,CAAC,CAACO,IAAI,CAAC,IAAI,CAAC,EACxF,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,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,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Events module
|
|
5
|
+
* Exports the main Embed event manager and related types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { default } from "./embed.event.js";
|
|
9
|
+
export { EventKeys, AgentEvent } from "./embed.types.js";
|
|
10
|
+
export { AgentEventEmitter } from "./agent-event-emitter.js";
|
|
11
|
+
export { validateEventKey, validateAnalyticsEvent } from "./embed.validators.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["default","EventKeys","AgentEvent","AgentEventEmitter","validateEventKey","validateAnalyticsEvent"],"sourceRoot":"../../../src","sources":["events/index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,kBAAe;AACvC,SAASC,SAAS,EAAEC,UAAU,QAAQ,kBAAe;AAOrD,SAASC,iBAAiB,QAAQ,0BAAuB;AACzD,SAASC,gBAAgB,EAAEC,sBAAsB,QAAQ,uBAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file EmbedButton.animations.ts
|
|
5
|
+
* @description Animation logic and hooks for the EmbedButton component
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useEffect } from 'react';
|
|
9
|
+
import { Gesture } from 'react-native-gesture-handler';
|
|
10
|
+
import { getReanimatedAPI, showReanimatedSetupError } from "../utils/reanimated.helper.js";
|
|
11
|
+
import { BUTTON_DIMENSIONS, calculateMaxX, calculateMaxY, clamp, SCREEN_WIDTH } from "./EmbedButton.helpers.js";
|
|
12
|
+
|
|
13
|
+
// Get reanimated API with fallbacks
|
|
14
|
+
const {
|
|
15
|
+
useSharedValue,
|
|
16
|
+
useAnimatedStyle,
|
|
17
|
+
withTiming,
|
|
18
|
+
withSpring,
|
|
19
|
+
withRepeat,
|
|
20
|
+
withSequence,
|
|
21
|
+
runOnJS,
|
|
22
|
+
Easing,
|
|
23
|
+
Animated,
|
|
24
|
+
isAvailable: isReanimatedAvailable
|
|
25
|
+
} = getReanimatedAPI();
|
|
26
|
+
|
|
27
|
+
// Show warning if reanimated is not available
|
|
28
|
+
if (!isReanimatedAvailable) {
|
|
29
|
+
showReanimatedSetupError();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Export the Animated component for use in the main component
|
|
33
|
+
export { Animated };
|
|
34
|
+
|
|
35
|
+
// ==================== ANIMATION VALUES HOOK ====================
|
|
36
|
+
/**
|
|
37
|
+
* Hook to initialize and manage all animation shared values
|
|
38
|
+
*/
|
|
39
|
+
export const useAnimationValues = () => {
|
|
40
|
+
const isPressed = useSharedValue(false);
|
|
41
|
+
const offset = useSharedValue({
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0
|
|
44
|
+
});
|
|
45
|
+
const start = useSharedValue({
|
|
46
|
+
x: 0,
|
|
47
|
+
y: 0
|
|
48
|
+
});
|
|
49
|
+
const menuAnimation = useSharedValue(0);
|
|
50
|
+
const buttonWidth = useSharedValue(BUTTON_DIMENSIONS.WIDTH);
|
|
51
|
+
const buttonScale = useSharedValue(1);
|
|
52
|
+
return {
|
|
53
|
+
isPressed,
|
|
54
|
+
offset,
|
|
55
|
+
start,
|
|
56
|
+
menuAnimation,
|
|
57
|
+
buttonWidth,
|
|
58
|
+
buttonScale
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// ==================== BUTTON ANIMATIONS ====================
|
|
63
|
+
/**
|
|
64
|
+
* Hook to handle button expand/collapse animations
|
|
65
|
+
*/
|
|
66
|
+
export const useButtonAnimations = (isOpen, menuAnimation, buttonWidth) => {
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
menuAnimation.value = withTiming(isOpen ? 0.8 : 0, {
|
|
69
|
+
duration: 300
|
|
70
|
+
});
|
|
71
|
+
buttonWidth.value = withTiming(isOpen ? BUTTON_DIMENSIONS.EXPANDED_WIDTH : BUTTON_DIMENSIONS.WIDTH);
|
|
72
|
+
}, [isOpen, menuAnimation, buttonWidth]);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ==================== BREATHING ANIMATION ====================
|
|
76
|
+
/**
|
|
77
|
+
* Hook to handle breathing animation when auto-popup is shown
|
|
78
|
+
*/
|
|
79
|
+
export const useBreathingAnimation = (isOpen, isAutoOpen, buttonScale) => {
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!isOpen && isAutoOpen) {
|
|
82
|
+
// Start breathing animation
|
|
83
|
+
buttonScale.value = withRepeat(withSequence(withTiming(1.1, {
|
|
84
|
+
duration: 1500,
|
|
85
|
+
easing: Easing.inOut(Easing.ease)
|
|
86
|
+
}), withTiming(1, {
|
|
87
|
+
duration: 1500,
|
|
88
|
+
easing: Easing.inOut(Easing.ease)
|
|
89
|
+
})), -1,
|
|
90
|
+
// Infinite repeat
|
|
91
|
+
false);
|
|
92
|
+
} else {
|
|
93
|
+
// Reset animation
|
|
94
|
+
buttonScale.value = withTiming(1, {
|
|
95
|
+
duration: 300
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, [buttonScale, isAutoOpen, isOpen]);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// ==================== ANIMATED STYLES ====================
|
|
102
|
+
/**
|
|
103
|
+
* Hook to create animated styles for the button
|
|
104
|
+
*/
|
|
105
|
+
export const useButtonAnimatedStyles = (isOpen, offset, buttonWidth, isPressed, buttonScale) => {
|
|
106
|
+
return useAnimatedStyle(() => {
|
|
107
|
+
const maxX = calculateMaxX(isOpen);
|
|
108
|
+
const clampedX = clamp(offset.value.x, -maxX, 0);
|
|
109
|
+
return {
|
|
110
|
+
width: buttonWidth.value,
|
|
111
|
+
height: BUTTON_DIMENSIONS.HEIGHT,
|
|
112
|
+
transform: [{
|
|
113
|
+
translateX: clampedX
|
|
114
|
+
}, {
|
|
115
|
+
translateY: offset.value.y
|
|
116
|
+
}, {
|
|
117
|
+
scale: withSpring(isPressed.value ? 0.95 : buttonScale.value)
|
|
118
|
+
}],
|
|
119
|
+
justifyContent: isOpen ? 'space-between' : 'flex-start',
|
|
120
|
+
overflow: 'hidden'
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Hook to create animated styles for the popup text
|
|
127
|
+
*/
|
|
128
|
+
export const usePopupAnimatedStyles = (offset, isPressed) => {
|
|
129
|
+
return useAnimatedStyle(() => {
|
|
130
|
+
const maxX = SCREEN_WIDTH;
|
|
131
|
+
const clampedX = clamp(offset.value.x, -maxX, 0);
|
|
132
|
+
return {
|
|
133
|
+
transform: [{
|
|
134
|
+
translateX: clampedX
|
|
135
|
+
}, {
|
|
136
|
+
translateY: offset.value.y
|
|
137
|
+
}, {
|
|
138
|
+
scale: withSpring(isPressed.value ? 1 : 1)
|
|
139
|
+
}]
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// ==================== GESTURE HANDLER ====================
|
|
145
|
+
/**
|
|
146
|
+
* Create pan gesture for drag functionality
|
|
147
|
+
*/
|
|
148
|
+
export const createPanGesture = (isPressed, offset, start, isOpen, setIsAutoOpen) => {
|
|
149
|
+
return Gesture.Pan().onBegin(() => {
|
|
150
|
+
isPressed.value = true;
|
|
151
|
+
if (setIsAutoOpen) {
|
|
152
|
+
runOnJS(setIsAutoOpen)(false);
|
|
153
|
+
}
|
|
154
|
+
}).onUpdate(e => {
|
|
155
|
+
const maxX = calculateMaxX(isOpen);
|
|
156
|
+
const maxY = calculateMaxY();
|
|
157
|
+
const newX = clamp(e.translationX + start.value.x, -maxX, 0);
|
|
158
|
+
const newY = clamp(e.translationY + start.value.y, -maxY, 0);
|
|
159
|
+
offset.value = {
|
|
160
|
+
x: newX,
|
|
161
|
+
y: newY
|
|
162
|
+
};
|
|
163
|
+
}).onEnd(() => {
|
|
164
|
+
start.value = {
|
|
165
|
+
x: offset.value.x,
|
|
166
|
+
y: offset.value.y
|
|
167
|
+
};
|
|
168
|
+
}).onFinalize(() => {
|
|
169
|
+
isPressed.value = false;
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=EmbedButton.animations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","Gesture","getReanimatedAPI","showReanimatedSetupError","BUTTON_DIMENSIONS","calculateMaxX","calculateMaxY","clamp","SCREEN_WIDTH","useSharedValue","useAnimatedStyle","withTiming","withSpring","withRepeat","withSequence","runOnJS","Easing","Animated","isAvailable","isReanimatedAvailable","useAnimationValues","isPressed","offset","x","y","start","menuAnimation","buttonWidth","WIDTH","buttonScale","useButtonAnimations","isOpen","value","duration","EXPANDED_WIDTH","useBreathingAnimation","isAutoOpen","easing","inOut","ease","useButtonAnimatedStyles","maxX","clampedX","width","height","HEIGHT","transform","translateX","translateY","scale","justifyContent","overflow","usePopupAnimatedStyles","createPanGesture","setIsAutoOpen","Pan","onBegin","onUpdate","e","maxY","newX","translationX","newY","translationY","onEnd","onFinalize"],"sourceRoot":"../../../src","sources":["hooks/EmbedButton.animations.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,gBAAgB,EAChBC,wBAAwB,QACnB,+BAA4B;AACnC,SACEC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,KAAK,EACLC,YAAY,QACP,0BAAuB;;AAE9B;AACA,MAAM;EACJC,cAAc;EACdC,gBAAgB;EAChBC,UAAU;EACVC,UAAU;EACVC,UAAU;EACVC,YAAY;EACZC,OAAO;EACPC,MAAM;EACNC,QAAQ;EACRC,WAAW,EAAEC;AACf,CAAC,GAAGjB,gBAAgB,CAAC,CAAC;;AAEtB;AACA,IAAI,CAACiB,qBAAqB,EAAE;EAC1BhB,wBAAwB,CAAC,CAAC;AAC5B;;AAEA;AACA,SAASc,QAAQ;;AAEjB;AACA;AACA;AACA;AACA,OAAO,MAAMG,kBAAkB,GAAGA,CAAA,KAAM;EACtC,MAAMC,SAAS,GAAGZ,cAAc,CAAC,KAAK,CAAC;EACvC,MAAMa,MAAM,GAAGb,cAAc,CAAC;IAAEc,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE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