@bridge-ai-dev/ecom-chat 1.0.8 → 1.0.9
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 +63 -163
- package/dist/cjs/ChatComponent.d.ts.map +1 -1
- package/dist/cjs/ChatComponent.js +40 -2
- package/dist/cjs/ChatComponent.js.map +1 -1
- package/dist/cjs/types.d.ts +13 -1
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/ChatComponent.js +40 -2
- package/dist/esm/ChatComponent.js.map +1 -1
- package/package.json +2 -2
- package/templates/route.ts.template +12 -1
package/README.md
CHANGED
|
@@ -1,193 +1,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Ecom Chat - UI
|
|
2
2
|
|
|
3
|
-
Bridge E-commerce Chat widget integration for Next.js with Litium authentication.
|
|
4
3
|
|
|
5
|
-
## Why This Package?
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## Getting started
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
2. **Providing a React component** that fetches these cookies via the API and passes them to the chat widget
|
|
9
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
13
10
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
### Step 1: Run the Setup Command
|
|
11
|
+
## Add your files
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
14
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
19
15
|
|
|
20
|
-
```
|
|
21
|
-
|
|
16
|
+
```
|
|
17
|
+
cd existing_repo
|
|
18
|
+
git remote add origin https://git.bridge-delivery.com/bridge-ai/ecom-chat-ui.git
|
|
19
|
+
git branch -M main
|
|
20
|
+
git push -uf origin main
|
|
22
21
|
```
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
## Integrate with your tools
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
- [ ] [Set up project integrations](https://git.bridge-delivery.com/bridge-ai/ecom-chat-ui/-/settings/integrations)
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
npm install @bridge-ai-dev/ecom-chat
|
|
30
|
-
```
|
|
27
|
+
## Collaborate with your team
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
30
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
+
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Add the `ChatComponent` to your layout:
|
|
37
|
-
|
|
38
|
-
```tsx
|
|
39
|
-
// app/layout.tsx
|
|
40
|
-
import { ChatComponent } from '@bridge-ai-dev/ecom-chat';
|
|
41
|
-
|
|
42
|
-
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
43
|
-
return (
|
|
44
|
-
<html>
|
|
45
|
-
<body>
|
|
46
|
-
{children}
|
|
47
|
-
<ChatComponent
|
|
48
|
-
tenantId="your-tenant-uuid"
|
|
49
|
-
widgetScriptUrl="http://localhost:5173/chat-widget.js"
|
|
50
|
-
/>
|
|
51
|
-
</body>
|
|
52
|
-
</html>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
```
|
|
35
|
+
## Test and Deploy
|
|
56
36
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
<ChatComponent
|
|
61
|
-
tenantId="your-tenant-uuid"
|
|
62
|
-
widgetScriptUrl="http://localhost:5173/chat-widget.js"
|
|
63
|
-
accessToken="optional-access-token"
|
|
64
|
-
position="bottom-right"
|
|
65
|
-
backgroundColor="#6366f1"
|
|
66
|
-
foregroundColor="#ffffff"
|
|
67
|
-
size="medium"
|
|
68
|
-
borderWidth={2}
|
|
69
|
-
borderColor="#4f46e5"
|
|
70
|
-
autoPopup={false}
|
|
71
|
-
onAuthSuccess={(authData) => {
|
|
72
|
-
console.log('Auth successful, cart context:', authData.cart_context);
|
|
73
|
-
}}
|
|
74
|
-
onAuthError={(error) => {
|
|
75
|
-
console.error('Auth failed:', error.message);
|
|
76
|
-
}}
|
|
77
|
-
/>
|
|
78
|
-
```
|
|
37
|
+
Use the built-in continuous integration in GitLab.
|
|
79
38
|
|
|
80
|
-
|
|
39
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
|
40
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
41
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
42
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
81
44
|
|
|
82
|
-
|
|
83
|
-
<ChatComponent
|
|
84
|
-
tenantId="your-tenant-uuid"
|
|
85
|
-
bridgeAuthEndpoint="/api/custom-bridge-auth" // Custom API route path
|
|
86
|
-
containerId="my-chat-container" // Custom container ID
|
|
87
|
-
/>
|
|
88
|
-
```
|
|
45
|
+
***
|
|
89
46
|
|
|
90
|
-
|
|
91
|
-
If you already have access to the identity/cart tokens (e.g. in a Server Component), you can pass them directly:
|
|
47
|
+
# Editing this README
|
|
92
48
|
|
|
93
|
-
|
|
94
|
-
<ChatComponent
|
|
95
|
-
tenantId="your-tenant-uuid"
|
|
96
|
-
identity="optional-identity-token"
|
|
97
|
-
cartContext="optional-cart-jwt"
|
|
98
|
-
// ... other props
|
|
99
|
-
/>
|
|
100
|
-
```
|
|
49
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
101
50
|
|
|
102
|
-
##
|
|
103
|
-
|
|
104
|
-
### ChatComponent Props
|
|
105
|
-
|
|
106
|
-
| Prop | Type | Required | Default | Description |
|
|
107
|
-
|------|------|----------|---------|-------------|
|
|
108
|
-
| `tenantId` | `string` | ✅ | - | Your Bridge Chat tenant identifier |
|
|
109
|
-
| `identity` | `string` | ❌ | - | Identity token (skips API call if provided) |
|
|
110
|
-
| `cartContext` | `string` | ❌ | - | Cart context token (skips API call if provided) |
|
|
111
|
-
| `widgetScriptUrl` | `string` | ❌ | - | URL to the chat widget script (loads dynamically) |
|
|
112
|
-
| `accessToken` | `string` | ❌ | - | Optional access token for authenticated requests |
|
|
113
|
-
| `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | ❌ | `'bottom-right'` | Widget position on screen |
|
|
114
|
-
| `backgroundColor` | `string` | ❌ | `'#6366f1'` | Widget background color |
|
|
115
|
-
| `foregroundColor` | `string` | ❌ | `'#ffffff'` | Widget foreground/text color |
|
|
116
|
-
| `size` | `'small' \| 'medium' \| 'large'` | ❌ | `'medium'` | Widget size |
|
|
117
|
-
| `borderWidth` | `number` | ❌ | `2` | Widget border width in pixels |
|
|
118
|
-
| `borderColor` | `string` | ❌ | `'#4f46e5'` | Widget border color |
|
|
119
|
-
| `autoPopup` | `boolean` | ❌ | `false` | Auto popup the chat widget on load |
|
|
120
|
-
| `onAuthSuccess` | `(authData: BridgeAuthResponse) => void` | ❌ | - | Callback when auth bridge succeeds |
|
|
121
|
-
| `onAuthError` | `(error: Error) => void` | ❌ | - | Callback when auth bridge fails |
|
|
122
|
-
| `bridgeAuthEndpoint` | `string` | ❌ | `/api/bridge-auth` | Custom API endpoint path |
|
|
123
|
-
| `containerId` | `string` | ❌ | `bgc-chat-container` | Container element ID |
|
|
124
|
-
|
|
125
|
-
### BridgeAuthResponse
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
interface BridgeAuthResponse {
|
|
129
|
-
cart_context: string | null;
|
|
130
|
-
identity: string | null;
|
|
131
|
-
raw?: string | null;
|
|
132
|
-
}
|
|
133
|
-
```
|
|
51
|
+
## Suggestions for a good README
|
|
134
52
|
|
|
135
|
-
|
|
53
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
136
54
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
│ ChatComponent │ ──▶ │ /api/bridge-auth │ ──▶ │ Chat Widget │
|
|
140
|
-
│ (Client) │ │ (Server) │ │ (BridgeChat) │
|
|
141
|
-
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
|
142
|
-
│ │ │
|
|
143
|
-
│ 1. Fetch cookies │ │
|
|
144
|
-
│ ──────────────────────▶│ │
|
|
145
|
-
│ │ Server can read │
|
|
146
|
-
│ │ HttpOnly cookies │
|
|
147
|
-
│ │ │
|
|
148
|
-
│ 2. Return JSON │ │
|
|
149
|
-
│ ◀──────────────────────│ │
|
|
150
|
-
│ │ │
|
|
151
|
-
│ 3. Initialize with cookies + config │
|
|
152
|
-
│ ────────────────────────────────────────────────▶│
|
|
153
|
-
│ │ │
|
|
154
|
-
```
|
|
55
|
+
## Name
|
|
56
|
+
Choose a self-explaining name for your project.
|
|
155
57
|
|
|
156
|
-
##
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
autoPopup: false
|
|
177
|
-
});
|
|
178
|
-
```
|
|
58
|
+
## Description
|
|
59
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
60
|
+
|
|
61
|
+
## Badges
|
|
62
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
63
|
+
|
|
64
|
+
## Visuals
|
|
65
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
72
|
+
|
|
73
|
+
## Support
|
|
74
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
75
|
+
|
|
76
|
+
## Roadmap
|
|
77
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
179
78
|
|
|
180
|
-
##
|
|
79
|
+
## Contributing
|
|
80
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
181
81
|
|
|
182
|
-
|
|
183
|
-
- Cookies are passed to the chat widget via JavaScript, not exposed to third parties
|
|
184
|
-
- The component uses `credentials: 'include'` to ensure cookies are sent with the request
|
|
82
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
185
83
|
|
|
186
|
-
|
|
84
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
187
85
|
|
|
188
|
-
|
|
189
|
-
|
|
86
|
+
## Authors and acknowledgment
|
|
87
|
+
Show your appreciation to those who have contributed to the project.
|
|
190
88
|
|
|
191
89
|
## License
|
|
90
|
+
For open source projects, say how it is licensed.
|
|
192
91
|
|
|
193
|
-
|
|
92
|
+
## Project status
|
|
93
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatComponent.d.ts","sourceRoot":"","sources":["../../src/ChatComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAsB,MAAM,SAAS,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"ChatComponent.d.ts","sourceRoot":"","sources":["../../src/ChatComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAsB,MAAM,SAAS,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAmOtD,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -36,7 +36,7 @@ const react_1 = require("react");
|
|
|
36
36
|
*/
|
|
37
37
|
const ChatComponent = ({ tenantId, onAuthSuccess, onAuthError, bridgeAuthEndpoint = '/api/bridge-auth', containerId = 'bgc-chat-container',
|
|
38
38
|
// Widget configuration options
|
|
39
|
-
position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext }) => {
|
|
39
|
+
position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext, getCartFunction }) => {
|
|
40
40
|
const [isInitialized, setIsInitialized] = (0, react_1.useState)(false);
|
|
41
41
|
const [error, setError] = (0, react_1.useState)(null);
|
|
42
42
|
const [scriptLoaded, setScriptLoaded] = (0, react_1.useState)(false);
|
|
@@ -97,6 +97,43 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
|
|
|
97
97
|
}
|
|
98
98
|
authData = await authRes.json();
|
|
99
99
|
console.log('[ecom-package] Bridge auth response:', authData);
|
|
100
|
+
// 2. If cart-context cookie is missing, trigger client-side cart creation and retry
|
|
101
|
+
if (authData.cart_context_missing && getCartFunction) {
|
|
102
|
+
console.log('[ecom-package] cart-context cookie missing. Triggering client-side cart creation...');
|
|
103
|
+
try {
|
|
104
|
+
await getCartFunction();
|
|
105
|
+
console.log('[ecom-package] getCart completed. Re-fetching bridge auth to pick up new cookie...');
|
|
106
|
+
// Re-fetch bridge-auth to read the newly created cart-context cookie
|
|
107
|
+
const retryRes = await fetch(bridgeAuthEndpoint, {
|
|
108
|
+
method: 'GET',
|
|
109
|
+
credentials: 'include',
|
|
110
|
+
});
|
|
111
|
+
if (!retryRes.ok) {
|
|
112
|
+
console.warn('[ecom-package] Bridge auth retry failed:', retryRes.status, retryRes.statusText);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const retryData = await retryRes.json();
|
|
116
|
+
console.log('[ecom-package] Bridge auth retry response:', retryData);
|
|
117
|
+
if (retryData.cart_context) {
|
|
118
|
+
// Successfully obtained cart-context after retry
|
|
119
|
+
authData = retryData;
|
|
120
|
+
console.log('[ecom-package] cart-context obtained after retry:', authData.cart_context);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
console.warn('[ecom-package] cart-context still missing after retry. Proceeding without it.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (cartError) {
|
|
128
|
+
// Graceful degradation: log the error but continue initialization
|
|
129
|
+
console.warn('[ecom-package] Failed to create cart-context via getCartFunction:', cartError);
|
|
130
|
+
console.warn('[ecom-package] Proceeding with initialization without cart-context.');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (authData.cart_context_missing && !getCartFunction) {
|
|
134
|
+
console.warn('[ecom-package] cart-context cookie is missing but no getCartFunction prop provided. Cannot trigger cart creation.');
|
|
135
|
+
console.warn('[ecom-package] Tip: Pass getCartFunction prop to enable automatic cart creation when cookie is missing.');
|
|
136
|
+
}
|
|
100
137
|
}
|
|
101
138
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
102
139
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
@@ -171,7 +208,8 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
|
|
|
171
208
|
borderColor,
|
|
172
209
|
autoPopup,
|
|
173
210
|
onAuthSuccess,
|
|
174
|
-
onAuthError
|
|
211
|
+
onAuthError,
|
|
212
|
+
getCartFunction
|
|
175
213
|
]);
|
|
176
214
|
(0, react_1.useEffect)(() => {
|
|
177
215
|
initChat();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatComponent.js","sourceRoot":"","sources":["../../src/ChatComponent.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCAAgE;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACI,MAAM,aAAa,GAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,WAAW,EACX,kBAAkB,GAAG,kBAAkB,EACvC,WAAW,GAAG,oBAAoB;AAClC,+BAA+B;AAC/B,QAAQ,GAAG,cAAc,EACzB,eAAe,GAAG,SAAS,EAC3B,eAAe,GAAG,SAAS,EAC3B,IAAI,GAAG,QAAQ,EACf,WAAW,GAAG,CAAC,EACf,WAAW,GAAG,SAAS,EACvB,SAAS,GAAG,KAAK,EACjB,eAAe,EACf,QAAQ,EACR,WAAW,
|
|
1
|
+
{"version":3,"file":"ChatComponent.js","sourceRoot":"","sources":["../../src/ChatComponent.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCAAgE;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACI,MAAM,aAAa,GAAiC,CAAC,EACxD,QAAQ,EACR,aAAa,EACb,WAAW,EACX,kBAAkB,GAAG,kBAAkB,EACvC,WAAW,GAAG,oBAAoB;AAClC,+BAA+B;AAC/B,QAAQ,GAAG,cAAc,EACzB,eAAe,GAAG,SAAS,EAC3B,eAAe,GAAG,SAAS,EAC3B,IAAI,GAAG,QAAQ,EACf,WAAW,GAAG,CAAC,EACf,WAAW,GAAG,SAAS,EACvB,SAAS,GAAG,KAAK,EACjB,eAAe,EACf,QAAQ,EACR,WAAW,EACX,eAAe,EAClB,EAAE,EAAE;IACD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC1D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAe,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,YAAY,EAAE,eA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AAC,CAAC;AAnOW,QAAA,aAAa,iBAmOxB;AAEF,kBAAe,qBAAa,CAAC"}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -43,15 +43,27 @@ export interface ChatComponentProps {
|
|
|
43
43
|
identity?: string;
|
|
44
44
|
/** Optional cart context token to skip internal API call */
|
|
45
45
|
cartContext?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional function to call getCart from the client side.
|
|
48
|
+
* When cart-context cookie is missing, this function will be called
|
|
49
|
+
* to trigger cart creation (which sets the cookie), then bridge-auth
|
|
50
|
+
* is re-fetched to pick up the newly created cookie.
|
|
51
|
+
*
|
|
52
|
+
* Example: import { get as getCart } from 'services/cartService.client';
|
|
53
|
+
* <ChatComponent getCartFunction={getCart} />
|
|
54
|
+
*/
|
|
55
|
+
getCartFunction?: () => Promise<any>;
|
|
46
56
|
}
|
|
47
57
|
/**
|
|
48
58
|
* Response from the bridge-auth API route
|
|
49
59
|
*/
|
|
50
60
|
export interface BridgeAuthResponse {
|
|
51
|
-
/** The cart context cookie value
|
|
61
|
+
/** The cart context cookie value */
|
|
52
62
|
cart_context?: string | null;
|
|
53
63
|
/** The ASP.NET Core Identity cookie value */
|
|
54
64
|
identity: string | null;
|
|
65
|
+
/** Whether the cart-context cookie was missing from the request */
|
|
66
|
+
cart_context_missing?: boolean;
|
|
55
67
|
/** Raw cookie header string (optional, for debugging) */
|
|
56
68
|
raw?: string | null;
|
|
57
69
|
}
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;AAEvF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD;;GAEG;AACH,MAAM,W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|
34
34
|
export const ChatComponent = ({ tenantId, onAuthSuccess, onAuthError, bridgeAuthEndpoint = '/api/bridge-auth', containerId = 'bgc-chat-container',
|
|
35
35
|
// Widget configuration options
|
|
36
|
-
position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext }) => {
|
|
36
|
+
position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext, getCartFunction }) => {
|
|
37
37
|
const [isInitialized, setIsInitialized] = useState(false);
|
|
38
38
|
const [error, setError] = useState(null);
|
|
39
39
|
const [scriptLoaded, setScriptLoaded] = useState(false);
|
|
@@ -94,6 +94,43 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
|
|
|
94
94
|
}
|
|
95
95
|
authData = await authRes.json();
|
|
96
96
|
console.log('[ecom-package] Bridge auth response:', authData);
|
|
97
|
+
// 2. If cart-context cookie is missing, trigger client-side cart creation and retry
|
|
98
|
+
if (authData.cart_context_missing && getCartFunction) {
|
|
99
|
+
console.log('[ecom-package] cart-context cookie missing. Triggering client-side cart creation...');
|
|
100
|
+
try {
|
|
101
|
+
await getCartFunction();
|
|
102
|
+
console.log('[ecom-package] getCart completed. Re-fetching bridge auth to pick up new cookie...');
|
|
103
|
+
// Re-fetch bridge-auth to read the newly created cart-context cookie
|
|
104
|
+
const retryRes = await fetch(bridgeAuthEndpoint, {
|
|
105
|
+
method: 'GET',
|
|
106
|
+
credentials: 'include',
|
|
107
|
+
});
|
|
108
|
+
if (!retryRes.ok) {
|
|
109
|
+
console.warn('[ecom-package] Bridge auth retry failed:', retryRes.status, retryRes.statusText);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const retryData = await retryRes.json();
|
|
113
|
+
console.log('[ecom-package] Bridge auth retry response:', retryData);
|
|
114
|
+
if (retryData.cart_context) {
|
|
115
|
+
// Successfully obtained cart-context after retry
|
|
116
|
+
authData = retryData;
|
|
117
|
+
console.log('[ecom-package] cart-context obtained after retry:', authData.cart_context);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.warn('[ecom-package] cart-context still missing after retry. Proceeding without it.');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (cartError) {
|
|
125
|
+
// Graceful degradation: log the error but continue initialization
|
|
126
|
+
console.warn('[ecom-package] Failed to create cart-context via getCartFunction:', cartError);
|
|
127
|
+
console.warn('[ecom-package] Proceeding with initialization without cart-context.');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (authData.cart_context_missing && !getCartFunction) {
|
|
131
|
+
console.warn('[ecom-package] cart-context cookie is missing but no getCartFunction prop provided. Cannot trigger cart creation.');
|
|
132
|
+
console.warn('[ecom-package] Tip: Pass getCartFunction prop to enable automatic cart creation when cookie is missing.');
|
|
133
|
+
}
|
|
97
134
|
}
|
|
98
135
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
99
136
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
@@ -168,7 +205,8 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
|
|
|
168
205
|
borderColor,
|
|
169
206
|
autoPopup,
|
|
170
207
|
onAuthSuccess,
|
|
171
|
-
onAuthError
|
|
208
|
+
onAuthError,
|
|
209
|
+
getCartFunction
|
|
172
210
|
]);
|
|
173
211
|
useEffect(() => {
|
|
174
212
|
initChat();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatComponent.js","sourceRoot":"","sources":["../../src/ChatComponent.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,M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-ai-dev/ecom-chat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Bridge E-commerce Chat widget integration for Next.js with Litium authentication",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"type": "git",
|
|
47
47
|
"url": "https://github.com/bridge-ai/ecom-chat.git"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
@@ -8,6 +8,10 @@ import { NextRequest, NextResponse } from "next/server";
|
|
|
8
8
|
*
|
|
9
9
|
* The ChatComponent uses this route to get authentication context
|
|
10
10
|
* before initializing the chat widget.
|
|
11
|
+
*
|
|
12
|
+
* If the cart-context cookie is missing, the response includes a
|
|
13
|
+
* `cart_context_missing` flag so the client can trigger cart creation
|
|
14
|
+
* and retry.
|
|
11
15
|
*/
|
|
12
16
|
export const GET = async (request: NextRequest) => {
|
|
13
17
|
const cookies = request.cookies;
|
|
@@ -19,15 +23,22 @@ export const GET = async (request: NextRequest) => {
|
|
|
19
23
|
|
|
20
24
|
// Retrieve the secure cookies
|
|
21
25
|
const identity = cookies.get(".AspNetCore.Identity.Application")?.value;
|
|
22
|
-
const cartContext = cookies.get("
|
|
26
|
+
const cartContext = cookies.get("cart-context")?.value;
|
|
23
27
|
|
|
24
28
|
// Debug: Log retrieved values
|
|
25
29
|
console.log('[bridge-auth] Identity cookie value:', identity ?? 'NOT FOUND');
|
|
26
30
|
console.log('[bridge-auth] Cart context cookie value:', cartContext ?? 'NOT FOUND');
|
|
27
31
|
|
|
32
|
+
const cartContextMissing = !cartContext;
|
|
33
|
+
|
|
34
|
+
if (cartContextMissing) {
|
|
35
|
+
console.log('[bridge-auth] cart-context cookie is missing. Client should trigger cart creation and retry.');
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
const response = {
|
|
29
39
|
identity: identity || null,
|
|
30
40
|
cart_context: cartContext || null,
|
|
41
|
+
cart_context_missing: cartContextMissing,
|
|
31
42
|
// Optional: Include the raw cookie string if your backend needs it
|
|
32
43
|
raw: request.headers.get("cookie")
|
|
33
44
|
};
|