@bridge-ai-dev/ecom-chat 1.0.9 → 1.0.11

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 CHANGED
@@ -1,93 +1,76 @@
1
- # Ecom Chat - UI
1
+ # Bridge E-commerce Chat widget integration for Next.js
2
2
 
3
+ A powerful chat widget integration specifically designed for Next.js and Litium storefronts. It handles complex authentication flows and automatic cart context initialization.
3
4
 
5
+ ## Features
4
6
 
5
- ## Getting started
7
+ - **Automatic Cart Scaling**: Server-side cart creation using Litium's `CreateCart` mutation.
8
+ - **Secure Auth Bridge**: Handles HttpOnly cookies (`.AspNetCore.Identity.Application` and `cart-context`) safely.
9
+ - **Next.js Optimized**: Built for the App Router and React Server Components.
10
+ - **Zero Configuration**: Scaffolding tool to get you started in seconds.
6
11
 
7
- To make it easy for you to get started with GitLab, here's a list of recommended next steps.
12
+ ## Quick Start
8
13
 
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)!
14
+ Run the following command in your Next.js project root:
10
15
 
11
- ## Add your files
12
-
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:
15
-
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
16
+ ```bash
17
+ npx @bridge-ai-dev/ecom-chat
21
18
  ```
22
19
 
23
- ## Integrate with your tools
24
-
25
- - [ ] [Set up project integrations](https://git.bridge-delivery.com/bridge-ai/ecom-chat-ui/-/settings/integrations)
26
-
27
- ## Collaborate with your team
28
-
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/)
34
-
35
- ## Test and Deploy
36
-
37
- Use the built-in continuous integration in GitLab.
38
-
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)
20
+ This will:
21
+ 1. Create `app/api/bridge-auth/route.ts` (The secure auth bridge)
22
+ 2. Create `components/ChatWrapper.tsx` (A pre-configured component wrapper)
44
23
 
45
- ***
24
+ ## Configuration
46
25
 
47
- # Editing this README
26
+ Add the following environment variables to your `.env.local`:
48
27
 
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.
28
+ ```env
29
+ # Required for the Widget
30
+ NEXT_PUBLIC_BRIDGE_TENANT_ID=your-tenant-uuid
31
+ NEXT_PUBLIC_BRIDGE_WIDGET_URL=https://...
50
32
 
51
- ## Suggestions for a good README
52
-
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.
54
-
55
- ## Name
56
- Choose a self-explaining name for your project.
57
-
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.
33
+ # Required for server-side cart initialization
34
+ RUNTIME_LITIUM_SERVER_URL=https://your-litium-backend.com
35
+ ```
69
36
 
70
37
  ## 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
38
 
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.
39
+ In your `app/layout.tsx`:
40
+
41
+ ```tsx
42
+ import ChatWrapper from '@/components/ChatWrapper';
43
+
44
+ export default function RootLayout({ children }) {
45
+ return (
46
+ <html>
47
+ <body>
48
+ {children}
49
+ <ChatWrapper />
50
+ </body>
51
+ </html>
52
+ );
53
+ }
54
+ ```
75
55
 
76
- ## Roadmap
77
- If you have ideas for releases in the future, it is a good idea to list them in the README.
56
+ ## How it works
78
57
 
79
- ## Contributing
80
- State if you are open to contributions and what your requirements are for accepting them.
58
+ The library uses a "Bridge Auth" pattern:
59
+ 1. The **ChatComponent** (client-side) calls the `/api/bridge-auth` route.
60
+ 2. The **Auth Route** (server-side) reads the secure Litium cookies.
61
+ 3. If the **cart-context** cookie is missing, the route automatically performs a `CreateCart` mutation to Litium's GraphQL API.
62
+ 4. The route returns the auth data to the widget and forwards any new `Set-Cookie` headers to the browser.
81
63
 
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.
64
+ ## Customization
83
65
 
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.
66
+ ### `ChatComponent` Props
85
67
 
86
- ## Authors and acknowledgment
87
- Show your appreciation to those who have contributed to the project.
68
+ | Prop | Type | Default | Description |
69
+ |------|------|---------|-------------|
70
+ | `tenantId` | `string` | **Required** | Your Bridge AI tenant ID. |
71
+ | `widgetScriptUrl` | `string` | **Required** | URL of the chat widget script. |
72
+ | `cartCreationMode` | `'server' \| 'client' \| 'none'` | `'server'` | How to handle missing carts. |
88
73
 
89
74
  ## License
90
- For open source projects, say how it is licensed.
91
75
 
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.
76
+ MIT
package/bin/cli.js CHANGED
@@ -21,14 +21,19 @@ const log = {
21
21
  step: (msg) => console.log(`${colors.bold}🚀 ${msg}${colors.reset}`)
22
22
  };
23
23
 
24
- // Read the API route content from the template file
25
- const templatePath = path.join(__dirname, '..', 'templates', 'route.ts.template');
26
- let apiRouteContent;
24
+ // Read the template contents
25
+ const templatesDir = path.join(__dirname, '..', 'templates');
26
+ const routeTemplatePath = path.join(templatesDir, 'route.ts.template');
27
+ const wrapperTemplatePath = path.join(templatesDir, 'ChatWrapper.tsx.template');
28
+
29
+ let routeTemplateContent;
30
+ let wrapperTemplateContent;
27
31
 
28
32
  try {
29
- apiRouteContent = fs.readFileSync(templatePath, 'utf8');
33
+ routeTemplateContent = fs.readFileSync(routeTemplatePath, 'utf8');
34
+ wrapperTemplateContent = fs.readFileSync(wrapperTemplatePath, 'utf8');
30
35
  } catch (error) {
31
- console.error(`${colors.red}❌ Error reading template file: ${error.message}${colors.reset}`);
36
+ console.error(`${colors.red}❌ Error reading template files: ${error.message}${colors.reset}`);
32
37
  process.exit(1);
33
38
  }
34
39
 
@@ -39,9 +44,7 @@ function isNextJsProject(cwd) {
39
44
  'next.config.mjs',
40
45
  'next.config.ts',
41
46
  path.join('app', 'layout.tsx'),
42
- path.join('app', 'layout.js'),
43
- path.join('app', 'page.tsx'),
44
- path.join('app', 'page.js')
47
+ path.join('app', 'app', 'layout.tsx')
45
48
  ];
46
49
 
47
50
  for (const indicator of indicators) {
@@ -115,41 +118,65 @@ function setup() {
115
118
  }
116
119
 
117
120
  function createFiles(cwd) {
118
- const targetDir = path.join(cwd, 'app', 'api', 'bridge-auth');
119
- const targetFile = path.join(targetDir, 'route.ts');
121
+ // 1. Create the API Route
122
+ const apiDir = path.join(cwd, 'app', 'api', 'bridge-auth');
123
+ const apiFile = path.join(apiDir, 'route.ts');
120
124
 
121
- // Check if file already exists
122
- if (fs.existsSync(targetFile)) {
125
+ if (fs.existsSync(apiFile)) {
123
126
  log.warning('API route already exists at: app/api/bridge-auth/route.ts');
124
- log.info('Skipping file creation to avoid overwriting.');
125
127
  } else {
126
- // Create directory structure
127
- if (!fs.existsSync(targetDir)) {
128
- fs.mkdirSync(targetDir, { recursive: true });
128
+ if (!fs.existsSync(apiDir)) {
129
+ fs.mkdirSync(apiDir, { recursive: true });
129
130
  log.success('Created directory: app/api/bridge-auth/');
130
131
  }
131
-
132
- // Write the API route file
133
- fs.writeFileSync(targetFile, apiRouteContent, 'utf8');
132
+ fs.writeFileSync(apiFile, routeTemplateContent, 'utf8');
134
133
  log.success('Created API route: app/api/bridge-auth/route.ts');
135
134
  }
136
135
 
136
+ // 2. Create the ChatWrapper Component
137
+ // Try to find components directory, fallback to cwd/components
138
+ let componentsDir = path.join(cwd, 'components');
139
+ if (!fs.existsSync(componentsDir)) {
140
+ // Check if there's an src/components
141
+ const srcComponents = path.join(cwd, 'src', 'components');
142
+ if (fs.existsSync(srcComponents)) {
143
+ componentsDir = srcComponents;
144
+ } else {
145
+ // Create a components directory if it doesn't exist
146
+ fs.mkdirSync(componentsDir, { recursive: true });
147
+ log.success('Created directory: components/');
148
+ }
149
+ }
150
+
151
+ const wrapperFile = path.join(componentsDir, 'ChatWrapper.tsx');
152
+
153
+ if (fs.existsSync(wrapperFile)) {
154
+ log.warning('ChatWrapper already exists at: components/ChatWrapper.tsx');
155
+ } else {
156
+ fs.writeFileSync(wrapperFile, wrapperTemplateContent, 'utf8');
157
+ log.success(`Created ChatWrapper: ${path.relative(cwd, wrapperFile)}`);
158
+ }
159
+
137
160
  console.log('\n');
138
161
  log.step('Next Steps:');
139
162
  console.log('\n');
140
163
  console.log(' 1. Install the package (if not already):');
141
164
  console.log(` ${colors.yellow}npm install @bridge-ai-dev/ecom-chat${colors.reset}`);
142
165
  console.log('\n');
143
- console.log(' 2. Add the ChatComponent to your layout.tsx:');
144
- console.log(` ${colors.yellow}import { ChatComponent } from '@bridge-ai-dev/ecom-chat';${colors.reset}`);
166
+ console.log(' 2. Add environment variables to your .env.local:');
167
+ console.log(` ${colors.yellow}NEXT_PUBLIC_BRIDGE_TENANT_ID=your-tenant-id${colors.reset}`);
168
+ console.log(` ${colors.yellow}NEXT_PUBLIC_BRIDGE_WIDGET_URL=https://...${colors.reset}`);
169
+ console.log(` ${colors.yellow}RUNTIME_LITIUM_SERVER_URL=https://your-litium-backend.com${colors.reset}`);
145
170
  console.log('\n');
146
- console.log(' 3. Include it in your layout:');
147
- console.log(` ${colors.yellow}<ChatComponent tenantId="your-tenant-uuid" />${colors.reset}`);
171
+ console.log(' 3. Use the ChatWrapper in your app/layout.tsx:');
172
+ console.log(` ${colors.yellow}import ChatWrapper from 'components/ChatWrapper';${colors.reset}`);
173
+ console.log(' ...');
174
+ console.log(` ${colors.yellow}<ChatWrapper />${colors.reset}`);
148
175
  console.log('\n');
149
- console.log(' 4. Add your chat widget script to the layout:');
150
- console.log(` ${colors.yellow}<script src="https://your-cdn.com/chat-widget.js" async />${colors.reset}`);
176
+ console.log(' 4. Verify the bridge-auth route is accessible:');
177
+ console.log(` ${colors.blue}http://localhost:3000/api/bridge-auth${colors.reset}`);
151
178
  console.log('\n');
152
- log.success('Setup complete! 🎉');
179
+ log.success('Scaffolding complete! 🎉');
153
180
  console.log('\n');
154
181
  }
155
182
 
@@ -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,CAmOtD,CAAC;AAEF,eAAe,aAAa,CAAC"}
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;AAuCtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAwOtD,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -4,6 +4,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ChatComponent = void 0;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_1 = require("react");
7
+ /**
8
+ * Attempt client-side cart creation using the provided getCartFunction,
9
+ * then re-fetch bridge-auth to pick up the newly created cart-context cookie.
10
+ */
11
+ async function tryClientCartCreation(bridgeAuthEndpoint, getCartFunction, currentAuthData) {
12
+ try {
13
+ await getCartFunction();
14
+ console.log('[ecom-package] getCartFunction completed. Re-fetching bridge auth...');
15
+ const retryRes = await fetch(bridgeAuthEndpoint, {
16
+ method: 'GET',
17
+ credentials: 'include',
18
+ });
19
+ if (!retryRes.ok) {
20
+ console.warn('[ecom-package] Bridge auth retry failed:', retryRes.status);
21
+ return currentAuthData;
22
+ }
23
+ const retryData = await retryRes.json();
24
+ if (retryData.cart_context) {
25
+ console.log('[ecom-package] cart-context obtained after client-side creation.');
26
+ return retryData;
27
+ }
28
+ console.warn('[ecom-package] cart-context still missing after client-side creation.');
29
+ return currentAuthData;
30
+ }
31
+ catch (cartError) {
32
+ console.warn('[ecom-package] Client-side cart creation failed:', cartError);
33
+ return currentAuthData;
34
+ }
35
+ }
7
36
  /**
8
37
  * ChatComponent - Bridge Chat Widget Integration for Next.js
9
38
  *
@@ -36,7 +65,7 @@ const react_1 = require("react");
36
65
  */
37
66
  const ChatComponent = ({ tenantId, onAuthSuccess, onAuthError, bridgeAuthEndpoint = '/api/bridge-auth', containerId = 'bgc-chat-container',
38
67
  // Widget configuration options
39
- position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext, getCartFunction }) => {
68
+ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext, cartCreationMode = 'server', getCartFunction }) => {
40
69
  const [isInitialized, setIsInitialized] = (0, react_1.useState)(false);
41
70
  const [error, setError] = (0, react_1.useState)(null);
42
71
  const [scriptLoaded, setScriptLoaded] = (0, react_1.useState)(false);
@@ -87,7 +116,10 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
87
116
  }
88
117
  else {
89
118
  // 1. Call our local Next.js bridge route to get secure cookies
119
+ // In 'server' mode (default), the bridge-auth route automatically
120
+ // creates a cart if cart-context is missing — no client-side retry needed.
90
121
  console.log('[ecom-package] Fetching bridge auth from:', bridgeAuthEndpoint);
122
+ console.log('[ecom-package] Cart creation mode:', cartCreationMode);
91
123
  const authRes = await fetch(bridgeAuthEndpoint, {
92
124
  method: 'GET',
93
125
  credentials: 'include', // Important: include cookies in the request
@@ -97,42 +129,45 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
97
129
  }
98
130
  authData = await authRes.json();
99
131
  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);
132
+ // 2. Handle missing cart-context based on cartCreationMode
133
+ if (authData.cart_context_missing) {
134
+ if (cartCreationMode === 'server') {
135
+ // In server mode, the bridge-auth route should have created
136
+ // the cart already. If it still reports missing, log a warning.
137
+ // Fall back to client-side if getCartFunction is available.
138
+ console.warn('[ecom-package] Server-side cart creation did not produce a cart-context.');
139
+ if (getCartFunction) {
140
+ console.log('[ecom-package] Falling back to client-side cart creation...');
141
+ authData = await tryClientCartCreation(bridgeAuthEndpoint, getCartFunction, authData);
113
142
  }
114
143
  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
- }
144
+ console.warn('[ecom-package] No getCartFunction fallback. Proceeding without cart context.');
125
145
  }
126
146
  }
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.');
147
+ else if (cartCreationMode === 'client' && getCartFunction) {
148
+ // Client mode: use the provided getCartFunction
149
+ console.log('[ecom-package] Client-side cart creation mode. Triggering getCartFunction...');
150
+ authData = await tryClientCartCreation(bridgeAuthEndpoint, getCartFunction, authData);
131
151
  }
152
+ else if (cartCreationMode === 'none') {
153
+ console.log('[ecom-package] Cart creation mode is "none". Proceeding without cart context.');
154
+ }
155
+ else {
156
+ console.warn('[ecom-package] cart-context missing. Mode:', cartCreationMode, getCartFunction ? '(getCartFunction available)' : '(no getCartFunction)');
157
+ }
158
+ }
159
+ }
160
+ // 3. Persist the cart context as a client-accessible cookie
161
+ // The Litium proxy may strip Set-Cookie headers from API responses,
162
+ // so we persist a fallback "bridge-cart-context" cookie via JavaScript.
163
+ // The bridge-auth route checks both "cart-context" and "bridge-cart-context".
164
+ if (authData.cart_context) {
165
+ try {
166
+ document.cookie = `bridge-cart-context=${authData.cart_context}; path=/; max-age=${60 * 60 * 24 * 7}; SameSite=Lax`;
167
+ console.log('[ecom-package] Persisted bridge-cart-context cookie');
132
168
  }
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.');
169
+ catch (cookieErr) {
170
+ console.warn('[ecom-package] Failed to persist cart context cookie:', cookieErr);
136
171
  }
137
172
  }
138
173
  // 2. Wait for BridgeChat to be available (with timeout)
@@ -209,6 +244,7 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
209
244
  autoPopup,
210
245
  onAuthSuccess,
211
246
  onAuthError,
247
+ cartCreationMode,
212
248
  getCartFunction
213
249
  ]);
214
250
  (0, react_1.useEffect)(() => {
@@ -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,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,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAExD,oDAAoD;IACpD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,CAAC,eAAe,EAAE,CAAC;YACnB,6CAA6C;YAC7C,eAAe,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO;QACX,CAAC;QAED,iCAAiC;QACjC,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC,eAAe,eAAe,IAAI,CAAC,CAAC;QAClF,IAAI,cAAc,EAAE,CAAC;YACjB,eAAe,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO;QACX,CAAC;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,iBAAS,EAAC,GAAG,EAAE;QACX,QAAQ,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,yCAAyC;IACzC,8DAA8D;IAC9D,OAAO,CACH,gCACI,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;AAxOW,QAAA,aAAa,iBAwOxB;AAEF,kBAAe,qBAAa,CAAC"}
@@ -43,14 +43,28 @@ export interface ChatComponentProps {
43
43
  identity?: string;
44
44
  /** Optional cart context token to skip internal API call */
45
45
  cartContext?: string;
46
+ /**
47
+ * Controls how cart context is created when the cart-context cookie is missing.
48
+ *
49
+ * - `'server'` (default): The bridge-auth API route handles cart creation
50
+ * server-side using the Litium CreateCart mutation. No additional props needed.
51
+ * - `'client'`: Falls back to calling `getCartFunction` on the client side,
52
+ * then retries bridge-auth. Requires `getCartFunction` prop.
53
+ * - `'none'`: No automatic cart creation. The widget initializes without
54
+ * a cart context if the cookie is missing.
55
+ */
56
+ cartCreationMode?: 'server' | 'client' | 'none';
46
57
  /**
47
58
  * Optional function to call getCart from the client side.
59
+ * Used as a fallback when `cartCreationMode` is `'client'`, or when
60
+ * server-side cart creation (the default) fails.
61
+ *
48
62
  * When cart-context cookie is missing, this function will be called
49
63
  * to trigger cart creation (which sets the cookie), then bridge-auth
50
64
  * is re-fetched to pick up the newly created cookie.
51
65
  *
52
66
  * Example: import { get as getCart } from 'services/cartService.client';
53
- * <ChatComponent getCartFunction={getCart} />
67
+ * <ChatComponent getCartFunction={getCart} cartCreationMode="client" />
54
68
  */
55
69
  getCartFunction?: () => Promise<any>;
56
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,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AAS,CAAC,EAAE,OAAO,CAAC;IAEpB,wCAAwC;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,oDAAoD;IACpD,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"}
@@ -1,6 +1,35 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useEffect, useState, useCallback } from 'react';
4
+ /**
5
+ * Attempt client-side cart creation using the provided getCartFunction,
6
+ * then re-fetch bridge-auth to pick up the newly created cart-context cookie.
7
+ */
8
+ async function tryClientCartCreation(bridgeAuthEndpoint, getCartFunction, currentAuthData) {
9
+ try {
10
+ await getCartFunction();
11
+ console.log('[ecom-package] getCartFunction completed. Re-fetching bridge auth...');
12
+ const retryRes = await fetch(bridgeAuthEndpoint, {
13
+ method: 'GET',
14
+ credentials: 'include',
15
+ });
16
+ if (!retryRes.ok) {
17
+ console.warn('[ecom-package] Bridge auth retry failed:', retryRes.status);
18
+ return currentAuthData;
19
+ }
20
+ const retryData = await retryRes.json();
21
+ if (retryData.cart_context) {
22
+ console.log('[ecom-package] cart-context obtained after client-side creation.');
23
+ return retryData;
24
+ }
25
+ console.warn('[ecom-package] cart-context still missing after client-side creation.');
26
+ return currentAuthData;
27
+ }
28
+ catch (cartError) {
29
+ console.warn('[ecom-package] Client-side cart creation failed:', cartError);
30
+ return currentAuthData;
31
+ }
32
+ }
4
33
  /**
5
34
  * ChatComponent - Bridge Chat Widget Integration for Next.js
6
35
  *
@@ -33,7 +62,7 @@ import { useEffect, useState, useCallback } from 'react';
33
62
  */
34
63
  export const ChatComponent = ({ tenantId, onAuthSuccess, onAuthError, bridgeAuthEndpoint = '/api/bridge-auth', containerId = 'bgc-chat-container',
35
64
  // Widget configuration options
36
- position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext, getCartFunction }) => {
65
+ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffffff', size = 'medium', borderWidth = 2, borderColor = '#4f46e5', autoPopup = false, widgetScriptUrl, identity, cartContext, cartCreationMode = 'server', getCartFunction }) => {
37
66
  const [isInitialized, setIsInitialized] = useState(false);
38
67
  const [error, setError] = useState(null);
39
68
  const [scriptLoaded, setScriptLoaded] = useState(false);
@@ -84,7 +113,10 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
84
113
  }
85
114
  else {
86
115
  // 1. Call our local Next.js bridge route to get secure cookies
116
+ // In 'server' mode (default), the bridge-auth route automatically
117
+ // creates a cart if cart-context is missing — no client-side retry needed.
87
118
  console.log('[ecom-package] Fetching bridge auth from:', bridgeAuthEndpoint);
119
+ console.log('[ecom-package] Cart creation mode:', cartCreationMode);
88
120
  const authRes = await fetch(bridgeAuthEndpoint, {
89
121
  method: 'GET',
90
122
  credentials: 'include', // Important: include cookies in the request
@@ -94,42 +126,45 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
94
126
  }
95
127
  authData = await authRes.json();
96
128
  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);
129
+ // 2. Handle missing cart-context based on cartCreationMode
130
+ if (authData.cart_context_missing) {
131
+ if (cartCreationMode === 'server') {
132
+ // In server mode, the bridge-auth route should have created
133
+ // the cart already. If it still reports missing, log a warning.
134
+ // Fall back to client-side if getCartFunction is available.
135
+ console.warn('[ecom-package] Server-side cart creation did not produce a cart-context.');
136
+ if (getCartFunction) {
137
+ console.log('[ecom-package] Falling back to client-side cart creation...');
138
+ authData = await tryClientCartCreation(bridgeAuthEndpoint, getCartFunction, authData);
110
139
  }
111
140
  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
- }
141
+ console.warn('[ecom-package] No getCartFunction fallback. Proceeding without cart context.');
122
142
  }
123
143
  }
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.');
144
+ else if (cartCreationMode === 'client' && getCartFunction) {
145
+ // Client mode: use the provided getCartFunction
146
+ console.log('[ecom-package] Client-side cart creation mode. Triggering getCartFunction...');
147
+ authData = await tryClientCartCreation(bridgeAuthEndpoint, getCartFunction, authData);
128
148
  }
149
+ else if (cartCreationMode === 'none') {
150
+ console.log('[ecom-package] Cart creation mode is "none". Proceeding without cart context.');
151
+ }
152
+ else {
153
+ console.warn('[ecom-package] cart-context missing. Mode:', cartCreationMode, getCartFunction ? '(getCartFunction available)' : '(no getCartFunction)');
154
+ }
155
+ }
156
+ }
157
+ // 3. Persist the cart context as a client-accessible cookie
158
+ // The Litium proxy may strip Set-Cookie headers from API responses,
159
+ // so we persist a fallback "bridge-cart-context" cookie via JavaScript.
160
+ // The bridge-auth route checks both "cart-context" and "bridge-cart-context".
161
+ if (authData.cart_context) {
162
+ try {
163
+ document.cookie = `bridge-cart-context=${authData.cart_context}; path=/; max-age=${60 * 60 * 24 * 7}; SameSite=Lax`;
164
+ console.log('[ecom-package] Persisted bridge-cart-context cookie');
129
165
  }
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.');
166
+ catch (cookieErr) {
167
+ console.warn('[ecom-package] Failed to persist cart context cookie:', cookieErr);
133
168
  }
134
169
  }
135
170
  // 2. Wait for BridgeChat to be available (with timeout)
@@ -206,6 +241,7 @@ position = 'bottom-right', backgroundColor = '#6366f1', foregroundColor = '#ffff
206
241
  autoPopup,
207
242
  onAuthSuccess,
208
243
  onAuthError,
244
+ cartCreationMode,
209
245
  getCartFunction
210
246
  ]);
211
247
  useEffect(() => {
@@ -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;A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+ "version": "1.0.11",
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",
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+
3
+ import { ChatComponent } from '@bridge-ai-dev/ecom-chat';
4
+
5
+ /**
6
+ * ChatWrapper Component
7
+ *
8
+ * This component wraps the Bridge ChatComponent. By default, it uses
9
+ * 'server' cart creation mode, which relies on the /api/bridge-auth route
10
+ * to initialize the Litium cart context.
11
+ */
12
+ export default function ChatWrapper() {
13
+ return (
14
+ <ChatComponent
15
+ tenantId={process.env.NEXT_PUBLIC_BRIDGE_TENANT_ID || ""}
16
+ widgetScriptUrl={process.env.NEXT_PUBLIC_BRIDGE_WIDGET_URL}
17
+ />
18
+ );
19
+ }
@@ -1,49 +1,208 @@
1
1
  import { NextRequest, NextResponse } from "next/server";
2
2
 
3
+ const CREATE_CART_MUTATION = `
4
+ mutation CreateCart {
5
+ createCart {
6
+ cart {
7
+ __typename
8
+ }
9
+ }
10
+ }
11
+ `;
12
+
3
13
  /**
4
- * Bridge Auth API Route
14
+ * Constructs the GraphQL endpoint URL.
15
+ * Uses the same Next.js server so the rewrite rule in next.config.js
16
+ * forwards the request to Litium with proper context.
5
17
  *
18
+ * Note: The incoming request.url may show https:// (from the proxy),
19
+ * but the Next.js dev server runs on http://. We force http:// for
20
+ * localhost to avoid SSL errors.
21
+ */
22
+ function getGraphQLUrl(request: NextRequest): string {
23
+ const url = new URL(request.url);
24
+ // Force http:// for localhost — Next.js dev server doesn't use SSL
25
+ if (url.hostname === 'localhost' || url.hostname === '127.0.0.1') {
26
+ url.protocol = 'http:';
27
+ }
28
+ return `${url.origin}/storefront.graphql`;
29
+ }
30
+
31
+ /**
32
+ * Parse a single Set-Cookie header string into a cookie object.
33
+ */
34
+ function parseSetCookieString(cookieStr: string): { name: string; value: string; [k: string]: any } | null {
35
+ const parts = cookieStr.split(';').map(p => p.trim());
36
+ const [nameValue, ...attrs] = parts;
37
+ const eqIdx = nameValue.indexOf('=');
38
+ if (eqIdx === -1) return null;
39
+
40
+ const name = nameValue.substring(0, eqIdx);
41
+ const value = nameValue.substring(eqIdx + 1);
42
+
43
+ const cookieObj: any = { name, value };
44
+ for (const attr of attrs) {
45
+ const [aKey, ...aValParts] = attr.split('=');
46
+ const aKeyLower = aKey.toLowerCase().trim();
47
+ const aVal = aValParts.join('=').trim();
48
+
49
+ if (aKeyLower === 'path') cookieObj.path = aVal || '/';
50
+ if (aKeyLower === 'max-age') cookieObj.maxAge = parseInt(aVal, 10);
51
+ if (aKeyLower === 'httponly') cookieObj.httpOnly = true;
52
+ if (aKeyLower === 'secure') cookieObj.secure = true;
53
+ if (aKeyLower === 'samesite') cookieObj.sameSite = aVal.toLowerCase();
54
+ if (aKeyLower === 'domain') cookieObj.domain = aVal;
55
+ }
56
+
57
+ return cookieObj;
58
+ }
59
+
60
+ /**
61
+ * Bridge Auth API Route
62
+ *
6
63
  * This route acts as a secure bridge to retrieve HttpOnly cookies
7
64
  * that cannot be accessed from client-side JavaScript.
8
- *
65
+ *
9
66
  * The ChatComponent uses this route to get authentication context
10
67
  * 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.
68
+ *
69
+ * If the cart-context cookie is missing, this route will automatically
70
+ * create a new cart by calling the Litium CreateCart mutation server-side,
71
+ * and forward the resulting Set-Cookie headers to the browser.
15
72
  */
16
73
  export const GET = async (request: NextRequest) => {
17
74
  const cookies = request.cookies;
18
75
 
19
- // Debug: Log all available cookie names
20
- const allCookieNames = cookies.getAll().map(c => c.name);
21
- console.log('[bridge-auth] All cookie names:', allCookieNames);
22
76
  console.log('[bridge-auth] Raw cookie header:', request.headers.get("cookie"));
23
-
77
+
24
78
  // Retrieve the secure cookies
25
79
  const identity = cookies.get(".AspNetCore.Identity.Application")?.value;
26
- const cartContext = cookies.get("cart-context")?.value;
80
+ // Check native Litium cart-context first, then our fallback bridge-cart-context
81
+ let cartContext = cookies.get("cart-context")?.value
82
+ || cookies.get("bridge-cart-context")?.value;
83
+
84
+ console.log('[bridge-auth] Identity:', identity ? 'FOUND' : 'NOT FOUND');
85
+ console.log('[bridge-auth] Cart context:', cartContext ? 'FOUND' : 'NOT FOUND',
86
+ cartContext ? `(from: ${cookies.get("cart-context")?.value ? 'cart-context' : 'bridge-cart-context'})` : '');
87
+
88
+ const responseCookies: Array<{ name: string; value: string; [k: string]: any }> = [];
89
+
90
+ // If cart-context is missing, create one via the Litium CreateCart mutation
91
+ if (!cartContext) {
92
+ console.log('[bridge-auth] cart-context missing. Creating cart server-side...');
93
+ try {
94
+ const graphqlUrl = getGraphQLUrl(request);
95
+ console.log('[bridge-auth] GraphQL URL:', graphqlUrl);
96
+
97
+ // Determine the storefront context URL for the Litium header.
98
+ // This MUST be the storefront URL (e.g., https://localhost:3001/),
99
+ // NOT the Litium backend URL. Litium uses this to resolve the channel/website.
100
+ const refererUrl = request.headers.get('referer');
101
+ const originUrl = request.headers.get('origin');
102
+ const storefrontContextUrl = refererUrl || originUrl || new URL(request.url).origin;
103
+ console.log('[bridge-auth] Context URL:', storefrontContextUrl,
104
+ '(from:', refererUrl ? 'referer' : originUrl ? 'origin' : 'request.url', ')');
105
+
106
+ const gqlRes = await fetch(graphqlUrl, {
107
+ method: 'POST',
108
+ headers: {
109
+ 'Content-Type': 'application/json',
110
+ // Critical: Litium requires this to know which storefront context to use
111
+ 'x-litium-storefront-context-url': storefrontContextUrl,
112
+ // Forward the browser's cookies to Litium so it can associate
113
+ // the new cart with any existing session/identity
114
+ ...(request.headers.get('cookie')
115
+ ? { 'Cookie': request.headers.get('cookie')! }
116
+ : {}),
117
+ },
118
+ body: JSON.stringify({ query: CREATE_CART_MUTATION }),
119
+ });
120
+
121
+ console.log('[bridge-auth] CreateCart response status:', gqlRes.status);
122
+
123
+ // Log all response headers for debugging
124
+ const allHeaders: Record<string, string> = {};
125
+ gqlRes.headers.forEach((value, key) => {
126
+ allHeaders[key] = key.toLowerCase() === 'set-cookie' ? value : value.substring(0, 100);
127
+ });
128
+ console.log('[bridge-auth] Response headers:', JSON.stringify(allHeaders));
27
129
 
28
- // Debug: Log retrieved values
29
- console.log('[bridge-auth] Identity cookie value:', identity ?? 'NOT FOUND');
30
- console.log('[bridge-auth] Cart context cookie value:', cartContext ?? 'NOT FOUND');
130
+ if (gqlRes.ok) {
131
+ // Log the response body for debugging
132
+ const responseBody = await gqlRes.text();
133
+ console.log('[bridge-auth] CreateCart response body:', responseBody.substring(0, 500));
31
134
 
32
- const cartContextMissing = !cartContext;
135
+ // Extract Set-Cookie headers from Litium's response
136
+ // Use getSetCookie() (standard) with fallback to get('set-cookie')
137
+ const setCookieHeaders: string[] = gqlRes.headers.getSetCookie?.()
138
+ ?? (gqlRes.headers.get('set-cookie')?.split(',')
139
+ .map((s: string) => s.trim())
140
+ .filter(Boolean) as string[] ?? []);
33
141
 
34
- if (cartContextMissing) {
35
- console.log('[bridge-auth] cart-context cookie is missing. Client should trigger cart creation and retry.');
142
+ console.log('[bridge-auth] Set-Cookie headers count:', setCookieHeaders.length);
143
+ if (setCookieHeaders.length > 0) {
144
+ console.log('[bridge-auth] Set-Cookie values:', setCookieHeaders.map(s => s.substring(0, 80)));
145
+ }
146
+
147
+ for (const cookieStr of setCookieHeaders) {
148
+ const parsed = parseSetCookieString(cookieStr);
149
+ if (!parsed) continue;
150
+
151
+ responseCookies.push(parsed);
152
+
153
+ // Check if this is the cart-context cookie we need
154
+ if (parsed.name === 'cart-context') {
155
+ cartContext = parsed.value;
156
+ console.log('[bridge-auth] Cart context created successfully');
157
+ }
158
+ }
159
+
160
+ // Also check for cart context in the GraphQL extensions
161
+ // Litium may return the cart context in the extensions field instead of Set-Cookie
162
+ try {
163
+ const jsonBody = JSON.parse(responseBody);
164
+ const extensionCartContext = jsonBody?.extensions?.['x-litium-storefront-cart-context'];
165
+ if (extensionCartContext && !cartContext) {
166
+ cartContext = extensionCartContext;
167
+ console.log('[bridge-auth] Cart context obtained from extensions field');
168
+ }
169
+ } catch (parseErr) {
170
+ // Ignore parse errors
171
+ }
172
+
173
+ if (!cartContext) {
174
+ console.warn('[bridge-auth] CreateCart succeeded but no cart-context in response');
175
+ }
176
+ } else {
177
+ const errorText = await gqlRes.text().catch(() => 'unknown');
178
+ console.error('[bridge-auth] CreateCart mutation failed:', gqlRes.status, errorText);
179
+ }
180
+ } catch (err) {
181
+ console.error('[bridge-auth] Error creating cart:', err);
182
+ }
36
183
  }
37
184
 
38
- const response = {
185
+ const jsonBody = {
39
186
  identity: identity || null,
40
187
  cart_context: cartContext || null,
41
- cart_context_missing: cartContextMissing,
42
- // Optional: Include the raw cookie string if your backend needs it
43
- raw: request.headers.get("cookie")
188
+ cart_context_missing: !cartContext,
189
+ raw: request.headers.get("cookie"),
44
190
  };
45
191
 
46
- console.log('[bridge-auth] Returning response:', JSON.stringify(response, null, 2));
192
+ console.log('[bridge-auth] Response:', JSON.stringify({
193
+ identity: jsonBody.identity ? '[present]' : null,
194
+ cart_context: jsonBody.cart_context ? '[present]' : null,
195
+ cart_context_missing: jsonBody.cart_context_missing,
196
+ }));
197
+
198
+ const response = NextResponse.json(jsonBody);
199
+
200
+ // Forward Litium's Set-Cookie headers to the browser so
201
+ // the cart-context cookie is persisted for subsequent requests
202
+ for (const cookie of responseCookies) {
203
+ const { name, value, ...options } = cookie;
204
+ response.cookies.set(name, value, options);
205
+ }
47
206
 
48
- return NextResponse.json(response);
207
+ return response;
49
208
  };