{"_id":"@eetech-commerce/cart-sdk","name":"@eetech-commerce/cart-sdk","dist-tags":{"latest":"0.3.4"},"versions":{"0.3.4":{"name":"@eetech-commerce/cart-sdk","version":"0.3.4","description":"Type-safe Next.js SDK for Cart-Checkout API","type":"module","main":"./nextjs/index.ts","types":"./nextjs/index.ts","exports":{".":"./nextjs/index.ts","./types":"./nextjs/types.gen.ts","./client":"./nextjs/client.gen.ts"},"repository":{"type":"git","url":"git+https://github.com/eetech-group/eetech-cart.git","directory":"sdk"},"license":"MIT","publishConfig":{"access":"public"},"keywords":["cart","checkout","api","sdk","nextjs","typescript"],"dependencies":{"@tanstack/react-query":"^5.90.10"},"peerDependencies":{"next":">=14.0.0","react":">=18.0.0"},"_id":"@eetech-commerce/cart-sdk@0.3.4","gitHead":"fef6664c361442502c51664211427d8784a1da48","bugs":{"url":"https://github.com/eetech-group/eetech-cart/issues"},"homepage":"https://github.com/eetech-group/eetech-cart#readme","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-g7sCKN3OsSMOywK7Iyvw3KqC+CQkZYOfeI3GaLyXlHWBDgosCsDMusy/i85aJ3u1X8t/MZHbkMBTtjdQ07TYSw==","shasum":"0d20e7a272b1b49f7979747ddd447d1675e84864","tarball":"https://registry.npmjs.org/@eetech-commerce/cart-sdk/-/cart-sdk-0.3.4.tgz","fileCount":21,"unpackedSize":142350,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBrIv7rCek/gFMH4nMVgI21E6+gUhekoJ3U+10Wvs1HLAiAPOhmhDSst35XBx8EArVXJfqcwJyT+wF/kgrmMUGuQvQ=="}]},"_npmUser":{"name":"paolo-eetech","email":"paolo@marketpush.com"},"directories":{},"maintainers":[{"name":"paolo-eetech","email":"paolo@marketpush.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cart-sdk_0.3.4_1769139290836_0.6277917770794934"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-23T03:34:50.717Z","0.3.4":"2026-01-23T03:34:50.992Z","modified":"2026-01-23T03:34:51.250Z"},"maintainers":[{"name":"paolo-eetech","email":"paolo@marketpush.com"}],"description":"Type-safe Next.js SDK for Cart-Checkout API","homepage":"https://github.com/eetech-group/eetech-cart#readme","keywords":["cart","checkout","api","sdk","nextjs","typescript"],"repository":{"type":"git","url":"git+https://github.com/eetech-group/eetech-cart.git","directory":"sdk"},"bugs":{"url":"https://github.com/eetech-group/eetech-cart/issues"},"license":"MIT","readme":"# Cart-Checkout API SDK\n\nThis directory contains generated TypeScript SDKs for the Cart-Checkout API.\n\n## NextJS SDK\n\nThe NextJS SDK is located in `./nextjs` and provides type-safe API client functions optimized for Next.js applications.\n\n### Generating the SDK\n\nThe SDK is generated from the OpenAPI specification served by the running API server:\n\n```bash\n# Make sure the API server is running on http://localhost:3001\nbun run start:dev\n\n# In another terminal, generate the SDK\nbun run sdk:generate\n```\n\n### Configuration\n\nSDK generation is configured in `openapi-ts.config.ts` at the project root. It:\n- Fetches the OpenAPI spec from `http://localhost:3001/api/docs-json`\n- Generates type-safe Next.js client code\n- Outputs to `./sdk/nextjs`\n- Applies Biome linting and Prettier formatting\n\n### Usage in Next.js Applications\n\nThe SDK comes with **built-in runtime configuration** that automatically reads from environment variables.\n\n#### Step 1: Install the SDK in Your Next.js Project\n\n```bash\n# Option A: If using a monorepo with workspaces\n# Add to your Next.js package.json:\n{\n  \"dependencies\": {\n    \"@mp/cart-sdk\": \"workspace:*\"  // or \"file:../mp_cart/sdk/nextjs\"\n  }\n}\n\n# Option B: Direct file reference\nnpm install file:../mp_cart/sdk/nextjs\n```\n\n#### Step 2: Set Environment Variables\n\nCreate or update your `.env.local` file in your Next.js project:\n\n```bash\n# .env.local\nNEXT_PUBLIC_CART_API_BASE_URL=http://localhost:3001\nCART_API_KEY=your-api-key-here\n```\n\n**That's it!** The SDK will automatically use these environment variables.\n\n#### Step 3: Use the SDK\n\n```typescript\n// app/page.tsx or any component\nimport { getHealth, createCart, addItem } from '@mp/cart-sdk';\n\nexport default async function Page() {\n  // No configuration needed - automatically uses env vars!\n  const health = await getHealth();\n\n  return <div>API Status: {health.data?.status}</div>;\n}\n```\n\n#### Advanced: Customizing Runtime Config\n\nIf you need to customize the configuration logic (e.g., different env var names, custom headers, timeout settings), edit `sdk/config.ts`:\n\n```typescript\n// sdk/config.ts\nexport const createClientConfig: CreateClientConfig = (config) => ({\n  ...config,\n  baseUrl: process.env.NEXT_PUBLIC_CART_API_BASE_URL || 'http://localhost:3001',\n  headers: {\n    'X-API-Key': process.env.CART_API_KEY || '',\n    // Add custom headers here\n  },\n  // Add other fetch options\n  // timeout: 30000,\n  // credentials: 'include',\n});\n```\n\nThen regenerate the SDK:\n\n```bash\nbun run sdk:generate\n```\n\n**Note:** The `sdk/config.ts` file is **not** regenerated, so your changes persist. Only the `sdk/nextjs/` directory gets regenerated.\n\n### Generated Files\n\n- `index.ts` - Main entry point, exports types and SDK functions\n- `sdk.gen.ts` - All API endpoint functions\n- `types.gen.ts` - TypeScript type definitions for requests/responses\n- `client.gen.ts` - HTTP client configuration\n- `transformers.gen.ts` - Data transformation utilities\n- `core/` - Core utilities for serialization, auth, etc.\n- `client/` - Next.js specific client implementation\n\n### Type Safety\n\nAll API calls are fully type-safe:\n\n```typescript\nimport type { CreateCartDto, AddItemDto } from '@/sdk/nextjs';\n\n// TypeScript will enforce correct request structure\nconst cart: CreateCartDto = {\n  currency: 'USD', // Required\n  metadata: {}, // Optional\n};\n```\n\n### Error Handling\n\n```typescript\ntry {\n  const result = await getCart({\n    path: { cartSessionId: 'abc123' },\n  });\n\n  if (result.error) {\n    console.error('API Error:', result.error);\n  } else {\n    console.log('Cart:', result.data);\n  }\n} catch (error) {\n  console.error('Network error:', error);\n}\n```\n\n## Regenerating After API Changes\n\nWhenever you make changes to the API (controllers, DTOs, routes):\n\n1. Ensure your changes are reflected in the Swagger documentation\n2. Start the development server if not already running\n3. Run `bun run sdk:generate` to regenerate the SDK\n4. The generated files in `sdk/nextjs` will be updated automatically\n\n## Notes\n\n- The `sdk/nextjs` directory is gitignored and should be regenerated as needed\n- Always regenerate the SDK after API changes to maintain type safety\n- The SDK uses the Next.js fetch implementation under the hood\n","readmeFilename":"README.md","_rev":"1-56c8c8ed96516fc5505d2ef8a8f6c09d"}