# Publishing @buzztrail-ai/engage v1.0.0

## Pre-Publishing Checklist

✅ **All checks passed - Ready to publish!**

- ✅ Package built successfully
- ✅ Bundle size verified: 30.17 KB (8.59 KB gzipped) - Under 15KB Wix limit
- ✅ package.json updated to v1.0.0
- ✅ .npmignore configured (security)
- ✅ README.md publish-ready
- ✅ CHANGELOG.md created
- ✅ TypeScript declarations generated
- ✅ All entry points configured correctly
- ✅ Dry run successful (10 files, 152.8 KB tarball)

## Package Contents

```
dist/libs/engage-package/
├── buzztrail.min.js (30.2 KB) + .map (167.1 KB)
├── buzztrail.esm.js (53.2 KB) + .map (169.2 KB)
├── buzztrail.umd.js (30.4 KB) + .map (167.1 KB)
├── index.d.ts (5.1 KB)
├── package.json (1.9 KB)
├── README.md (11.4 KB)
└── CHANGELOG.md (3.2 KB)

Total: 10 files, 638.6 KB unpacked, 152.8 KB tarball
```

## Publishing Steps

### 1. Login to npm

```bash
npm login
```

**Credentials needed**:
- Username: (buzztrail-ai org member)
- Password: (your npm password)
- Email: (your email)
- 2FA: (if enabled)

**Verify login**:
```bash
npm whoami
# Should return your username
```

### 2. Verify Organization Access

```bash
npm org ls buzztrail-ai
# Should show you're a member
```

If not a member, request access from organization admin.

### 3. Publish to npm

```bash
cd dist/libs/engage-package
npm publish --access public
```

**Expected output**:
```
+ @buzztrail-ai/engage@1.0.0
```

### 4. Verify Publication

```bash
npm view @buzztrail-ai/engage
```

Check:
- Version shows 1.0.0
- All metadata correct
- Files list matches expectations

## CDN Verification (Wait 5-10 minutes)

### jsDelivr (Primary CDN)

**URLs to test**:
```
https://cdn.jsdelivr.net/npm/@buzztrail-ai/engage@1.0.0/buzztrail.min.js
https://cdn.jsdelivr.net/npm/@buzztrail-ai/engage@latest/buzztrail.min.js
```

**Test in browser console**:
```javascript
// Load from CDN
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/@buzztrail-ai/engage@latest/buzztrail.min.js';
script.onload = () => console.log('Loaded! BuzzTrailAPI available:', typeof BuzzTrailAPI);
script.onerror = () => console.error('Failed to load');
document.head.appendChild(script);
```

### unpkg (Fallback CDN)

**URLs to test**:
```
https://unpkg.com/@buzztrail-ai/engage@1.0.0/buzztrail.min.js
https://unpkg.com/@buzztrail-ai/engage@latest/buzztrail.min.js
```

## Post-Publishing Tasks

### 1. Create Git Tag

```bash
cd /Users/lars/mycode/buzztrail/extension
git tag -a v1.0.0 -m "Release v1.0.0: Initial npm publication"
git push origin v1.0.0
```

### 2. Document CDN Verification

Create `libs/engage-package/docs/CDN_VERIFICATION.md` with test results:
- jsDelivr load times
- unpkg load times
- File sizes
- Browser compatibility tests

### 3. Update Context Documentation

Update `.claude/context/progress.md`:
- Mark Issue #174 as completed
- Document package availability
- Note CDN URLs

### 4. Update Epic Status

Update `.claude/epics/universal-npm-package-cdn-distribution/epic.md`:
- Increment progress percentage
- Mark publishing milestone complete

### 5. Close GitHub Issue

```bash
gh issue close 174 --comment "✅ Package published to npm as @buzztrail-ai/engage@1.0.0

Available via:
- npm: npm install @buzztrail-ai/engage
- jsDelivr: https://cdn.jsdelivr.net/npm/@buzztrail-ai/engage@latest/buzztrail.min.js
- unpkg: https://unpkg.com/@buzztrail-ai/engage@latest/buzztrail.min.js

Bundle size: 8.59 KB gzipped (under 15KB Wix limit)"
```

## Rollback Procedure

If issues are discovered after publishing:

### Within 24 hours (Unpublish)

```bash
npm unpublish @buzztrail-ai/engage@1.0.0
```

**WARNING**: Only works within 24 hours of publishing!

### After 24 hours (Deprecate + Patch)

```bash
# Mark broken version as deprecated
npm deprecate @buzztrail-ai/engage@1.0.0 "Broken, use 1.0.1"

# Publish fixed version
# (fix issues in code, bump to 1.0.1)
cd dist/libs/engage-package
npm publish --access public
```

## Troubleshooting

### "need auth" error
**Solution**: Run `npm login` and authenticate

### "403 Forbidden" error
**Solution**: Ensure you're a member of @buzztrail-ai organization

### "402 Payment Required" error
**Solution**: Organization needs active npm Teams subscription

### "package already exists" error
**Solution**: Version 1.0.0 already published, bump to 1.0.1

### CDN not syncing
**Solution**:
- Wait 10-15 minutes (can take time)
- Try purging cache: https://www.jsdelivr.com/tools/purge
- Check npm registry: `npm view @buzztrail-ai/engage`

## Success Criteria

- [ ] npm publish successful (v1.0.0 visible)
- [ ] jsDelivr CDN serving files (5-10 min after publish)
- [ ] unpkg CDN serving files (5-10 min after publish)
- [ ] @latest alias working on both CDNs
- [ ] Bundle loads in browser console test
- [ ] File sizes confirmed <15KB gzipped
- [ ] Git tag created (v1.0.0)
- [ ] Documentation updated
- [ ] GitHub issue closed

## Next Steps After Publishing

1. **Integration with Edge Function** (Issue #175)
   - Get Supabase anon key from dashboard
   - Update package to call Edge Function
   - Test domain validation

2. **Production Wix Testing**
   - Update buzztrail.ai/norsk-unloc to use CDN script
   - Test full workflow
   - Monitor for issues

3. **Plan v1.1.0 Enhancements**
   - Collect user feedback
   - Address any issues discovered
   - Plan feature additions

## Contact

For npm organization access or issues:
- Organization: @buzztrail-ai
- Email: noreply@buzztrail.ai
- GitHub: https://github.com/buzztrail-ai/engage-package
