{"_id":"@ecomdy/tiktok-sdk","name":"@ecomdy/tiktok-sdk","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@ecomdy/tiktok-sdk","version":"0.1.0","description":"Ecomdy TikTok Partner SDK for TypeScript/JavaScript - Business & Marketing API Integration","main":"dist/index.js","module":"dist/index.esm.js","types":"dist/index.d.ts","scripts":{"build":"tsc && rollup -c","dev":"tsc --watch","test":"jest","test:all":"node scripts/test-runner.js","test:watch":"jest --watch","test:coverage":"jest --coverage","lint":"eslint src/**/*.ts","typecheck":"tsc --noEmit","validate":"node scripts/validate.js","validate:partner":"node scripts/partner-onboarding.js","prepublishOnly":"npm run validate && npm run build"},"keywords":["tiktok","sdk","api","oauth","typescript","javascript"],"author":{"name":"Ecomdy Partners Team"},"license":"MIT","dependencies":{"axios":"^1.6.2"},"devDependencies":{"@types/jest":"^29.5.8","@types/node":"^20.9.0","@typescript-eslint/eslint-plugin":"^6.12.0","@typescript-eslint/parser":"^6.12.0","eslint":"^8.54.0","jest":"^29.7.0","rollup":"^4.6.1","rollup-plugin-typescript2":"^0.36.0","ts-jest":"^29.1.1","typescript":"^5.3.2"},"repository":{"type":"git","url":"git+https://github.com/ecomdy/tiktok-partner-sdk.git","directory":"packages/typescript-sdk"},"_id":"@ecomdy/tiktok-sdk@0.1.0","gitHead":"e4362d28808444d2b021717dfdcb2576d5ea842e","bugs":{"url":"https://github.com/ecomdy/tiktok-partner-sdk/issues"},"homepage":"https://github.com/ecomdy/tiktok-partner-sdk#readme","_nodeVersion":"20.19.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-QK7oXtpDEWouluCkX3EatAjtN5sm1+O7lSHuT16rLE3UR4ppn3XC4/ofRmhZXLra/MWpIrhaN1uRlfFrweJOYA==","shasum":"1fc265dac88df6255da927b6009560cc629c04f6","tarball":"https://registry.npmjs.org/@ecomdy/tiktok-sdk/-/tiktok-sdk-0.1.0.tgz","fileCount":81,"unpackedSize":542890,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDu00sWeu3fE7edx1jJXsyE0va+B6TQAddq9zsg9JubDAiBudtMhtndMqSFtEFnJ2sZmSvLNRGlYXQLVZH134HqwUg=="}]},"_npmUser":{"name":"tony_ecomdy","email":"tony@ecomdy.com"},"directories":{},"maintainers":[{"name":"tony_ecomdy","email":"tony@ecomdy.com"},{"name":"tonytinnguyen","email":"nguyenquangtin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tiktok-sdk_0.1.0_1767085022794_0.376081064930613"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-30T08:57:02.715Z","0.1.0":"2025-12-30T08:57:02.938Z","modified":"2025-12-30T08:57:03.228Z"},"maintainers":[{"name":"tony_ecomdy","email":"tony@ecomdy.com"},{"name":"tonytinnguyen","email":"nguyenquangtin@gmail.com"}],"description":"Ecomdy TikTok Partner SDK for TypeScript/JavaScript - Business & Marketing API Integration","homepage":"https://github.com/ecomdy/tiktok-partner-sdk#readme","keywords":["tiktok","sdk","api","oauth","typescript","javascript"],"repository":{"type":"git","url":"git+https://github.com/ecomdy/tiktok-partner-sdk.git","directory":"packages/typescript-sdk"},"author":{"name":"Ecomdy Partners Team"},"bugs":{"url":"https://github.com/ecomdy/tiktok-partner-sdk/issues"},"license":"MIT","readme":"# TikTok SDK for TypeScript/JavaScript\n\n> **MVP Version** - Minimal SDK for partner integration testing and validation\n\nA lightweight TypeScript/JavaScript SDK for integrating with TikTok's API platform. This MVP version focuses on core OAuth2 authentication and essential user/video endpoints for partner validation.\n\n## Features\n\n- ✅ OAuth2 authentication flow\n- ✅ Token management and refresh\n- ✅ User profile information\n- ✅ User videos listing\n- ✅ TypeScript support with full type definitions\n- ✅ Node.js and browser compatibility\n- ✅ Minimal dependencies (only axios)\n\n## Installation\n\n```bash\nnpm install @ecomdy/tiktok-sdk\n```\n\n## Quick Start\n\n### 1. Initialize the SDK\n\n```typescript\nimport { TikTokSDK } from '@ecomdy/tiktok-sdk';\n\nconst sdk = new TikTokSDK({\n  clientId: 'your_client_id',\n  clientSecret: 'your_client_secret',\n  redirectUri: 'https://your-app.com/callback',\n  scope: ['user.info.basic', 'video.list']\n});\n```\n\n### 2. OAuth2 Authentication\n\n```typescript\n// Generate authorization URL\nconst authUrl = sdk.oauth.getAuthorizationUrl('optional_state');\nconsole.log('Visit this URL:', authUrl);\n\n// Exchange authorization code for token (in your callback handler)\nconst tokenInfo = await sdk.oauth.getAccessToken(authorizationCode);\n\n// Set token for API calls\nsdk.setTokenInfo(tokenInfo);\n```\n\n### 3. Make API Calls\n\n```typescript\n// Get user information\nconst userInfo = await sdk.user.getCurrentUser();\nconsole.log('User:', userInfo.display_name);\n\n// Get user's videos\nconst videos = await sdk.video.getUserVideos({ max_count: 10 });\nconsole.log('Videos:', videos.videos.length);\n```\n\n## Configuration Options\n\n```typescript\ninterface TikTokSDKConfig {\n  // OAuth2 Configuration\n  clientId: string;          // Your app's client ID\n  clientSecret: string;      // Your app's client secret\n  redirectUri: string;       // OAuth callback URL\n  scope?: string[];          // Requested permissions\n\n  // API Configuration\n  accessToken?: string;      // Pre-existing access token\n  baseUrl?: string;          // API base URL (default: TikTok's API)\n  timeout?: number;          // Request timeout in ms (default: 30000)\n}\n```\n\n## Available Scopes\n\n- `user.info.basic` - Access basic user profile information\n- `video.list` - Access user's video list and details\n\n## API Reference\n\n### Authentication (`sdk.oauth`)\n\n```typescript\n// Generate authorization URL\ngetAuthorizationUrl(state?: string): string\n\n// Exchange code for access token\ngetAccessToken(code: string): Promise<TikTokTokenInfo>\n\n// Refresh access token\nrefreshAccessToken(refreshToken: string): Promise<TikTokTokenInfo>\n\n// Check if token is expired\nisTokenExpired(tokenInfo: TikTokTokenInfo): boolean\n```\n\n### User API (`sdk.user`)\n\n```typescript\n// Get current user information\ngetCurrentUser(fields?: string[]): Promise<TikTokUserInfo>\n```\n\n### Video API (`sdk.video`)\n\n```typescript\n// Get user's videos\ngetUserVideos(params?: TikTokQueryParams): Promise<TikTokVideosResponse>\n\n// Get specific video information\ngetVideoInfo(videoId: string, fields?: string[]): Promise<TikTokVideoInfo>\n```\n\n## Examples\n\n### Express.js Integration\n\n```typescript\nimport express from 'express';\nimport { TikTokSDK } from '@ecomdy/tiktok-sdk';\n\nconst app = express();\nconst sdk = new TikTokSDK({ /* config */ });\n\n// Start OAuth flow\napp.get('/auth', (req, res) => {\n  const authUrl = sdk.oauth.getAuthorizationUrl();\n  res.redirect(authUrl);\n});\n\n// Handle callback\napp.get('/callback', async (req, res) => {\n  const { code } = req.query;\n  const tokenInfo = await sdk.oauth.getAccessToken(code);\n\n  // Store tokenInfo in session/database\n  req.session.tokenInfo = tokenInfo;\n  res.redirect('/profile');\n});\n\n// Protected route\napp.get('/profile', async (req, res) => {\n  sdk.setTokenInfo(req.session.tokenInfo);\n  const userInfo = await sdk.user.getCurrentUser();\n  res.json(userInfo);\n});\n```\n\n### Next.js API Routes\n\n```typescript\n// pages/api/auth/callback.ts\nimport { TikTokSDK } from '@ecomdy/tiktok-sdk';\n\nexport default async function handler(req, res) {\n  const sdk = new TikTokSDK({ /* config */ });\n  const { code } = req.query;\n\n  try {\n    const tokenInfo = await sdk.oauth.getAccessToken(code);\n    // Store in session or return to client\n    res.json({ success: true, tokenInfo });\n  } catch (error) {\n    res.status(400).json({ error: error.message });\n  }\n}\n```\n\n### React Hook\n\n```typescript\nimport { useState, useEffect } from 'react';\nimport { TikTokSDK } from '@ecomdy/tiktok-sdk';\n\nexport function useTikTokUser(accessToken: string) {\n  const [user, setUser] = useState(null);\n  const [loading, setLoading] = useState(true);\n\n  useEffect(() => {\n    const sdk = new TikTokSDK({ accessToken });\n\n    sdk.user.getCurrentUser()\n      .then(setUser)\n      .finally(() => setLoading(false));\n  }, [accessToken]);\n\n  return { user, loading };\n}\n```\n\n## Error Handling\n\nThe SDK throws descriptive errors for common scenarios:\n\n```typescript\ntry {\n  const userInfo = await sdk.user.getCurrentUser();\n} catch (error) {\n  if (error.message.includes('Unauthorized')) {\n    // Token expired or invalid\n    // Redirect to re-authentication\n  } else if (error.message.includes('Rate limit')) {\n    // Handle rate limiting\n  } else {\n    // Handle other API errors\n  }\n}\n```\n\n## Token Management\n\n```typescript\n// Check if token is expired\nif (sdk.oauth.isTokenExpired(tokenInfo)) {\n  // Refresh token if available\n  if (tokenInfo.refreshToken) {\n    const newTokenInfo = await sdk.oauth.refreshAccessToken(tokenInfo.refreshToken);\n    sdk.setTokenInfo(newTokenInfo);\n  } else {\n    // Redirect to re-authentication\n  }\n}\n```\n\n## Requirements\n\n- Node.js 16+ or modern browser environment\n- TikTok Developer App with approved OAuth2 credentials\n\n## Getting TikTok API Access\n\n1. Create a TikTok Developer account at [developers.tiktok.com](https://developers.tiktok.com)\n2. Create a new app and configure OAuth2 settings\n3. Add your redirect URI to the app configuration\n4. Get your `client_id` and `client_secret`\n\n## Limitations (MVP Version)\n\n- Limited to basic user info and video listing endpoints\n- No file upload or content creation features\n- No webhook handling\n- No advanced error recovery or retry logic\n- No caching or offline support\n\n## TypeScript Support\n\nFull TypeScript definitions are included:\n\n```typescript\nimport {\n  TikTokSDK,\n  TikTokUserInfo,\n  TikTokVideoInfo,\n  TikTokTokenInfo,\n  TikTokOAuthConfig\n} from '@ecomdy/tiktok-sdk';\n```\n\n## Contributing\n\nThis is an MVP version for partner validation. For production features and improvements, please contact the TikTok Partners team.\n\n## License\n\nMIT\n\n## Support\n\n- GitHub Issues: [Report bugs and feature requests]\n- Partner Support: Contact your TikTok partner representative\n- Documentation: [API Documentation](https://developers.tiktok.com/doc)\n\n---\n\n**Note**: This is an MVP version designed for partner integration testing. Production-ready features, enhanced error handling, and additional endpoints will be added based on partner feedback.","readmeFilename":"README.md","_rev":"1-64945bbc06716c586611f97c8c0db2bc"}