@commercengine/pos 0.1.3 → 0.3.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 +104 -34
- package/dist/index.d.ts +3779 -129
- package/dist/index.js +1510 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ const pos = new PosSDK({
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
// Login with email (returns OTP token)
|
|
27
|
-
const { data: loginData, error: loginError } = await pos.
|
|
27
|
+
const { data: loginData, error: loginError } = await pos.loginWithEmail({
|
|
28
28
|
device_id: 'device-123',
|
|
29
29
|
email: 'cashier@store.com'
|
|
30
30
|
});
|
|
@@ -35,7 +35,7 @@ if (loginError) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// Verify OTP to get access tokens
|
|
38
|
-
const { data: authData, error: authError } = await pos.
|
|
38
|
+
const { data: authData, error: authError } = await pos.verifyOtp({
|
|
39
39
|
otp_token: loginData.otp_token,
|
|
40
40
|
otp: '123456'
|
|
41
41
|
});
|
|
@@ -46,8 +46,14 @@ if (authError) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Now you can make authenticated requests
|
|
49
|
-
const { data: cartData, error: cartError } = await pos.
|
|
50
|
-
|
|
49
|
+
const { data: cartData, error: cartError } = await pos.createCart({
|
|
50
|
+
items: [
|
|
51
|
+
{
|
|
52
|
+
product_id: "01H9XYZ12345ABCDE",
|
|
53
|
+
variant_id: null,
|
|
54
|
+
quantity: 2
|
|
55
|
+
}
|
|
56
|
+
]
|
|
51
57
|
});
|
|
52
58
|
|
|
53
59
|
if (cartData) {
|
|
@@ -222,7 +228,7 @@ The POS SDK uses a two-step authentication process:
|
|
|
222
228
|
|
|
223
229
|
```typescript
|
|
224
230
|
// Login with email
|
|
225
|
-
const { data: emailData, error: emailError } = await pos.
|
|
231
|
+
const { data: emailData, error: emailError } = await pos.loginWithEmail({
|
|
226
232
|
device_id: 'unique-device-id',
|
|
227
233
|
email: 'user@example.com'
|
|
228
234
|
});
|
|
@@ -233,13 +239,13 @@ if (emailError) {
|
|
|
233
239
|
}
|
|
234
240
|
|
|
235
241
|
// Login with phone
|
|
236
|
-
const { data: phoneData, error: phoneError } = await pos.
|
|
242
|
+
const { data: phoneData, error: phoneError } = await pos.loginWithPhone({
|
|
237
243
|
device_id: 'unique-device-id',
|
|
238
244
|
phone: '+1234567890'
|
|
239
245
|
});
|
|
240
246
|
|
|
241
247
|
// Login with WhatsApp
|
|
242
|
-
const { data: whatsappData, error: whatsappError } = await pos.
|
|
248
|
+
const { data: whatsappData, error: whatsappError } = await pos.loginWithWhatsapp({
|
|
243
249
|
device_id: 'unique-device-id',
|
|
244
250
|
phone: '+1234567890'
|
|
245
251
|
});
|
|
@@ -248,7 +254,7 @@ const { data: whatsappData, error: whatsappError } = await pos.pos.loginWithWhat
|
|
|
248
254
|
### Step 2: Verify OTP
|
|
249
255
|
|
|
250
256
|
```typescript
|
|
251
|
-
const { data: authData, error: authError } = await pos.
|
|
257
|
+
const { data: authData, error: authError } = await pos.verifyOtp({
|
|
252
258
|
otp_token: emailData.otp_token,
|
|
253
259
|
otp: '123456'
|
|
254
260
|
});
|
|
@@ -268,7 +274,7 @@ console.log('Authentication successful:', authData);
|
|
|
268
274
|
For new devices, you may need to pair first:
|
|
269
275
|
|
|
270
276
|
```typescript
|
|
271
|
-
const { data: pairData, error: pairError } = await pos.
|
|
277
|
+
const { data: pairData, error: pairError } = await pos.pairDevice({
|
|
272
278
|
pairing_code: 'ABC123'
|
|
273
279
|
});
|
|
274
280
|
|
|
@@ -282,7 +288,7 @@ console.log('Device paired successfully:', pairData);
|
|
|
282
288
|
|
|
283
289
|
## API Operations
|
|
284
290
|
|
|
285
|
-
The POS SDK provides access to all POS operations
|
|
291
|
+
The POS SDK provides access to all POS operations directly on the SDK instance:
|
|
286
292
|
|
|
287
293
|
### Authentication
|
|
288
294
|
- `loginWithEmail()` - Login with email address
|
|
@@ -290,38 +296,74 @@ The POS SDK provides access to all POS operations through the `pos` property:
|
|
|
290
296
|
- `loginWithWhatsapp()` - Login with WhatsApp
|
|
291
297
|
- `pairDevice()` - Pair a new device
|
|
292
298
|
- `verifyOtp()` - Verify OTP and get tokens
|
|
293
|
-
- `
|
|
299
|
+
- `refreshAccessToken()` - Refresh access token
|
|
300
|
+
- `logout()` - Logout from POS device
|
|
294
301
|
|
|
295
302
|
### Cart Management
|
|
296
|
-
- `createCart()` - Create a new cart
|
|
303
|
+
- `createCart()` - Create a new cart with items
|
|
297
304
|
- `getCart()` - Get cart details
|
|
298
|
-
- `updateCart()` -
|
|
299
|
-
- `deleteCart()` - Delete cart
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
- Add/remove/update line items
|
|
303
|
-
- Apply discounts and promotions
|
|
304
|
-
|
|
305
|
-
### Orders
|
|
306
|
-
- `createOrder()` - Create order from cart
|
|
305
|
+
- `updateCart()` - Add/update/remove cart items
|
|
306
|
+
- `deleteCart()` - Delete entire cart
|
|
307
|
+
- `createCartAddress()` - Set billing/shipping addresses
|
|
308
|
+
- `updateCartCustomer()` - Associate customer with cart
|
|
307
309
|
|
|
308
310
|
### Promotions & Coupons
|
|
309
311
|
- `listPromotions()` - Get available promotions
|
|
310
|
-
- `evaluatePromotions()` - Calculate promotion discounts
|
|
312
|
+
- `evaluatePromotions()` - Calculate promotion discounts for cart
|
|
311
313
|
- `listCoupons()` - Get available coupons
|
|
312
314
|
- `applyCoupon()` - Apply coupon to cart
|
|
313
315
|
- `removeCoupon()` - Remove coupon from cart
|
|
316
|
+
- `evaluateCoupons()` - Check applicable/inapplicable coupons
|
|
314
317
|
|
|
315
|
-
###
|
|
316
|
-
- `
|
|
317
|
-
- `
|
|
318
|
-
- `redeemLoyaltyPoints()` - Apply loyalty points
|
|
319
|
-
- `removeLoyaltyPoints()` - Remove loyalty points
|
|
318
|
+
### Credit Balance & Loyalty
|
|
319
|
+
- `redeemCreditBalance()` - Apply credit balance to cart
|
|
320
|
+
- `removeCreditBalance()` - Remove credit balance from cart
|
|
321
|
+
- `redeemLoyaltyPoints()` - Apply loyalty points to cart
|
|
322
|
+
- `removeLoyaltyPoints()` - Remove loyalty points from cart
|
|
320
323
|
|
|
321
324
|
### Fulfillment
|
|
322
325
|
- `updateFulfillmentPreference()` - Set pickup/delivery options
|
|
323
326
|
- `getFulfillmentOptions()` - Get available fulfillment methods
|
|
324
327
|
|
|
328
|
+
### Orders
|
|
329
|
+
- `createOrder()` - Create order from cart
|
|
330
|
+
- `listOrders()` - List orders (Admin)
|
|
331
|
+
- `getOrderDetail()` - Get order details (Admin)
|
|
332
|
+
- `listOrderActivity()` - Get order activity log (Admin)
|
|
333
|
+
- `getOrderInvoice()` - Get order invoice (Admin)
|
|
334
|
+
- `getOrderReceipt()` - Get order receipt (Admin)
|
|
335
|
+
- `getOrderShipments()` - Get order shipments (Admin)
|
|
336
|
+
|
|
337
|
+
### Catalog & Products
|
|
338
|
+
- `listCategories()` - List product categories
|
|
339
|
+
- `listProducts()` - List products with filtering
|
|
340
|
+
- `getProductDetail()` - Get product details
|
|
341
|
+
- `listProductVariants()` - Get product variants
|
|
342
|
+
- `getVariantDetail()` - Get variant details
|
|
343
|
+
- `listProductReviews()` - Get product reviews
|
|
344
|
+
- `searchProducts()` - Search products with filters
|
|
345
|
+
- `listCrosssellProducts()` - Get cross-sell recommendations
|
|
346
|
+
- `listSimilarProducts()` - Get similar product recommendations
|
|
347
|
+
- `listUpsellProducts()` - Get up-sell recommendations
|
|
348
|
+
- `listSkus()` - List all SKUs
|
|
349
|
+
|
|
350
|
+
### Inventory (Admin)
|
|
351
|
+
- `listInventories()` - List inventory levels
|
|
352
|
+
- `listInventoryActivities()` - List inventory activities
|
|
353
|
+
- `getInventoryDetail()` - Get inventory details
|
|
354
|
+
|
|
355
|
+
### Customers (Admin)
|
|
356
|
+
- `getCustomers()` - List customers
|
|
357
|
+
- `getCustomer()` - Get customer details
|
|
358
|
+
|
|
359
|
+
### Shipments (Admin)
|
|
360
|
+
- `listShipments()` - List shipments
|
|
361
|
+
- `getShipment()` - Get shipment details
|
|
362
|
+
- `updateShipment()` - Update shipment status
|
|
363
|
+
- `getShipmentInvoice()` - Get shipment invoice
|
|
364
|
+
- `checkInventory()` - Check inventory for order
|
|
365
|
+
- `refundShortfall()` - Process refund for shortfall
|
|
366
|
+
|
|
325
367
|
## User Information
|
|
326
368
|
|
|
327
369
|
Access user information from JWT tokens:
|
|
@@ -347,7 +389,15 @@ const isAuthenticated = await pos.isAuthenticated();
|
|
|
347
389
|
The SDK returns `ApiResult<T>` objects with consistent error handling:
|
|
348
390
|
|
|
349
391
|
```typescript
|
|
350
|
-
const { data, error, response } = await pos.
|
|
392
|
+
const { data, error, response } = await pos.createCart({
|
|
393
|
+
items: [
|
|
394
|
+
{
|
|
395
|
+
product_id: "01H9XYZ12345ABCDE",
|
|
396
|
+
variant_id: null,
|
|
397
|
+
quantity: 2
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
});
|
|
351
401
|
|
|
352
402
|
if (error) {
|
|
353
403
|
console.error('Error:', error.message);
|
|
@@ -412,19 +462,39 @@ const pos = new PosSDK({
|
|
|
412
462
|
|
|
413
463
|
## TypeScript Support
|
|
414
464
|
|
|
415
|
-
The SDK is written in TypeScript and provides full type safety:
|
|
465
|
+
The SDK is written in TypeScript and provides full type safety with advanced schema handling:
|
|
466
|
+
|
|
467
|
+
### Schema-Specific Typing
|
|
468
|
+
The POS SDK handles both regular storefront operations and admin operations with proper type safety. When both schemas define the same endpoint (like `/pos/orders`), the SDK automatically uses the appropriate schema based on the operation:
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
// Regular POS operation (POST) - uses storefront schema
|
|
472
|
+
await pos.createOrder({ cart_id: "cart-123" });
|
|
473
|
+
|
|
474
|
+
// Admin POS operation (GET) - uses admin schema
|
|
475
|
+
await pos.listOrders({ page: 1, limit: 10 });
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
This ensures you get proper TypeScript autocompletion and validation for each operation without any type conflicts.
|
|
416
479
|
|
|
417
480
|
```typescript
|
|
418
481
|
import type {
|
|
419
482
|
PosCreateCartBody,
|
|
420
483
|
PosCreateCartContent,
|
|
421
484
|
UserInfo,
|
|
422
|
-
TokenStorage
|
|
485
|
+
TokenStorage,
|
|
486
|
+
ApiResult
|
|
423
487
|
} from '@commercengine/pos';
|
|
424
488
|
|
|
425
489
|
// All API methods are fully typed
|
|
426
|
-
const cart: ApiResult<PosCreateCartContent> = await pos.
|
|
427
|
-
|
|
490
|
+
const cart: ApiResult<PosCreateCartContent> = await pos.createCart({
|
|
491
|
+
items: [
|
|
492
|
+
{
|
|
493
|
+
product_id: "01H9XYZ12345ABCDE",
|
|
494
|
+
variant_id: null,
|
|
495
|
+
quantity: 2
|
|
496
|
+
}
|
|
497
|
+
] // TypeScript validates this structure
|
|
428
498
|
});
|
|
429
499
|
```
|
|
430
500
|
|
|
@@ -464,7 +534,7 @@ const pos = new PosSDK({
|
|
|
464
534
|
Always check for error before accessing data:
|
|
465
535
|
|
|
466
536
|
```typescript
|
|
467
|
-
const { data, error, response } = await pos.
|
|
537
|
+
const { data, error, response } = await pos.getCart({ id: 'cart-123' });
|
|
468
538
|
|
|
469
539
|
if (error) {
|
|
470
540
|
if (response?.status === 404) {
|
|
@@ -488,7 +558,7 @@ const deviceId = localStorage.getItem('pos_device_id') || generateDeviceId();
|
|
|
488
558
|
localStorage.setItem('pos_device_id', deviceId);
|
|
489
559
|
|
|
490
560
|
// Use in all authentication calls
|
|
491
|
-
await pos.
|
|
561
|
+
await pos.loginWithEmail({
|
|
492
562
|
device_id: deviceId,
|
|
493
563
|
email: 'user@example.com'
|
|
494
564
|
});
|