{"_id":"@bradtjohnson1/asksage-token-generator","_rev":"2-08a9ce9bd0ae8b280a78d96900d2d8b1","name":"@bradtjohnson1/asksage-token-generator","dist-tags":{"latest":"1.2.0"},"versions":{"1.1.0":{"name":"@bradtjohnson1/asksage-token-generator","version":"1.1.0","keywords":["asksage","token","api","authentication","token-generator","ask-sage"],"author":{"name":"Bradley Johnson"},"license":"MIT","_id":"@bradtjohnson1/asksage-token-generator@1.1.0","maintainers":[{"name":"bradtjohnson1","email":"brad.johnson@inprov.ai"}],"homepage":"https://github.com/bradtjohnson1/Asksage-Utilities#readme","bugs":{"url":"https://github.com/bradtjohnson1/Asksage-Utilities/issues"},"bin":{"asksage-token":"asksage_token.js"},"dist":{"shasum":"4e0d66da2e6ce9ea60a8ef89fb677070be1dbfe2","tarball":"https://registry.npmjs.org/@bradtjohnson1/asksage-token-generator/-/asksage-token-generator-1.1.0.tgz","fileCount":5,"integrity":"sha512-rBW2S49XpC5qhV77gjP3zRAimZLnILBw9fvXTqaXirbYnPFzODcT5P8jyTFyRS/NUVtR4/TYYwMWvxydCLwZQw==","signatures":[{"sig":"MEUCIQCU18SN9IfU2QtlIPfEVXqF9j64MCU5wXwWvXBb7YpaSQIgTWZ2pLusTeZmFb0f7VHCTLPpSqXuuhbmSbGaSyCufjw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22836},"main":"asksage_token.js","engines":{"node":">=14.0.0"},"gitHead":"2b74c843a56db2e62030118f9467eb6d525fdcb5","scripts":{"test":"node asksage_token.js","setup":"node setup.js","start":"node asksage_token.js"},"_npmUser":{"name":"bradtjohnson1","email":"brad.johnson@inprov.ai"},"repository":{"url":"git+https://github.com/bradtjohnson1/Asksage-Utilities.git","type":"git","directory":"token-generator/javascript"},"_npmVersion":"10.8.2","description":"Secure utility for generating and managing Ask Sage API access tokens","directories":{},"_nodeVersion":"20.19.4","dependencies":{"axios":"^1.6.0"},"_hasShrinkwrap":false,"optionalDependencies":{"keytar":"^7.9.0"},"_npmOperationalInternal":{"tmp":"tmp/asksage-token-generator_1.1.0_1761868593498_0.20195111542873567","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@bradtjohnson1/asksage-token-generator","version":"1.2.0","description":"Secure utility for generating and managing Ask Sage API access tokens","main":"asksage_token.js","bin":{"asksage-token":"asksage_token.js"},"scripts":{"start":"node asksage_token.js","setup":"node setup.js","test":"node asksage_token.js"},"keywords":["asksage","token","api","authentication","token-generator","ask-sage"],"author":{"name":"Bradley Johnson"},"license":"MIT","dependencies":{"axios":"^1.6.0"},"optionalDependencies":{"keytar":"^7.9.0"},"engines":{"node":">=14.0.0"},"repository":{"type":"git","url":"git+https://github.com/bradtjohnson1/Asksage-Utilities.git","directory":"token-generator/javascript"},"bugs":{"url":"https://github.com/bradtjohnson1/Asksage-Utilities/issues"},"homepage":"https://github.com/bradtjohnson1/Asksage-Utilities#readme","_id":"@bradtjohnson1/asksage-token-generator@1.2.0","gitHead":"3677571f666edd87f1ae531784a5dfdc22d9c4fc","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-ZPCOvp5mH+3NNtt4oknh3hQChFWRt3mfsuwOAy8xM7Mqvi5KSWl+MPDlcPo1JLHg/6lx+jol02DFaypFMLQY9A==","shasum":"5244333450665f07a8e3f27fa9a2d9680c129860","tarball":"https://registry.npmjs.org/@bradtjohnson1/asksage-token-generator/-/asksage-token-generator-1.2.0.tgz","fileCount":5,"unpackedSize":23168,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHhTWJ6IyO8eCCG3ZaKSwH1oWE7OkX2Qw/8fL80qD0uEAiBDcV+FlpvuQKmnbN4aJhIX/a8pbM30v25AYbGg7uvpRw=="}]},"_npmUser":{"name":"bradtjohnson1","email":"brad.johnson@inprov.ai"},"directories":{},"maintainers":[{"name":"bradtjohnson1","email":"brad.johnson@inprov.ai"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/asksage-token-generator_1.2.0_1761933499875_0.9791169589446853"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-30T23:56:33.385Z","modified":"2025-10-31T17:58:20.266Z","1.1.0":"2025-10-30T23:56:33.716Z","1.2.0":"2025-10-31T17:58:20.063Z"},"bugs":{"url":"https://github.com/bradtjohnson1/Asksage-Utilities/issues"},"author":{"name":"Bradley Johnson"},"license":"MIT","homepage":"https://github.com/bradtjohnson1/Asksage-Utilities#readme","keywords":["asksage","token","api","authentication","token-generator","ask-sage"],"repository":{"type":"git","url":"git+https://github.com/bradtjohnson1/Asksage-Utilities.git","directory":"token-generator/javascript"},"description":"Secure utility for generating and managing Ask Sage API access tokens","maintainers":[{"name":"bradtjohnson1","email":"brad.johnson@inprov.ai"}],"readme":"# Ask Sage Token Generator (JavaScript/Node.js)\n\nA Node.js utility to generate and manage access tokens for the Ask Sage API.\n\n## Features\n\n- Interactive credential setup\n- Secure token storage (OS keychain or file-based)\n- Automatic token validation\n- Token caching with 65-minute expiration (1 hour 5 minutes)\n- Easy integration with other JavaScript applications\n\n## Prerequisites\n\n- Node.js 14.0.0 or higher\n- npm (comes with Node.js)\n- Ask Sage account with API key\n\n---\n\n## Quick Start\n\n### Installation & Setup\n\n#### Option 1: Automated Setup (Windows)\n```bash\nsetup.bat\n```\nThis will:\n- Check Node.js installation\n- Install npm dependencies\n- Show instructions to run `npm start`\n\n#### Option 2: Automated Setup (Linux/macOS/Node.js)\n```bash\nnode setup.js\n```\nThis will:\n- Check Node.js version\n- Install npm dependencies\n- Show instructions to run `npm start`\n\n#### Option 3: Manual Setup\n```bash\nnpm install\n```\n\n### Generate a Token\n\n```bash\nnpm start\n```\n\nThe script will:\n1. Ask for your Ask Sage email\n2. Ask for your Ask Sage API key\n3. Save credentials to `credentials.json`\n4. Request token from Ask Sage API\n5. Validate the token\n6. Save token securely (OS keychain or file)\n7. Create `asksage_config.json`\n\n### Regenerate Token (credentials already saved)\n\n```bash\nnpm start\n```\nThe script will use your saved credentials automatically.\n\n---\n\n## Getting Your API Key\n\n1. Go to https://asksage.ai\n2. Log in to your account\n3. Navigate to Account Settings\n4. Click \"Manage your API keys\"\n5. Create a new API key or copy an existing one\n\n---\n\n## Using the Token\n\n### In API Requests\n\n```javascript\nconst axios = require('axios');\n\nconst headers = {\n  'x-access-tokens': 'your_token_here',\n  'Content-Type': 'application/json'\n};\n\nconst response = await axios.post(\n  'https://api.asksage.ai/server/get-models',\n  {},\n  { headers }\n);\n```\n\n### As a Module in Your Code\n\n```javascript\nconst { getStoredToken, getToken } = require('./asksage_token');\n\n// Get stored token\nconst token = await getStoredToken('your.email@example.com');\n\n// Or generate new token\nconst newToken = await getToken('your.email@example.com', 'your_api_key');\n```\n\n### Using Environment Variable\n\nThe script sets the `ASK_SAGE_TOKEN` environment variable for the current session:\n\n```javascript\nconst token = process.env.ASK_SAGE_TOKEN;\n```\n\n---\n\n## Files Created\n\nAfter running the token generator:\n- `credentials.json` - Your email and API key (gitignored)\n- `asksage_config.json` - Config with metadata (gitignored)\n- `~/asksage_token.txt` - Token file (if keytar not available)\n\n## File Structure\n\n```\njavascript/\n├── asksage_token.js           # Main token generator script\n├── package.json               # npm package configuration\n├── setup.bat                  # Windows setup script\n├── setup.js                   # Cross-platform setup script\n├── credentials.json.example   # Example credentials file\n├── asksage_config.json.example # Example config file\n├── .gitignore                 # Git ignore rules\n└── README.md                  # This file\n```\n\n---\n\n## Security\n\n### Token Storage\n\nThe script uses multiple security layers:\n\n1. **OS Keychain (Preferred)**: If `keytar` is installed, tokens are stored in your operating system's credential manager:\n   - macOS: Keychain\n   - Windows: Credential Vault\n   - Linux: Secret Service API/libsecret\n\n2. **File-based (Fallback)**: Tokens are stored in `~/asksage_token.txt` with restricted permissions (600)\n\n### Installing Keytar (Optional but Recommended)\n\nFor enhanced security with OS keychain storage:\n\n```bash\nnpm install keytar\n```\n\n**Note**: keytar requires native build tools on some systems. If installation fails, the script will fall back to file-based storage.\n\n### Best Practices\n\n- Never commit `credentials.json` to version control\n- Keep your API key secure\n- Tokens expire after 65 minutes (1 hour 5 minutes)\n- Use environment variables in production\n\n---\n\n## Token Expiration\n\nAsk Sage tokens expire after 65 minutes (1 hour 5 minutes). When your token expires:\n1. Run `npm start` again to generate a new token\n2. The script will automatically test the new token\n3. Your credentials remain saved for easy regeneration\n\n---\n\n## Troubleshooting\n\n### \"Node.js not found\"\nInstall Node.js 14.0.0 or higher from https://nodejs.org\n\n### \"Authentication failed\"\n- Verify your email and API key in `credentials.json`\n- Ensure your API key is active and has the correct permissions\n\n### \"keytar not available\"\n- This is normal if keytar isn't installed\n- The script will use file-based storage instead\n- To install keytar (optional): `npm install keytar`\n\n### \"Permission denied\"\n- On Unix systems: Ensure you have write permissions to your home directory\n- On Windows: Run as administrator if needed\n\n### \"Request timed out\"\n- Check your internet connection\n- Verify the API endpoints are accessible\n\n---\n\n## Support\n\nFor issues or questions:\n- Check the main README in the parent directory\n- Visit https://asksage.ai for API documentation\n- Contact Ask Sage support\n\n## License\n\nMIT\n","readmeFilename":"README.md"}