@takeshape/purchase-order-chat 1.51.0-beta.1
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 +305 -0
- package/dist/pdf-CYwqEJpJ.js +20562 -0
- package/dist/pdf-CYwqEJpJ.js.map +1 -0
- package/dist/pdf.worker-eoyvlo7V.js +37634 -0
- package/dist/pdf.worker-eoyvlo7V.js.map +1 -0
- package/dist/purchase-order-chat-wrapper-D8d5NFc9.js +7899 -0
- package/dist/purchase-order-chat-wrapper-D8d5NFc9.js.map +1 -0
- package/dist/shadow.d.ts +1505 -0
- package/dist/shadow.js +58 -0
- package/dist/shadow.js.map +1 -0
- package/dist/sources.css +4 -0
- package/dist/tailwind.d.ts +1502 -0
- package/dist/tailwind.js +15 -0
- package/dist/tailwind.js.map +1 -0
- package/dist/testing.d.ts +456 -0
- package/dist/testing.js +610 -0
- package/dist/testing.js.map +1 -0
- package/dist/theme.css +75 -0
- package/dist/utilities.css +233 -0
- package/package.json +87 -0
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# @takeshape/purchase-order-chat
|
|
2
|
+
|
|
3
|
+
A React component library for purchase order chat integration with BigCommerce storefronts.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @takeshape/purchase-order-chat
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @takeshape/purchase-order-chat
|
|
11
|
+
# or
|
|
12
|
+
yarn add @takeshape/purchase-order-chat
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- React 19+
|
|
18
|
+
|
|
19
|
+
## Choosing an Import
|
|
20
|
+
|
|
21
|
+
This library provides three entry points:
|
|
22
|
+
|
|
23
|
+
| Import | Use Case | CSS Handling |
|
|
24
|
+
| ----------------------------------------- | -------------------------- | ----------------------------------- |
|
|
25
|
+
| `@takeshape/purchase-order-chat` | Default - works everywhere | Shadow DOM with bundled CSS |
|
|
26
|
+
| `@takeshape/purchase-order-chat/tailwind` | Tailwind v4 projects | Integrates with your Tailwind setup |
|
|
27
|
+
| `@takeshape/purchase-order-chat/testing` | Unit tests and Storybook | Mock BigCommerce client |
|
|
28
|
+
|
|
29
|
+
**Default (recommended for most projects):**
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { PurchaseOrderChatWidget } from "@takeshape/purchase-order-chat";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**For Tailwind v4 projects** (like Catalyst with Tailwind v4):
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { PurchaseOrderChatWidget } from "@takeshape/purchase-order-chat/tailwind";
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The default version wraps the component in a Shadow DOM with all styles bundled, ensuring no CSS conflicts with your existing styles.
|
|
42
|
+
|
|
43
|
+
## Basic Usage
|
|
44
|
+
|
|
45
|
+
The simplest way to integrate the component:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { PurchaseOrderChatWidget } from "@takeshape/purchase-order-chat";
|
|
49
|
+
|
|
50
|
+
function App() {
|
|
51
|
+
return (
|
|
52
|
+
<PurchaseOrderChatWidget
|
|
53
|
+
takeshape={{
|
|
54
|
+
projectId: "your-project-id",
|
|
55
|
+
apiKey: "your-api-key",
|
|
56
|
+
}}
|
|
57
|
+
bigcommerce={{
|
|
58
|
+
endpoint: "https://store-{hash}.mybigcommerce.com/graphql",
|
|
59
|
+
storefrontToken: "your-storefront-token",
|
|
60
|
+
channelId: 1,
|
|
61
|
+
}}
|
|
62
|
+
onViewProduct={(product) => {
|
|
63
|
+
window.location.href = product.path || `/product/${product.sku}`;
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Catalyst (Next.js) Integration
|
|
71
|
+
|
|
72
|
+
For BigCommerce Catalyst storefronts, the recommended approach uses a proxy API route to avoid CORS issues and keep your storefront token server-side.
|
|
73
|
+
|
|
74
|
+
### 1. Install the package
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pnpm add @takeshape/purchase-order-chat
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 2. Configure Tailwind
|
|
81
|
+
|
|
82
|
+
Add the library's source files to your Tailwind config:
|
|
83
|
+
|
|
84
|
+
```css
|
|
85
|
+
/* In your global CSS file */
|
|
86
|
+
@import "tailwindcss";
|
|
87
|
+
@source "../node_modules/@takeshape/purchase-order-chat/src";
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 3. Create a BigCommerce proxy route
|
|
91
|
+
|
|
92
|
+
Create `app/api/bigcommerce/graphql/route.ts`:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
96
|
+
|
|
97
|
+
const BIGCOMMERCE_STORE_HASH = process.env.BIGCOMMERCE_STORE_HASH;
|
|
98
|
+
const BIGCOMMERCE_STOREFRONT_TOKEN = process.env.BIGCOMMERCE_STOREFRONT_TOKEN;
|
|
99
|
+
|
|
100
|
+
export async function POST(request: NextRequest) {
|
|
101
|
+
if (!BIGCOMMERCE_STORE_HASH || !BIGCOMMERCE_STOREFRONT_TOKEN) {
|
|
102
|
+
return NextResponse.json(
|
|
103
|
+
{ errors: [{ message: "BigCommerce configuration missing" }] },
|
|
104
|
+
{ status: 500 },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const body = await request.json();
|
|
109
|
+
const response = await fetch(
|
|
110
|
+
`https://store-${BIGCOMMERCE_STORE_HASH}.mybigcommerce.com/graphql`,
|
|
111
|
+
{
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: {
|
|
114
|
+
"Content-Type": "application/json",
|
|
115
|
+
Authorization: `Bearer ${BIGCOMMERCE_STOREFRONT_TOKEN}`,
|
|
116
|
+
},
|
|
117
|
+
body: JSON.stringify(body),
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const data = await response.json();
|
|
122
|
+
return NextResponse.json(data, { status: response.status });
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 4. Create the page
|
|
127
|
+
|
|
128
|
+
Create `app/[locale]/(default)/purchase-order-agent/page.tsx`:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
"use client";
|
|
132
|
+
|
|
133
|
+
import { useRouter } from "~/i18n/routing";
|
|
134
|
+
import { PurchaseOrderChatWidget } from "@takeshape/purchase-order-chat/tailwind";
|
|
135
|
+
|
|
136
|
+
export default function PurchaseOrderAgentPage() {
|
|
137
|
+
const router = useRouter();
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div className="container mx-auto px-4 py-8">
|
|
141
|
+
<PurchaseOrderChatWidget
|
|
142
|
+
takeshape={{
|
|
143
|
+
projectId: process.env.NEXT_PUBLIC_TAKESHAPE_PROJECT_ID!,
|
|
144
|
+
apiKey: process.env.NEXT_PUBLIC_TAKESHAPE_API_KEY!,
|
|
145
|
+
}}
|
|
146
|
+
bigcommerce={{
|
|
147
|
+
endpoint: "/api/bigcommerce/graphql",
|
|
148
|
+
channelId: Number(process.env.NEXT_PUBLIC_BIGCOMMERCE_CHANNEL_ID),
|
|
149
|
+
}}
|
|
150
|
+
onViewProduct={(product) => product.path && router.push(product.path)}
|
|
151
|
+
onCheckout={(checkoutUrl) => router.push(checkoutUrl)}
|
|
152
|
+
/>
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 5. Add environment variables
|
|
159
|
+
|
|
160
|
+
Add to your `.env.local`:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# TakeShape Configuration
|
|
164
|
+
NEXT_PUBLIC_TAKESHAPE_PROJECT_ID=your-project-id
|
|
165
|
+
NEXT_PUBLIC_TAKESHAPE_API_KEY=your-api-key
|
|
166
|
+
NEXT_PUBLIC_BIGCOMMERCE_CHANNEL_ID=1
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The widget is now available at `/purchase-order-agent`.
|
|
170
|
+
|
|
171
|
+
## B2B Edition Support
|
|
172
|
+
|
|
173
|
+
For BigCommerce B2B Edition stores, you can enable B2B features (company addresses, B2B checkout) by providing a `getB2BJwt` callback.
|
|
174
|
+
|
|
175
|
+
### Stencil Themes
|
|
176
|
+
|
|
177
|
+
For Stencil storefronts, use the built-in `stencilB2BJwt` function:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import {
|
|
181
|
+
PurchaseOrderChatWidget,
|
|
182
|
+
stencilB2BJwt,
|
|
183
|
+
} from "@takeshape/purchase-order-chat";
|
|
184
|
+
|
|
185
|
+
<PurchaseOrderChatWidget
|
|
186
|
+
takeshape={{
|
|
187
|
+
projectId: "your-project-id",
|
|
188
|
+
apiKey: "your-api-key",
|
|
189
|
+
}}
|
|
190
|
+
bigcommerce={{
|
|
191
|
+
endpoint: "/graphql",
|
|
192
|
+
channelId: 1,
|
|
193
|
+
getB2BJwt: stencilB2BJwt,
|
|
194
|
+
}}
|
|
195
|
+
/>;
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Custom Implementation
|
|
199
|
+
|
|
200
|
+
For other platforms (like Catalyst/Next.js), implement your own token fetcher:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
const getB2BJwt = async (channelId: number) => {
|
|
204
|
+
const response = await fetch(`/api/b2b/token?channelId=${channelId}`);
|
|
205
|
+
if (!response.ok) return null;
|
|
206
|
+
const { token } = await response.json();
|
|
207
|
+
return token;
|
|
208
|
+
};
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Props Reference
|
|
212
|
+
|
|
213
|
+
### PurchaseOrderChatWidgetProps
|
|
214
|
+
|
|
215
|
+
| Prop | Type | Required | Description |
|
|
216
|
+
| --------------- | ---------------------------------------- | -------- | ------------------------------------------------------------------------------ |
|
|
217
|
+
| `takeshape` | `TakeShapeConfigProps` | Yes | TakeShape API configuration |
|
|
218
|
+
| `bigcommerce` | `BigCommerceConfigProps` | Yes | BigCommerce storefront configuration |
|
|
219
|
+
| `agentName` | `string` | No | TakeShape agent name. Defaults to `'bigcommercePurchaseOrderAgent'` |
|
|
220
|
+
| `inputName` | `string` | No | TakeShape input name. Defaults to `'bigcommercePurchaseOrderAgent'` |
|
|
221
|
+
| `onViewProduct` | `(product) => void` | No | Called when user clicks to view a product |
|
|
222
|
+
| `onCheckout` | `(checkoutUrl) => void \| Promise<void>` | No | Called when checkout is initiated. Defaults to `window.location.href` redirect |
|
|
223
|
+
| `className` | `string` | No | CSS class for the container |
|
|
224
|
+
| `expandOnReady` | `boolean` | No | Auto-expand to fullscreen modal when ready |
|
|
225
|
+
|
|
226
|
+
### TakeShapeConfigProps
|
|
227
|
+
|
|
228
|
+
| Prop | Type | Required | Description |
|
|
229
|
+
| ----------- | -------- | -------- | ------------------------------------------------------------------ |
|
|
230
|
+
| `projectId` | `string` | Yes | TakeShape project ID |
|
|
231
|
+
| `apiKey` | `string` | Yes | TakeShape API key |
|
|
232
|
+
| `origin` | `string` | No | TakeShape API origin URL. Defaults to `'https://api.takeshape.io'` |
|
|
233
|
+
| `sseOrigin` | `string` | No | TakeShape SSE origin URL. Defaults to `'https://api.takeshape.io'` |
|
|
234
|
+
|
|
235
|
+
### BigCommerceConfigProps
|
|
236
|
+
|
|
237
|
+
| Prop | Type | Required | Description |
|
|
238
|
+
| ----------------- | ------------------------------------------------ | -------- | ---------------------------------------------------------------------------------------------------- |
|
|
239
|
+
| `endpoint` | `string` | Yes | GraphQL endpoint URL (absolute or relative for proxy) |
|
|
240
|
+
| `storefrontToken` | `string` | No | Storefront API token. Optional when using a proxy |
|
|
241
|
+
| `channelId` | `number` | Yes | BigCommerce channel ID |
|
|
242
|
+
| `getB2BJwt` | `(channelId: number) => Promise<string \| null>` | No | B2B JWT fetcher. Receives channelId, returns B2B storefront token. For Stencil, use `stencilB2BJwt`. |
|
|
243
|
+
|
|
244
|
+
## Advanced Usage (Base Component)
|
|
245
|
+
|
|
246
|
+
For advanced use cases requiring custom provider setup or client management, use `PurchaseOrderChat` with `TakeShapeConfigProvider`:
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
import {
|
|
250
|
+
PurchaseOrderChat,
|
|
251
|
+
TakeShapeConfigProvider,
|
|
252
|
+
createBigCommerceClient,
|
|
253
|
+
} from "@takeshape/purchase-order-chat/tailwind";
|
|
254
|
+
|
|
255
|
+
const bigCommerceClient = createBigCommerceClient({
|
|
256
|
+
endpoint: "https://store-{hash}.mybigcommerce.com/graphql",
|
|
257
|
+
storefrontToken: "your-storefront-token",
|
|
258
|
+
channelId: 1,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
function App() {
|
|
262
|
+
return (
|
|
263
|
+
<TakeShapeConfigProvider projectId="your-project-id" apiKey="your-api-key">
|
|
264
|
+
<PurchaseOrderChat
|
|
265
|
+
bigcommerce={{
|
|
266
|
+
client: bigCommerceClient,
|
|
267
|
+
onViewProduct: (product) => {
|
|
268
|
+
window.location.href = product.path || `/product/${product.sku}`;
|
|
269
|
+
},
|
|
270
|
+
onCheckout: (checkoutUrl) => {
|
|
271
|
+
window.location.href = checkoutUrl;
|
|
272
|
+
},
|
|
273
|
+
}}
|
|
274
|
+
/>
|
|
275
|
+
</TakeShapeConfigProvider>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
For testing, import `createMockBigCommerceClient` from the `/testing` entry point:
|
|
281
|
+
|
|
282
|
+
```tsx
|
|
283
|
+
import { createMockBigCommerceClient } from "@takeshape/purchase-order-chat/testing";
|
|
284
|
+
|
|
285
|
+
const mockClient = createMockBigCommerceClient();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Styling
|
|
289
|
+
|
|
290
|
+
### For Tailwind v4 Projects
|
|
291
|
+
|
|
292
|
+
Configure Tailwind to scan the package source files:
|
|
293
|
+
|
|
294
|
+
```css
|
|
295
|
+
@import "tailwindcss";
|
|
296
|
+
@source "../node_modules/@takeshape/purchase-order-chat/src";
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### For Tailwind v3 or Non-Tailwind Projects
|
|
300
|
+
|
|
301
|
+
Use the default import - styles are bundled in a Shadow DOM:
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
import { PurchaseOrderChatWidget } from "@takeshape/purchase-order-chat";
|
|
305
|
+
```
|