# Publishing Instructions

## Prerequisites

1. **npm account**: Create one at https://www.npmjs.com/signup if you don't have one
2. **npm login**: Run `npm login` and enter your credentials

## Steps to Publish

### 1. Review Package Contents
```bash
npm pack --dry-run
```

This shows what will be published. Verify all necessary files are included.

### 2. Test the Package Locally (Optional but Recommended)

Create a test n8n installation and install your package locally:

```bash
npm pack
npm install -g n8n-nodes-schwab-0.1.0.tgz
```

Then restart n8n and test the node.

### 3. Publish to npm

```bash
npm publish
```

Or for first-time publication with public access:

```bash
npm publish --access public
```

### 4. Verify Publication

After publishing, check:
- Package page: https://www.npmjs.com/package/n8n-nodes-schwab
- Installation works: `npm install n8n-nodes-schwab`

## Version Updates

For future updates:

1. Make your changes
2. Update version in `package.json` (follow semver):
   - Patch (0.1.0 → 0.1.1): Bug fixes
   - Minor (0.1.0 → 0.2.0): New features, backward compatible
   - Major (0.1.0 → 1.0.0): Breaking changes

3. Rebuild:
```bash
npm run build
```

4. Publish:
```bash
npm publish
```

## Important Notes

### OAuth2 Setup for Users

Users will need to:
1. Register an app at https://developer.schwab.com/
2. Get Client ID and Client Secret
3. Complete OAuth2 flow to get authorization code
4. Enter credentials in n8n

### Package Structure

```
n8n-nodes-schwab/
├── dist/
│   ├── credentials/
│   │   └── SchwabApi.credentials.js
│   ├── nodes/
│   │   └── Schwab/
│   │       ├── Schwab.node.js
│   │       ├── schwab_openapi.json
│   │       └── schwab.svg
│   └── index.js
├── package.json
├── README.md
└── LICENSE
```

### n8n Community Nodes Documentation

After publishing, users can install with:

```bash
npm install n8n-nodes-schwab
```

Or via n8n UI:
- Settings → Community Nodes → Install
- Enter: `n8n-nodes-schwab`

## Troubleshooting

### Authentication Issues
The Schwab API uses OAuth2. Make sure your credentials setup includes:
- Proper token exchange implementation
- Token refresh logic
- Correct redirect URI

### Build Issues
If build fails:
```bash
# Clean and rebuild
rimraf dist
npm run build
```

### Publishing Errors

**Error: "You do not have permission to publish"**
- Make sure you're logged in: `npm whoami`
- Use `--access public` for first publication

**Error: "Package name too similar to existing package"**
- Choose a different package name in package.json

**Error: "Version already exists"**
- Bump the version number in package.json

## Support

For issues:
- GitHub Issues: [Your Repository URL]
- n8n Community: https://community.n8n.io/
- Schwab Developer: https://developer.schwab.com/

## Resources

- [n8n Community Nodes Docs](https://docs.n8n.io/integrations/community-nodes/)
- [npm Publishing Guide](https://docs.npmjs.com/creating-and-publishing-unscoped-public-packages)
- [Schwab API Documentation](https://developer.schwab.com/)
