Packages
Cloud
Cloud infrastructure orchestration — deploy CommerceJS stores to Cloudflare with Neon Postgres.
The @commercejs/cloud package orchestrates cloud infrastructure for deploying CommerceJS stores. It provides API wrappers for Cloudflare (Workers, Pages, R2, KV), Neon Postgres, GitHub, and billing providers.
Installation
pnpm add @commercejs/cloud
Architecture
┌──────────────────────────────────────────────────────────────┐
│ @commercejs/cloud │
│ │
│ DeployOrchestrator │
│ ├─ CloudflareProvider → Workers, Pages, R2, KV, domains │
│ ├─ NeonProvider → Postgres databases, branching │
│ ├─ GitHubProvider → Webhooks, repo access, auth │
│ └─ BillingProvider → Stripe / Tap subscriptions │
│ │
│ WebhookHandler → GitHub push/PR event dispatch │
│ PreviewManager → Branch-per-PR preview environments │
└──────────────────────────────────────────────────────────────┘
Deploy Orchestrator
The main entry point for deploying stores:
import { DeployOrchestrator } from '@commercejs/cloud'
const orchestrator = new DeployOrchestrator({
cloudflare: {
accountId: process.env.CF_ACCOUNT_ID!,
apiToken: process.env.CF_API_TOKEN!,
},
neon: {
apiKey: process.env.NEON_API_KEY!,
},
github: {
appId: process.env.GITHUB_APP_ID!,
privateKey: process.env.GITHUB_PRIVATE_KEY!,
},
})
const result = await orchestrator.deploy({
project: myProject,
environment: 'production',
source: { repoUrl: 'https://github.com/user/store', branch: 'main' },
})
// → { url: 'https://my-store.commercejs.cloud', status: 'healthy' }
Providers
Cloudflare
Manages Workers, Pages, R2, KV, and custom domains.
import { CloudflareProvider } from '@commercejs/cloud'
const cf = new CloudflareProvider({
accountId: process.env.CF_ACCOUNT_ID!,
apiToken: process.env.CF_API_TOKEN!,
})
await cf.createProject('my-store')
await cf.deployWorker('my-store', workerBundle)
await cf.createR2Bucket('my-store-assets')
await cf.setCustomDomain('my-store', 'store.example.com')
Neon
Manages Postgres databases with branch-per-PR support.
import { NeonProvider } from '@commercejs/cloud'
const neon = new NeonProvider({ apiKey: process.env.NEON_API_KEY! })
const project = await neon.createProject('my-store')
const connectionString = await neon.getConnectionString(project.id)
// Preview environments: branch per PR
const branch = await neon.createBranch(project.id, 'pr-42')
await neon.deleteBranch(project.id, branch.id)
GitHub
Handles GitHub App authentication and webhook events.
import { GitHubProvider } from '@commercejs/cloud'
const github = new GitHubProvider({
appId: process.env.GITHUB_APP_ID!,
privateKey: process.env.GITHUB_PRIVATE_KEY!,
})
const repos = await github.listRepos(installationId)
await github.installWebhook(installationId, repoName, webhookUrl)
Billing
Dual provider: Stripe (international) + Tap Payments (GCC region).
import { BillingProvider } from '@commercejs/cloud'
const billing = new BillingProvider({
stripe: { secretKey: process.env.STRIPE_SECRET_KEY! },
tap: { secretKey: process.env.TAP_SECRET_KEY! },
})
const subscription = await billing.createSubscription({
customerId: 'cus_123',
plan: 'pro',
provider: 'stripe', // or 'tap' for GCC merchants
})
Preview Environments
The PreviewManager creates ephemeral environments for PRs:
import { PreviewManager } from '@commercejs/cloud'
const previews = new PreviewManager({ neon, cloudflare })
// On PR open: branch DB + deploy preview
const preview = await previews.create(project, prNumber)
// → { url: 'https://pr-42.my-store.pages.dev', dbBranch: 'pr-42' }
// On PR close: cleanup
await previews.destroy(project, prNumber)
Webhook Handler
Process GitHub webhook events for automated deploys:
import { WebhookHandler } from '@commercejs/cloud'
const handler = new WebhookHandler({ orchestrator, previews })
// In your webhook endpoint:
await handler.handle(event)
// push to main → production deploy
// PR opened/updated → preview deploy
// PR closed → preview cleanup
Types
| Type | Description |
|---|---|
CloudProject | Project config (name, repo, environment settings) |
CloudEnvironment | Environment config (production, staging, preview) |
DeployConfig | Deploy settings (source, environment, build command) |
DeployResult | Deploy outcome (URL, status, logs) |
CloudflareConfig | Cloudflare API credentials |
NeonConfig | Neon API credentials |
GitHubConfig | GitHub App credentials |
BillingConfig | Stripe + Tap credentials |
Status
Scaffold — Provider APIs are structured but not yet integration-tested against live services. Unit tests with mocked APIs are planned.