yelda-webchat 1.1.22 → 1.1.23

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/AGENTS.md ADDED
@@ -0,0 +1,84 @@
1
+ ---
2
+ name: chat_plugin_agent
3
+ description: Maintainer for the Yelda website chat injector plugin (webpack + browser API + Mocha).
4
+ ---
5
+
6
+ ## Overview
7
+
8
+ - Browser plugin library that injects Yelda webchat into a host website.
9
+ - Main public API is the `yeldaChat` browser object exported from `src/js/yeldaWebchatInjector.js`.
10
+ - Bundled with webpack and shipped as JS/CSS assets in `dist/`.
11
+ - Tests use Mocha, Chai, jsdom, and xhr-mock.
12
+ - Upload/publish flow is handled by `uploadBuildToS3.js`.
13
+
14
+ ## Setup
15
+
16
+ - Node: use Node.js >=10.12.0 (Mocha 8.x requires >=10.12.0).
17
+ - Install deps: `npm install`
18
+ - Build: `npm run build`
19
+ - Test: `npm test`
20
+
21
+ ## Key Scripts
22
+
23
+ - `npm run build` builds the browser bundle into `dist/`.
24
+ - `npm run test` runs the Mocha suite against the built artifact.
25
+ - `npm run lint:check` runs ESLint on `src/`.
26
+ - `npm run lint:fix` auto-fixes ESLint issues in `src/`.
27
+ - `npm run uploadBuildToS3` builds, tests, uploads assets to S3, updates the package version, and pushes the version commit.
28
+
29
+ ## Env Vars
30
+
31
+ - `AWS_REGION`: S3 region used by `uploadBuildToS3.js`.
32
+ - `AWS_BUCKET`: target bucket for uploaded build assets.
33
+ - `AWS_ACCESS_KEY_ID`: AWS credential required for upload.
34
+ - `AWS_SECRET_ACCESS_KEY`: AWS credential required for upload.
35
+ - `.env` is loaded by `uploadBuildToS3.js` through `dotenv`.
36
+
37
+ ## Code Layout
38
+
39
+ - `src/js/yeldaWebchatInjector.js`: primary implementation of the injected chat widget and public API.
40
+ - `src/config/index.js`: constants, host rules, and iframe frame event names.
41
+ - `src/css/yeldaWebchatInjector.css`: widget styling.
42
+ - `test/test.js`: Mocha + jsdom integration-style tests that import the built bundle from `dist/`.
43
+ - `webpack.config.js`: production build config for JS, CSS, and compressed outputs.
44
+ - `uploadBuildToS3.js`: packaging, S3 upload, git push, and npm publish flow.
45
+ - `README.md`: public usage and maintenance notes.
46
+
47
+ ## Behavior Gotchas
48
+
49
+ - `test/test.js` requires a fresh `npm run build` because it imports `../dist/js/yeldaWebchatInjector.min`.
50
+ - `yeldaChat` is exposed both as the default export and on `window.yeldaChat`.
51
+ - `FRAME_EVENT_TYPES.SENT.UPDATE_SLOT` is part of the public iframe protocol and must stay aligned with `updateSlot()` behavior.
52
+ - `parentContainerId`, `bubbleContainerChildId`, and `canBeClosed` affect DOM placement, visibility, and closing behavior.
53
+ - External assistant settings are loaded from `https://webchat.yelda.ai/webchat`, with fallback logic to Yelda domains in `src/js/yeldaWebchatInjector.js`.
54
+ - `setAssistantUrl`, `getAppEnv`, and `formatData` drive environment resolution, URL normalization, and default init behavior.
55
+ - `unLoadChat()` and `resetChat()` are part of the lifecycle used by `init()` and `setupChat()`.
56
+
57
+ ## Coding Style & Conventions
58
+
59
+ - Follow the existing code style in the repo: 2-space indentation, single quotes, no semicolons, and no trailing commas.
60
+ - Keep ESLint rules intact, especially `no-console` restrictions and `require-await`.
61
+ - Use the webpack alias `@` for `src/` imports when it keeps paths clearer.
62
+ - Prefer camelCase for variables and functions, PascalCase for classes/constructors, and keep filenames consistent with existing modules.
63
+ - Keep function names verb-driven when adding new helpers.
64
+ - Use small helpers instead of long inline logic when changing the injector.
65
+ - Avoid deep nesting; prefer early returns and straightforward control flow.
66
+ - Do not declare new functions inside other functions unless there is a strong local reason.
67
+ - Add or update JSDoc for new helper functions, and keep existing JSDoc accurate when behavior or parameters change.
68
+ - Avoid magic numbers when a value belongs in `src/config/index.js`.
69
+ - Prefer reusing existing helpers and shared logic instead of introducing new ones.
70
+ - Do not add new dependencies or delete files without asking first.
71
+ - Document any new env vars or endpoint changes in `README.md`.
72
+
73
+ ## Testing & Quality
74
+
75
+ - Run `npm test` after changes that affect the bundle or runtime behavior.
76
+ - Run `npm run lint:check` after code changes.
77
+ - Re-run the relevant test/lint command after editing code or tests, and say explicitly if you could not run them.
78
+ - When updating protocol constants or iframe message handling, add or update tests in `test/test.js`.
79
+
80
+ ## Working Agreements
81
+
82
+ - Preserve the current build and publish flow unless the user asks to change it.
83
+ - Keep changes focused on the plugin runtime and its documented maintenance workflow.
84
+ - Leave unrelated local edits alone unless they directly block the task.
package/README.md CHANGED
@@ -23,7 +23,7 @@ Each time a new package version is published, we also update static minified ver
23
23
  ## Usage - From Node Packages Manager
24
24
 
25
25
  **System requirements**
26
- Node.JS 8+
26
+ Node.JS 10.12+
27
27
 
28
28
  **Install & setup**
29
29
 
@@ -105,7 +105,35 @@ yeldaChat.init({
105
105
  });
106
106
  ```
107
107
 
108
- To avoid issue with window.onload which might not be called when using JS Frameworks, you can also use `yeldaChat.setupChat(data)`, and even reset it with `yeldaChat.reset(data)`
108
+ To avoid issues with window.onload which might not be called when using JS Frameworks, you can also use `yeldaChat.setupChat(data)`, and even reset it with `yeldaChat.resetChat(data)`
109
+
110
+ ## Public API for external developers
111
+
112
+ The `yeldaChat` object exposes the following methods:
113
+
114
+ - `init(data)`: initialize the chat and wait for the page load if needed
115
+ - `resetChat(data)`: destroy the current chat instance and optionally reinitialize it
116
+ - `setupChat(data)`: initialize the chat immediately without waiting for `window.onload`
117
+ - `openChat()`: open the chat window
118
+ - `closeChat()`: close the chat window
119
+ - `sendMessageToChat(message)`: open the chat and send a user message to the iframe
120
+ - `updateSlot(slotObject)`: send a slot update to the iframe (posts the slot object, then an `updateSlot` event with that object as `data`)
121
+
122
+ Example:
123
+
124
+ ```javascript
125
+ yeldaChat.init({
126
+ assistantSlug: 'fm_logistic',
127
+ assistantId: '5b7edb2c1060312cfeaa7981',
128
+ assistantUrl: 'https://staging.yelda.ai',
129
+ chatPath: '/chat',
130
+ locale: 'fr_FR'
131
+ })
132
+
133
+ yeldaChat.openChat()
134
+ yeldaChat.sendMessageToChat('Hello')
135
+ yeldaChat.updateSlot({ customerId: '1234' })
136
+ ```
109
137
 
110
138
  ## Issues and Feature Requests
111
139