@insure-os/client 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CDN_SETUP.md ADDED
@@ -0,0 +1,332 @@
1
+ # CDN Deployment Setup
2
+
3
+ This document explains how to deploy the InsureOS embeddable script to Cloudflare R2 CDN.
4
+
5
+ ## Prerequisites
6
+
7
+ 1. **Cloudflare R2 Bucket**: Already set up at `cdn.os.insure`
8
+ 2. **R2 API Credentials**: Generate from Cloudflare dashboard
9
+ 3. **Node.js**: v18 or higher
10
+ 4. **pnpm**: Package manager used in this monorepo
11
+
12
+ ## Initial Setup
13
+
14
+ ### 1. Generate R2 API Credentials
15
+
16
+ 1. Log in to Cloudflare Dashboard
17
+ 2. Navigate to **R2** > **Overview**
18
+ 3. Click **Manage R2 API Tokens**
19
+ 4. Click **Create API Token**
20
+ 5. Configure the token:
21
+ - **Token name**: `insureos-cdn-deploy`
22
+ - **Permissions**: Object Read & Write
23
+ - **TTL**: Never expire (or set appropriate expiry)
24
+ - **Bucket**: `insure-os` (or apply to all buckets)
25
+ 6. Copy the **Access Key ID** and **Secret Access Key**
26
+
27
+ ### 2. Configure Environment Variables
28
+
29
+ Create a `.env` file in `packages/client`:
30
+
31
+ ```bash
32
+ cp .env.example .env
33
+ ```
34
+
35
+ Edit `.env` and add your credentials:
36
+
37
+ ```bash
38
+ R2_ACCESS_KEY_ID=your_access_key_id_here
39
+ R2_SECRET_ACCESS_KEY=your_secret_access_key_here
40
+ R2_BUCKET_NAME=insure-os
41
+ CDN_DOMAIN=cdn.os.insure
42
+ ```
43
+
44
+ **Important**: Never commit `.env` to version control!
45
+
46
+ ### 3. Configure R2 Bucket (One-time setup)
47
+
48
+ #### Enable Public Access via Custom Domain
49
+
50
+ 1. In Cloudflare Dashboard, go to **R2** > **Buckets** > `insure-os`
51
+ 2. Click **Settings** tab
52
+ 3. Under **Custom Domains**, click **Connect Domain**
53
+ 4. Enter `cdn.os.insure` and complete the setup
54
+ 5. Cloudflare will automatically configure DNS and SSL
55
+
56
+ #### Configure CORS (Optional but recommended)
57
+
58
+ If you need to support older browsers or specific CORS requirements:
59
+
60
+ 1. In the bucket settings, find **CORS Policy**
61
+ 2. Add the following configuration:
62
+
63
+ ```json
64
+ [
65
+ {
66
+ "AllowedOrigins": ["*"],
67
+ "AllowedMethods": ["GET", "HEAD"],
68
+ "AllowedHeaders": ["*"],
69
+ "ExposeHeaders": ["ETag"],
70
+ "MaxAgeSeconds": 3600
71
+ }
72
+ ]
73
+ ```
74
+
75
+ ### 4. Install Dependencies
76
+
77
+ ```bash
78
+ cd packages/client
79
+ pnpm install
80
+ ```
81
+
82
+ ## Deployment Commands
83
+
84
+ ### Build for Production
85
+
86
+ ```bash
87
+ pnpm build:prod
88
+ ```
89
+
90
+ This creates optimized bundles in `dist/`:
91
+ - `index.umd.js` - Universal module for CDN (used for deployment)
92
+ - `index.esm.js` - ES module format
93
+ - `index.cjs` - CommonJS format
94
+ - Type definitions and source maps
95
+
96
+ ### Deploy to CDN
97
+
98
+ ```bash
99
+ # Option 1: Build and deploy separately
100
+ pnpm build:prod
101
+ pnpm publish:cdn
102
+
103
+ # Option 2: Build and deploy in one command
104
+ pnpm release:cdn
105
+
106
+ # Option 3: Bump version, build, and deploy
107
+ pnpm release # Bumps patch version (0.0.0 -> 0.0.1)
108
+ ```
109
+
110
+ ### Version Management
111
+
112
+ Use standard npm versioning:
113
+
114
+ ```bash
115
+ npm version patch # 0.0.1 -> 0.0.2
116
+ npm version minor # 0.0.2 -> 0.1.0
117
+ npm version major # 0.1.0 -> 1.0.0
118
+ ```
119
+
120
+ ## CDN Structure
121
+
122
+ Files are uploaded to multiple paths with different caching strategies:
123
+
124
+ ```
125
+ cdn.os.insure/
126
+ ├── v0.0.1/
127
+ │ ├── insureos.min.js # Immutable, cached forever
128
+ │ ├── insureos.min.js.map # Source map
129
+ │ └── metadata.json # Version info + SRI hash
130
+ ├── v0/
131
+ │ ├── insureos.min.js # Auto-updates with v0.x.x releases (1hr cache)
132
+ │ └── insureos.min.js.map
133
+ └── latest/
134
+ ├── insureos.min.js # Always latest stable (5min cache)
135
+ └── insureos.min.js.map
136
+ ```
137
+
138
+ ## Usage Examples
139
+
140
+ ### For Production (Recommended)
141
+
142
+ Use immutable versioned URLs with SRI integrity:
143
+
144
+ ```html
145
+ <script
146
+ src="https://cdn.os.insure/v0.0.1/insureos.min.js"
147
+ integrity="sha384-[generated-hash]"
148
+ crossorigin="anonymous">
149
+ </script>
150
+ ```
151
+
152
+ The deployment script will output the exact snippet with the correct SRI hash.
153
+
154
+ ### For Development
155
+
156
+ Use the auto-updating major version:
157
+
158
+ ```html
159
+ <script src="https://cdn.os.insure/v0/insureos.min.js"></script>
160
+ ```
161
+
162
+ ### For Testing Latest
163
+
164
+ Use the latest channel (not recommended for production):
165
+
166
+ ```html
167
+ <script src="https://cdn.os.insure/latest/insureos.min.js"></script>
168
+ ```
169
+
170
+ ## Integration Example
171
+
172
+ After loading the script, initialize InsureOS:
173
+
174
+ ```html
175
+ <!DOCTYPE html>
176
+ <html>
177
+ <head>
178
+ <title>Insurance Quote</title>
179
+ <script
180
+ src="https://cdn.os.insure/v0.0.1/insureos.min.js"
181
+ integrity="sha384-..."
182
+ crossorigin="anonymous">
183
+ </script>
184
+ </head>
185
+ <body>
186
+ <div id="insureos-container"></div>
187
+
188
+ <script>
189
+ const client = new InsureOSScripts.InsureOS({
190
+ apiKey: 'your-api-key',
191
+ environment: 'production',
192
+ });
193
+
194
+ client.mount('#insureos-container', {
195
+ quoteIntentId: 'your-quote-intent-id',
196
+ // Additional configuration...
197
+ });
198
+ </script>
199
+ </body>
200
+ </html>
201
+ ```
202
+
203
+ ## CI/CD Integration
204
+
205
+ ### GitHub Actions Example
206
+
207
+ Create `.github/workflows/deploy-cdn.yml`:
208
+
209
+ ```yaml
210
+ name: Deploy to CDN
211
+
212
+ on:
213
+ release:
214
+ types: [published]
215
+
216
+ jobs:
217
+ deploy:
218
+ runs-on: ubuntu-latest
219
+ steps:
220
+ - uses: actions/checkout@v4
221
+
222
+ - uses: pnpm/action-setup@v2
223
+ with:
224
+ version: 8
225
+
226
+ - uses: actions/setup-node@v4
227
+ with:
228
+ node-version: 18
229
+ cache: 'pnpm'
230
+
231
+ - name: Install dependencies
232
+ run: pnpm install
233
+
234
+ - name: Build and deploy
235
+ env:
236
+ R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
237
+ R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
238
+ R2_BUCKET_NAME: insure-os
239
+ CDN_DOMAIN: cdn.os.insure
240
+ run: |
241
+ cd packages/client
242
+ pnpm release:cdn
243
+ ```
244
+
245
+ Add secrets to GitHub:
246
+ - Settings > Secrets > Actions
247
+ - Add `R2_ACCESS_KEY_ID` and `R2_SECRET_ACCESS_KEY`
248
+
249
+ ## Troubleshooting
250
+
251
+ ### Upload Fails
252
+
253
+ **Problem**: `AccessDenied` error
254
+
255
+ **Solution**:
256
+ - Verify R2 API token has read/write permissions
257
+ - Check bucket name is correct (`insure-os`)
258
+ - Ensure token hasn't expired
259
+
260
+ ### CDN URL Not Accessible
261
+
262
+ **Problem**: `404` or SSL errors when accessing `cdn.os.insure`
263
+
264
+ **Solution**:
265
+ - Verify custom domain is properly connected in R2 settings
266
+ - Check DNS records are propagating (may take a few minutes)
267
+ - Ensure bucket has files uploaded
268
+
269
+ ### CORS Errors in Browser
270
+
271
+ **Problem**: Browser blocks script loading due to CORS
272
+
273
+ **Solution**:
274
+ - Add CORS policy to bucket (see setup section)
275
+ - Verify `crossorigin="anonymous"` attribute is present in script tag
276
+
277
+ ### SRI Integrity Check Fails
278
+
279
+ **Problem**: Browser refuses to execute script due to SRI mismatch
280
+
281
+ **Solution**:
282
+ - Always use the SRI hash output by the deployment script
283
+ - Don't manually edit the deployed files
284
+ - Clear CDN cache if you re-deployed the same version
285
+
286
+ ## Monitoring
287
+
288
+ ### Check Deployed Version
289
+
290
+ ```bash
291
+ curl https://cdn.os.insure/v0.0.1/metadata.json
292
+ ```
293
+
294
+ Returns:
295
+
296
+ ```json
297
+ {
298
+ "version": "0.0.1",
299
+ "timestamp": "2025-10-02T10:30:00.000Z",
300
+ "sri": "sha384-...",
301
+ "urls": {
302
+ "immutable": "https://cdn.os.insure/v0.0.1/insureos.min.js",
303
+ "major": "https://cdn.os.insure/v0/insureos.min.js",
304
+ "latest": "https://cdn.os.insure/latest/insureos.min.js"
305
+ },
306
+ "size": {
307
+ "original": 190240,
308
+ "gzipped": 55281
309
+ }
310
+ }
311
+ ```
312
+
313
+ ### Monitor Usage
314
+
315
+ Use Cloudflare Analytics:
316
+ 1. R2 Dashboard > `insure-os` bucket
317
+ 2. View request metrics, bandwidth, and storage
318
+
319
+ ## Security Best Practices
320
+
321
+ 1. **Use SRI hashes** for production deployments
322
+ 2. **Pin specific versions** rather than using `latest`
323
+ 3. **Rotate API tokens** periodically
324
+ 4. **Monitor bucket access** via Cloudflare logs
325
+ 5. **Keep credentials secure** - never commit `.env` files
326
+
327
+ ## Support
328
+
329
+ For issues or questions:
330
+ - Check Cloudflare R2 documentation
331
+ - Review deployment script output for errors
332
+ - Contact DevOps team for access issues
package/DEPLOYMENT.md ADDED
@@ -0,0 +1,192 @@
1
+ # Quick Deployment Reference
2
+
3
+ ## 🚀 Deploy New Version
4
+
5
+ ### Simple One-Command Deploy (CDN + NPM)
6
+
7
+ ```bash
8
+ pnpm release
9
+ ```
10
+
11
+ This will:
12
+ 1. Bump patch version (0.0.0 → 0.0.1)
13
+ 2. Build production bundle
14
+ 3. Upload to CDN (cdn.os.insure)
15
+ 4. Publish to NPM (@insure-os/scripts)
16
+
17
+ ### Deploy to Specific Destinations
18
+
19
+ ```bash
20
+ # CDN only
21
+ pnpm release:cdn
22
+
23
+ # NPM only
24
+ pnpm release:npm
25
+
26
+ # Both (no version bump)
27
+ pnpm release:all
28
+ ```
29
+
30
+ ### Manual Version Control
31
+
32
+ ```bash
33
+ # Choose version bump type
34
+ npm version patch # Bug fixes: 0.0.1 → 0.0.2
35
+ npm version minor # New features: 0.1.0 → 0.2.0
36
+ npm version major # Breaking changes: 1.0.0 → 2.0.0
37
+
38
+ # Then deploy to both
39
+ pnpm release:all
40
+ ```
41
+
42
+ ### Build Only (No Deploy)
43
+
44
+ ```bash
45
+ pnpm build:prod
46
+ ```
47
+
48
+ ### Individual Publish Commands
49
+
50
+ ```bash
51
+ # CDN
52
+ pnpm publish:cdn
53
+
54
+ # NPM (test first!)
55
+ pnpm publish:npm:dry # Dry-run
56
+ pnpm publish:npm # Actual publish
57
+ ```
58
+
59
+ ## 📦 What Gets Deployed
60
+
61
+ Every deployment uploads to **3 different paths**:
62
+
63
+ | Path | Cache | Purpose |
64
+ |------|-------|---------|
65
+ | `v0.0.1/insureos.min.js` | Forever | **Production** - Immutable, use with SRI |
66
+ | `v0/insureos.min.js` | 1 hour | **Auto-update** - Gets latest v0.x.x |
67
+ | `latest/insureos.min.js` | 5 min | **Testing** - Always newest |
68
+
69
+ ## 🔗 URLs After Deployment
70
+
71
+ Base URL: `https://cdn.os.insure`
72
+
73
+ ```
74
+ https://cdn.os.insure/v0.0.1/insureos.min.js ← Specific version
75
+ https://cdn.os.insure/v0.0.1/insureos.min.js.map ← Source map
76
+ https://cdn.os.insure/v0.0.1/metadata.json ← Version info + SRI
77
+
78
+ https://cdn.os.insure/v0/insureos.min.js ← Auto-updating v0
79
+ https://cdn.os.insure/latest/insureos.min.js ← Latest release
80
+ ```
81
+
82
+ ## ✅ Verify Deployment
83
+
84
+ ```bash
85
+ # Check deployed version
86
+ curl https://cdn.os.insure/v0.0.1/metadata.json
87
+
88
+ # Test in browser
89
+ open https://cdn.os.insure/v0.0.1/insureos.min.js
90
+
91
+ # Check all versions
92
+ curl https://cdn.os.insure/latest/metadata.json
93
+ ```
94
+
95
+ ## 📋 After Deployment Checklist
96
+
97
+ - [ ] Copy the SRI hash from deployment output
98
+ - [ ] Update customer documentation with new version
99
+ - [ ] Test the script in a sample HTML page
100
+ - [ ] Update any example code with new version number
101
+ - [ ] Notify customers if breaking changes in major version
102
+
103
+ ## 🔧 Troubleshooting
104
+
105
+ ### Build fails
106
+ ```bash
107
+ # Clean and rebuild
108
+ pnpm clean
109
+ pnpm install
110
+ pnpm build:prod
111
+ ```
112
+
113
+ ### Upload fails
114
+ ```bash
115
+ # Check environment variables
116
+ cat .env
117
+
118
+ # Verify R2 credentials are correct
119
+ # - R2_ACCESS_KEY_ID (32 characters)
120
+ # - R2_SECRET_ACCESS_KEY (64 characters)
121
+ ```
122
+
123
+ ### CDN not accessible
124
+ - Wait 1-2 minutes for DNS propagation
125
+ - Check Cloudflare R2 bucket has public custom domain enabled
126
+ - Verify `cdn.os.insure` is properly configured in Cloudflare
127
+
128
+ ## 🔐 Security Notes
129
+
130
+ - Never commit `.env` file (already in .gitignore)
131
+ - Rotate R2 API tokens periodically
132
+ - Always use SRI hashes for production deployments
133
+ - Monitor Cloudflare analytics for unusual traffic
134
+
135
+ ## 📚 Full Documentation
136
+
137
+ - **Detailed setup**: See [CDN_SETUP.md](./CDN_SETUP.md)
138
+ - **Usage examples**: See [README.md](./README.md)
139
+ - **Development**: See package.json scripts section
140
+
141
+ ## 🆘 Common Commands
142
+
143
+ ```bash
144
+ # Development
145
+ pnpm dev # Watch mode for local development
146
+ pnpm test # Run tests
147
+ pnpm lint # Lint code
148
+
149
+ # Size analysis
150
+ pnpm size:detailed # Show bundle sizes with gzip
151
+
152
+ # CI/CD
153
+ pnpm ci:bundle-check # Verify bundle size limits
154
+ pnpm ci:performance # Run performance checks
155
+ ```
156
+
157
+ ## 📝 Version History Template
158
+
159
+ When releasing, document changes:
160
+
161
+ ```markdown
162
+ ## v0.0.2 - 2025-10-02
163
+
164
+ ### Added
165
+ - New feature X
166
+ - Support for Y
167
+
168
+ ### Fixed
169
+ - Bug fix Z
170
+
171
+ ### Changed
172
+ - Improved performance of A
173
+
174
+ ### Breaking Changes (for major versions only)
175
+ - Removed deprecated API B
176
+ - Changed behavior of C
177
+ ```
178
+
179
+ ## 🎯 Release Workflow
180
+
181
+ 1. **Make changes** → Develop and test locally
182
+ 2. **Run tests** → `pnpm test`
183
+ 3. **Check bundle size** → `pnpm size:detailed`
184
+ 4. **Commit changes** → `git commit -am "feat: description"`
185
+ 5. **Deploy** → `pnpm release`
186
+ 6. **Verify** → Test on staging site
187
+ 7. **Document** → Update CHANGELOG or release notes
188
+ 8. **Notify** → Inform team/customers if needed
189
+
190
+ ---
191
+
192
+ **Need help?** See [CDN_SETUP.md](./CDN_SETUP.md) for troubleshooting or ask your team lead.