@bridge-ai-dev/ecom-chat 1.0.8 → 1.1.0
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 +71 -135
- package/dist/cjs/ChatComponent.d.ts.map +1 -1
- package/dist/cjs/ChatComponent.js +42 -2
- package/dist/cjs/ChatComponent.js.map +1 -1
- package/dist/cjs/LitiumChatComponent.d.ts +40 -0
- package/dist/cjs/LitiumChatComponent.d.ts.map +1 -0
- package/dist/cjs/LitiumChatComponent.js +47 -0
- package/dist/cjs/LitiumChatComponent.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.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 +42 -2
- package/dist/esm/ChatComponent.js.map +1 -1
- package/dist/esm/LitiumChatComponent.js +43 -0
- package/dist/esm/LitiumChatComponent.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/route.ts.template +12 -1
package/README.md
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Ecom Chat - UI
|
|
2
2
|
|
|
3
3
|
Bridge E-commerce Chat widget integration for Next.js with Litium authentication.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package provides React components to easily integrate the Bridge Chat widget into your Next.js ecommerce storefront. It securely handles the authentication handshake between your storefront's HttpOnly cookies and the Bridge Chat application.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Prerequisites
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
1. **Creating a secure API route** that runs on the server and can access HttpOnly cookies
|
|
12
|
-
2. **Providing a React component** that fetches these cookies via the API and passes them to the chat widget
|
|
9
|
+
- Next.js 13+ with App Router
|
|
10
|
+
- React 17 or higher
|
|
13
11
|
|
|
14
12
|
## Installation
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
In your Next.js project root, run:
|
|
14
|
+
Install the package via npm:
|
|
19
15
|
|
|
20
16
|
```bash
|
|
21
|
-
|
|
17
|
+
npm install @bridge-ai-dev/ecom-chat
|
|
22
18
|
```
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
## Setup
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
The chat components require a server-side API route to retrieve secure HttpOnly cookies (like `cart-context` and ASP.NET Core Identity cookies) that are inaccessible from client-side JavaScript.
|
|
23
|
+
|
|
24
|
+
To automatically generate this API route in your Next.js app, run:
|
|
27
25
|
|
|
28
26
|
```bash
|
|
29
|
-
|
|
27
|
+
npx create-ecom-chat
|
|
30
28
|
```
|
|
31
29
|
|
|
30
|
+
This will create an API route at `app/api/bridge-auth/route.ts`.
|
|
31
|
+
|
|
32
32
|
## Usage
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
You can include the chat component in your main layout or any client component.
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
### Standard Usage (`ChatComponent`)
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
|
-
|
|
39
|
+
'use client';
|
|
40
|
+
|
|
40
41
|
import { ChatComponent } from '@bridge-ai-dev/ecom-chat';
|
|
41
42
|
|
|
42
43
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
43
44
|
return (
|
|
44
|
-
<html>
|
|
45
|
+
<html lang="en">
|
|
45
46
|
<body>
|
|
46
47
|
{children}
|
|
47
48
|
<ChatComponent
|
|
48
49
|
tenantId="your-tenant-uuid"
|
|
49
|
-
widgetScriptUrl="
|
|
50
|
+
widgetScriptUrl="https://your-cdn.com/chat-widget.js"
|
|
50
51
|
/>
|
|
51
52
|
</body>
|
|
52
53
|
</html>
|
|
@@ -54,139 +55,74 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
54
55
|
}
|
|
55
56
|
```
|
|
56
57
|
|
|
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
|
-
```
|
|
58
|
+
### Litium Storefront Usage (`LitiumChatComponent`)
|
|
79
59
|
|
|
80
|
-
|
|
60
|
+
For Litium projects, there is a specialized wrapper component. You can pass your project's cart creation function to automatically handle cases where the user doesn't have an active cart session yet.
|
|
81
61
|
|
|
82
62
|
```tsx
|
|
83
|
-
|
|
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
|
-
```
|
|
63
|
+
'use client';
|
|
89
64
|
|
|
90
|
-
|
|
91
|
-
|
|
65
|
+
import { LitiumChatComponent } from '@bridge-ai-dev/ecom-chat';
|
|
66
|
+
import { createCart } from '@/services/cartService.client'; // Adjust path to your project's mutation
|
|
92
67
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/>
|
|
68
|
+
export default function ChatWrapper() {
|
|
69
|
+
return (
|
|
70
|
+
<LitiumChatComponent
|
|
71
|
+
tenantId="your-tenant-uuid"
|
|
72
|
+
widgetScriptUrl="https://your-cdn.com/chat-widget.js"
|
|
73
|
+
getCartFunction={createCart}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
100
77
|
```
|
|
101
78
|
|
|
102
79
|
## API Reference
|
|
103
80
|
|
|
104
|
-
###
|
|
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
|
|
81
|
+
### Component Properties
|
|
126
82
|
|
|
127
|
-
|
|
128
|
-
interface BridgeAuthResponse {
|
|
129
|
-
cart_context: string | null;
|
|
130
|
-
identity: string | null;
|
|
131
|
-
raw?: string | null;
|
|
132
|
-
}
|
|
133
|
-
```
|
|
83
|
+
Both `ChatComponent` and `LitiumChatComponent` accept the following properties:
|
|
134
84
|
|
|
135
|
-
|
|
85
|
+
#### Required
|
|
86
|
+
- **`tenantId`** (`string`): The unique tenant identifier for your Bridge Chat instance.
|
|
136
87
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
```
|
|
88
|
+
#### Optional Configuration
|
|
89
|
+
- **`widgetScriptUrl`** (`string`): URL to dynamically load the chat widget script if not already included in your HTML.
|
|
90
|
+
- **`getCartFunction`** (`() => Promise<any>`): Function to call the API from the client side when the `cart-context` cookie is missing. The component will trigger this function to create the cart and then read the locally updated cookies.
|
|
91
|
+
- **`bridgeAuthEndpoint`** (`string`): Custom API endpoint for the bridge auth route. Default is `'/api/bridge-auth'`.
|
|
92
|
+
- **`containerId`** (`string`): Custom ID for the chat container div. Default is `'bgc-chat-container'`.
|
|
155
93
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
accessToken: 'optional-access-token',
|
|
165
|
-
cookies: {
|
|
166
|
-
cart_context: 'value-from-cookie'
|
|
167
|
-
},
|
|
168
|
-
identityCookie: 'value-from-identity-cookie',
|
|
169
|
-
container: 'bgc-chat-container',
|
|
170
|
-
position: 'bottom-right',
|
|
171
|
-
backgroundColor: '#6366f1',
|
|
172
|
-
foregroundColor: '#ffffff',
|
|
173
|
-
size: 'medium',
|
|
174
|
-
borderWidth: 2,
|
|
175
|
-
borderColor: '#4f46e5',
|
|
176
|
-
autoPopup: false
|
|
177
|
-
});
|
|
178
|
-
```
|
|
94
|
+
#### Widget Customization
|
|
95
|
+
- **`position`** (`WidgetPosition`): Screen position. Default `'bottom-right'`.
|
|
96
|
+
- **`backgroundColor`** (`string`): Widget background color. Default `'#6366f1'`.
|
|
97
|
+
- **`foregroundColor`** (`string`): Widget text color. Default `'#ffffff'`.
|
|
98
|
+
- **`size`** (`WidgetSize`): Widget size (`'small' | 'medium' | 'large'`). Default `'medium'`.
|
|
99
|
+
- **`borderWidth`** (`number`): Widget border width in pixels. Default `2`.
|
|
100
|
+
- **`borderColor`** (`string`): Widget border color. Default `'#4f46e5'`.
|
|
101
|
+
- **`autoPopup`** (`boolean`): Automatically open the chat widget on load. Default `false`.
|
|
179
102
|
|
|
180
|
-
|
|
103
|
+
#### Callbacks
|
|
104
|
+
- **`onAuthSuccess`** (`(authData: BridgeAuthResponse) => void`): Callback when the authentication bridge completes successfully.
|
|
105
|
+
- **`onAuthError`** (`(error: Error) => void`): Callback when the authentication bridge fails.
|
|
181
106
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
-
|
|
107
|
+
#### Auth Bypass
|
|
108
|
+
If provided, these properties will bypass the internal `bridge-auth` API call completely.
|
|
109
|
+
- **`cartContext`** (`string`): Hardcode a specific cart context token.
|
|
110
|
+
- **`identity`** (`string`): Hardcode a specific identity token.
|
|
185
111
|
|
|
186
|
-
##
|
|
112
|
+
## Types
|
|
187
113
|
|
|
188
|
-
|
|
189
|
-
|
|
114
|
+
You can import types directly from the package:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import type {
|
|
118
|
+
ChatComponentProps,
|
|
119
|
+
BridgeAuthResponse,
|
|
120
|
+
BridgeChatInitConfig,
|
|
121
|
+
BridgeChatGlobal,
|
|
122
|
+
WidgetPosition,
|
|
123
|
+
WidgetSize
|
|
124
|
+
} from '@bridge-ai-dev/ecom-chat';
|
|
125
|
+
```
|
|
190
126
|
|
|
191
127
|
## License
|
|
192
128
|
|
|
@@ -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,CAqOtD,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,45 @@ 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
|
+
console.log('[ecom-package] Cookies BEFORE getCart:', document.cookie);
|
|
104
|
+
try {
|
|
105
|
+
await getCartFunction();
|
|
106
|
+
console.log('[ecom-package] Cookies AFTER getCart:', document.cookie);
|
|
107
|
+
console.log('[ecom-package] getCart completed. Re-fetching bridge auth to pick up new cookie...');
|
|
108
|
+
// Re-fetch bridge-auth to read the newly created cart-context cookie
|
|
109
|
+
const retryRes = await fetch(bridgeAuthEndpoint, {
|
|
110
|
+
method: 'GET',
|
|
111
|
+
credentials: 'include',
|
|
112
|
+
});
|
|
113
|
+
if (!retryRes.ok) {
|
|
114
|
+
console.warn('[ecom-package] Bridge auth retry failed:', retryRes.status, retryRes.statusText);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const retryData = await retryRes.json();
|
|
118
|
+
console.log('[ecom-package] Bridge auth retry response:', retryData);
|
|
119
|
+
if (retryData.cart_context) {
|
|
120
|
+
// Successfully obtained cart-context after retry
|
|
121
|
+
authData = retryData;
|
|
122
|
+
console.log('[ecom-package] cart-context obtained after retry:', authData.cart_context);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.warn('[ecom-package] cart-context still missing after retry. Proceeding without it.');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (cartError) {
|
|
130
|
+
// Graceful degradation: log the error but continue initialization
|
|
131
|
+
console.warn('[ecom-package] Failed to create cart-context via getCartFunction:', cartError);
|
|
132
|
+
console.warn('[ecom-package] Proceeding with initialization without cart-context.');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (authData.cart_context_missing && !getCartFunction) {
|
|
136
|
+
console.warn('[ecom-package] cart-context cookie is missing but no getCartFunction prop provided. Cannot trigger cart creation.');
|
|
137
|
+
console.warn('[ecom-package] Tip: Pass getCartFunction prop to enable automatic cart creation when cookie is missing.');
|
|
138
|
+
}
|
|
100
139
|
}
|
|
101
140
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
102
141
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
@@ -171,7 +210,8 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
|
|
|
171
210
|
borderColor,
|
|
172
211
|
autoPopup,
|
|
173
212
|
onAuthSuccess,
|
|
174
|
-
onAuthError
|
|
213
|
+
onAuthError,
|
|
214
|
+
getCartFunction
|
|
175
215
|
]);
|
|
176
216
|
(0, react_1.useEffect)(() => {
|
|
177
217
|
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,QAA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ComponentProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* LitiumChatComponent - Ready-to-use Bridge Chat Widget for Litium Storefront
|
|
5
|
+
*
|
|
6
|
+
* A convenience wrapper around `ChatComponent` tailored for Litium projects.
|
|
7
|
+
* Accepts the same props as `ChatComponent`. Pass your project's `createCart`
|
|
8
|
+
* function as `getCartFunction` so the widget can automatically create a cart
|
|
9
|
+
* (and set the `cart-context` cookie) when one doesn't exist yet.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* // In your layout.tsx or any client component:
|
|
14
|
+
* 'use client';
|
|
15
|
+
* import { LitiumChatComponent } from '@bridge-ai-dev/ecom-chat';
|
|
16
|
+
* import { createCart } from 'services/cartService.client';
|
|
17
|
+
*
|
|
18
|
+
* export default function ChatWrapper() {
|
|
19
|
+
* return (
|
|
20
|
+
* <LitiumChatComponent
|
|
21
|
+
* tenantId="your-tenant-uuid"
|
|
22
|
+
* widgetScriptUrl="https://your-chat-widget-url/chat-widget.js"
|
|
23
|
+
* getCartFunction={createCart}
|
|
24
|
+
* />
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - `getCartFunction` should be the `createCart` mutation (not `getCart`) from
|
|
31
|
+
* your Litium `cartService.client.ts`. The `createCart` mutation triggers
|
|
32
|
+
* Litium to set the `cart-context` cookie in the browser, which is required
|
|
33
|
+
* for the chat widget to initialize correctly.
|
|
34
|
+
* - Because this component uses React hooks, it must be rendered inside a
|
|
35
|
+
* `'use client'` boundary. Wrap it in a client component if your layout is
|
|
36
|
+
* a server component.
|
|
37
|
+
*/
|
|
38
|
+
export declare const LitiumChatComponent: React.FC<ChatComponentProps>;
|
|
39
|
+
export default LitiumChatComponent;
|
|
40
|
+
//# sourceMappingURL=LitiumChatComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LitiumChatComponent.d.ts","sourceRoot":"","sources":["../../src/LitiumChatComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAE5D,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LitiumChatComponent = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const ChatComponent_1 = require("./ChatComponent");
|
|
7
|
+
/**
|
|
8
|
+
* LitiumChatComponent - Ready-to-use Bridge Chat Widget for Litium Storefront
|
|
9
|
+
*
|
|
10
|
+
* A convenience wrapper around `ChatComponent` tailored for Litium projects.
|
|
11
|
+
* Accepts the same props as `ChatComponent`. Pass your project's `createCart`
|
|
12
|
+
* function as `getCartFunction` so the widget can automatically create a cart
|
|
13
|
+
* (and set the `cart-context` cookie) when one doesn't exist yet.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* // In your layout.tsx or any client component:
|
|
18
|
+
* 'use client';
|
|
19
|
+
* import { LitiumChatComponent } from '@bridge-ai-dev/ecom-chat';
|
|
20
|
+
* import { createCart } from 'services/cartService.client';
|
|
21
|
+
*
|
|
22
|
+
* export default function ChatWrapper() {
|
|
23
|
+
* return (
|
|
24
|
+
* <LitiumChatComponent
|
|
25
|
+
* tenantId="your-tenant-uuid"
|
|
26
|
+
* widgetScriptUrl="https://your-chat-widget-url/chat-widget.js"
|
|
27
|
+
* getCartFunction={createCart}
|
|
28
|
+
* />
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* - `getCartFunction` should be the `createCart` mutation (not `getCart`) from
|
|
35
|
+
* your Litium `cartService.client.ts`. The `createCart` mutation triggers
|
|
36
|
+
* Litium to set the `cart-context` cookie in the browser, which is required
|
|
37
|
+
* for the chat widget to initialize correctly.
|
|
38
|
+
* - Because this component uses React hooks, it must be rendered inside a
|
|
39
|
+
* `'use client'` boundary. Wrap it in a client component if your layout is
|
|
40
|
+
* a server component.
|
|
41
|
+
*/
|
|
42
|
+
const LitiumChatComponent = (props) => {
|
|
43
|
+
return (0, jsx_runtime_1.jsx)(ChatComponent_1.ChatComponent, { ...props });
|
|
44
|
+
};
|
|
45
|
+
exports.LitiumChatComponent = LitiumChatComponent;
|
|
46
|
+
exports.default = exports.LitiumChatComponent;
|
|
47
|
+
//# sourceMappingURL=LitiumChatComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LitiumChatComponent.js","sourceRoot":"","sources":["../../src/LitiumChatComponent.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAGb,mDAAgD;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,mBAAmB,GAAiC,CAAC,KAAK,EAAE,EAAE;IACvE,OAAO,uBAAC,6BAAa,OAAK,KAAK,GAAI,CAAC;AACxC,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B;AAEF,kBAAe,2BAAmB,CAAC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@
|
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
8
|
export { ChatComponent, default } from './ChatComponent';
|
|
9
|
+
export { LitiumChatComponent } from './LitiumChatComponent';
|
|
9
10
|
export type { ChatComponentProps, BridgeAuthResponse, BridgeChatInitConfig, BridgeChatGlobal, WidgetPosition, WidgetSize } from './types';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGzD,YAAY,EACR,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACb,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,YAAY,EACR,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,UAAU,EACb,MAAM,SAAS,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,9 +10,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.default = exports.ChatComponent = void 0;
|
|
13
|
+
exports.LitiumChatComponent = exports.default = exports.ChatComponent = void 0;
|
|
14
14
|
// Export the main component
|
|
15
15
|
var ChatComponent_1 = require("./ChatComponent");
|
|
16
16
|
Object.defineProperty(exports, "ChatComponent", { enumerable: true, get: function () { return ChatComponent_1.ChatComponent; } });
|
|
17
17
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(ChatComponent_1).default; } });
|
|
18
|
+
// Export the Litium-specific convenience component
|
|
19
|
+
var LitiumChatComponent_1 = require("./LitiumChatComponent");
|
|
20
|
+
Object.defineProperty(exports, "LitiumChatComponent", { enumerable: true, get: function () { return LitiumChatComponent_1.LitiumChatComponent; } });
|
|
18
21
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,4BAA4B;AAC5B,iDAAyD;AAAhD,8GAAA,aAAa,OAAA;AAAE,yHAAA,OAAO,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,4BAA4B;AAC5B,iDAAyD;AAAhD,8GAAA,aAAa,OAAA;AAAE,yHAAA,OAAO,OAAA;AAE/B,mDAAmD;AACnD,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA"}
|
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,WAAW,kBAAkB;IAC/B,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IAEjB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAEvD,yDAAyD;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAErC,yFAAyF;IACzF,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,qFAAqF;IACrF,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,cAAc,CAAC;IAE1B,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,sCAAsC;IACtC,IAAI,CAAC,EAAE,UAAU,CAAC;IAElB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,4DAA4D;IAC5D,eAAe,CAAC,EAAE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IAAI,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAE7C,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC;IAElB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IAEnB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAEpB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,UAAU,CAAC,EAAE,gBAAgB,CAAC;KACjC;CACJ;AAED,OAAO,EAAG,CAAC"}
|
|
@@ -33,7 +33,7 @@ import { useEffect, useState, useCallback } from 'react';
|
|
|
33
33
|
*/
|
|
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,45 @@ 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
|
+
console.log('[ecom-package] Cookies BEFORE getCart:', document.cookie);
|
|
101
|
+
try {
|
|
102
|
+
await getCartFunction();
|
|
103
|
+
console.log('[ecom-package] Cookies AFTER getCart:', document.cookie);
|
|
104
|
+
console.log('[ecom-package] getCart completed. Re-fetching bridge auth to pick up new cookie...');
|
|
105
|
+
// Re-fetch bridge-auth to read the newly created cart-context cookie
|
|
106
|
+
const retryRes = await fetch(bridgeAuthEndpoint, {
|
|
107
|
+
method: 'GET',
|
|
108
|
+
credentials: 'include',
|
|
109
|
+
});
|
|
110
|
+
if (!retryRes.ok) {
|
|
111
|
+
console.warn('[ecom-package] Bridge auth retry failed:', retryRes.status, retryRes.statusText);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const retryData = await retryRes.json();
|
|
115
|
+
console.log('[ecom-package] Bridge auth retry response:', retryData);
|
|
116
|
+
if (retryData.cart_context) {
|
|
117
|
+
// Successfully obtained cart-context after retry
|
|
118
|
+
authData = retryData;
|
|
119
|
+
console.log('[ecom-package] cart-context obtained after retry:', authData.cart_context);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.warn('[ecom-package] cart-context still missing after retry. Proceeding without it.');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (cartError) {
|
|
127
|
+
// Graceful degradation: log the error but continue initialization
|
|
128
|
+
console.warn('[ecom-package] Failed to create cart-context via getCartFunction:', cartError);
|
|
129
|
+
console.warn('[ecom-package] Proceeding with initialization without cart-context.');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (authData.cart_context_missing && !getCartFunction) {
|
|
133
|
+
console.warn('[ecom-package] cart-context cookie is missing but no getCartFunction prop provided. Cannot trigger cart creation.');
|
|
134
|
+
console.warn('[ecom-package] Tip: Pass getCartFunction prop to enable automatic cart creation when cookie is missing.');
|
|
135
|
+
}
|
|
97
136
|
}
|
|
98
137
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
99
138
|
// 2. Wait for BridgeChat to be available (with timeout)
|
|
@@ -168,7 +207,8 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
|
|
|
168
207
|
borderColor,
|
|
169
208
|
autoPopup,
|
|
170
209
|
onAuthSuccess,
|
|
171
|
-
onAuthError
|
|
210
|
+
onAuthError,
|
|
211
|
+
getCartFunction
|
|
172
212
|
]);
|
|
173
213
|
useEffect(() => {
|
|
174
214
|
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,MAAM,CAAC,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,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,aAAa,GAAiC,CAAC,EACxD,QAAQ,EACR,aAAa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CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;YACzD,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChB,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACL,CAAC,EAAE;QACC,QAAQ;QACR,kBAAkB;QAClB,aAAa;QACb,YAAY;QACZ,WAAW;QACX,QAAQ;QACR,eAAe;QACf,eAAe;QACf,IAAI;QACJ,WAAW;QACX,WAAW;QACX,SAAS;QACT,aAAa;QACb,WAAW;QACX,eAAe;KAClB,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,QAAQ,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,yCAAyC;IACzC,8DAA8D;IAC9D,OAAO,CACH,cACI,EAAE,EAAE,WAAW,oBACC,QAAQ,sBACN,aAAa,gBACnB,KAAK,EAAE,OAAO,EAC1B,KAAK,EAAE;QACH,8CAA8C;QAC9C,uCAAuC;SAC1C,GACH,CACL,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { ChatComponent } from './ChatComponent';
|
|
4
|
+
/**
|
|
5
|
+
* LitiumChatComponent - Ready-to-use Bridge Chat Widget for Litium Storefront
|
|
6
|
+
*
|
|
7
|
+
* A convenience wrapper around `ChatComponent` tailored for Litium projects.
|
|
8
|
+
* Accepts the same props as `ChatComponent`. Pass your project's `createCart`
|
|
9
|
+
* function as `getCartFunction` so the widget can automatically create a cart
|
|
10
|
+
* (and set the `cart-context` cookie) when one doesn't exist yet.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // In your layout.tsx or any client component:
|
|
15
|
+
* 'use client';
|
|
16
|
+
* import { LitiumChatComponent } from '@bridge-ai-dev/ecom-chat';
|
|
17
|
+
* import { createCart } from 'services/cartService.client';
|
|
18
|
+
*
|
|
19
|
+
* export default function ChatWrapper() {
|
|
20
|
+
* return (
|
|
21
|
+
* <LitiumChatComponent
|
|
22
|
+
* tenantId="your-tenant-uuid"
|
|
23
|
+
* widgetScriptUrl="https://your-chat-widget-url/chat-widget.js"
|
|
24
|
+
* getCartFunction={createCart}
|
|
25
|
+
* />
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* - `getCartFunction` should be the `createCart` mutation (not `getCart`) from
|
|
32
|
+
* your Litium `cartService.client.ts`. The `createCart` mutation triggers
|
|
33
|
+
* Litium to set the `cart-context` cookie in the browser, which is required
|
|
34
|
+
* for the chat widget to initialize correctly.
|
|
35
|
+
* - Because this component uses React hooks, it must be rendered inside a
|
|
36
|
+
* `'use client'` boundary. Wrap it in a client component if your layout is
|
|
37
|
+
* a server component.
|
|
38
|
+
*/
|
|
39
|
+
export const LitiumChatComponent = (props) => {
|
|
40
|
+
return _jsx(ChatComponent, { ...props });
|
|
41
|
+
};
|
|
42
|
+
export default LitiumChatComponent;
|
|
43
|
+
//# sourceMappingURL=LitiumChatComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LitiumChatComponent.js","sourceRoot":"","sources":["../../src/LitiumChatComponent.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiC,CAAC,KAAK,EAAE,EAAE;IACvE,OAAO,KAAC,aAAa,OAAK,KAAK,GAAI,CAAC;AACxC,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4BAA4B;AAC5B,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4BAA4B;AAC5B,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzD,mDAAmD;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -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
|
};
|