diff --git a/web/lib/srm/examples/createCheckout.ts b/web/lib/srm/examples/createCheckout.ts deleted file mode 100644 index c93bde81..00000000 --- a/web/lib/srm/examples/createCheckout.ts +++ /dev/null @@ -1,39 +0,0 @@ -import dotenv from "dotenv"; -dotenv.config(); -import { config } from "./srm.config"; - -import { createSRM } from "../src/lib"; -import Stripe from "stripe"; - -type Config = typeof config; - -const srm = createSRM(config, { - stripe: new Stripe(process.env.STRIPE_SECRET_KEY as string, { - apiVersion: "2024-06-20", - }), -}); - -(async () => { - const url = await srm.products.enterprise.prices.annual.createSubscriptionCheckoutUrl({ - userId: "testId", - successUrl: "http://localhost:3000/success", - cancelUrl: "http://localhost:3000/cancel", - }); - const oneTimeUrl = await srm.products.hobby.prices.lifetime.createOneTimePaymentCheckoutUrl({ - userId: "testId", - successUrl: "http://localhost:3000/success", - cancelUrl: "http://localhost:3000/cancel", - allowPromotionCodes: true, - }); - const withTrialUrl = await srm.products.enterprise.prices.annual.createSubscriptionCheckoutUrl({ - userId: "testId", - successUrl: "http://localhost:3000/success", - cancelUrl: "http://localhost:3000/cancel", - }); - console.log(url, 'createSubscriptionCheckoutUrl'); - console.log(oneTimeUrl, 'createOneTimePaymentCheckoutUrl'); - console.log(withTrialUrl, 'createSubscriptionCheckoutUrl with trial period'); -})(); - - - diff --git a/web/lib/srm/examples/srm.config.ts b/web/lib/srm/examples/srm.config.ts deleted file mode 100644 index 325b0706..00000000 --- a/web/lib/srm/examples/srm.config.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { PreSRMConfig } from "../src/types"; -import { taxCodes } from "../src/tax-codes"; - -export const config = { - features: { - basicAnalytics: "Basic Analytics", - aiReporting: "AI Reporting", - }, - products: { - hobby: { - name: "Hobby Plan", - id: "hobby", - taxCode: taxCodes.SOFTWARE_AS_A_SERVICE, - prices: { - monthly: { - amount: 1000, - interval: "month", - type: "recurring", - trialPeriodDays: 7, // Add trial period for monthly plan - }, - lifetime: { - amount: 20000, - interval: "one_time", - type: "one_time", - }, - }, - features: ["basicAnalytics"], - }, - pro: { - name: "Pro Plan", - id: "pro", - taxCode: taxCodes.SOFTWARE_AS_A_SERVICE, - prices: { - annual: { - amount: 20000, - interval: "year", - type: "recurring", - }, - }, - features: ["basicAnalytics", "aiReporting"], - }, - enterprise: { - name: "Enterprise Plan", - id: "enterprise", - prices: { - annual: { - amount: 20000, - interval: "year", - type: "recurring", - trialPeriodDays: 3, // Add trial period for enterprise plan - // tax_code is optional; will default if not specified - }, - }, - features: ["basicAnalytics", "aiReporting", "customReports"], - }, - }, - webhooks: { - // tip for vercel use e.g `${process.env.VERCEL_BRANCH_URL}/webhook` - // to get auto-deployed - endpoint: "https://srm-example-app.vercel.app/api/webhooks", - events: [ - "checkout.session.completed", - "customer.subscription.deleted", - "invoice.payment_failed", - ], - }, -} satisfies PreSRMConfig; diff --git a/web/lib/srm/src/cli.ts b/web/lib/srm/src/cli.ts deleted file mode 100644 index d355fd09..00000000 --- a/web/lib/srm/src/cli.ts +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env node -import { deploy } from './deploy'; -import { pull } from './pull'; -import path from 'path'; -import fs from 'fs'; - -interface CommandOptions { - config?: string; - env?: string; -} - -function printHelp() { - console.log(` -Usage: srm [options] - -Commands: - deploy Deploy configuration to Stripe - pull Pull configuration from Stripe - -Options: - --config Path to the configuration file (default: srm.config.ts) - --env Path to the .env file (default: .env) - --help Show this help message - -Examples: - srm deploy - srm deploy --config custom-config.ts --env .env.production - srm pull - srm pull --config custom-config.ts --env .env.production - `); -} - -function parseOptions(args: string[]): CommandOptions { - const options: CommandOptions = {}; - for (let i = 1; i < args.length; i += 2) { - if (args[i] === '--config') { - options.config = args[i + 1]; - } else if (args[i] === '--env') { - options.env = args[i + 1]; - } - } - return options; -} - -function validateConfigPath(configPath: string) { - const resolvedPath = path.resolve(process.cwd(), configPath); - if (!fs.existsSync(resolvedPath)) { - throw new Error(`Configuration file not found: ${resolvedPath}`); - } - return resolvedPath; -} - -async function main() { - const args = process.argv.slice(2); - const command = args[0]; - - if (args.includes('--help') || !command) { - printHelp(); - process.exit(0); - } - - const options = parseOptions(args); - - try { - switch (command) { - case 'deploy': - // Dynamically import ts-node only when needed - const tsNode = await import('ts-node'); - tsNode.register({ - compilerOptions: { - module: 'commonjs', - }, - }); - await deploy( - options.config && validateConfigPath(options.config), - options.env - ); - break; - case 'pull': - await pull( - options.config && validateConfigPath(options.config), - options.env - ); - break; - default: - console.error(`Unknown command: ${command}`); - printHelp(); - process.exit(1); - } - } catch (error) { - if (error instanceof Error) { - console.error('Error:', error.message); - if (error.message.includes('Configuration file not found')) { - console.error('Please make sure the configuration file exists and the path is correct.'); - } - } else { - console.error('An unexpected error occurred:', error); - } - process.exit(1); - } -} - -main().catch((error) => { - console.error('Error executing SRM command:', error); - process.exit(1); -}); \ No newline at end of file diff --git a/web/lib/srm/src/srm.ts b/web/lib/srm/src/srm.ts deleted file mode 100755 index 90fa85fb..00000000 --- a/web/lib/srm/src/srm.ts +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env node - -import path from 'path'; -import fs from 'fs'; -import * as tsNode from 'ts-node'; -import { deploy } from './deploy'; - -// Register ts-node to handle TypeScript files -tsNode.register({ - compilerOptions: { - module: 'commonjs', - }, -}); - -async function main() { - const args = process.argv.slice(2); - console.log('Received arguments:', args); - - if (args[0] === 'deploy') { - let configPath = 'srm.config.ts'; - let envFilePath = '.env'; - - console.log('Initial config path:', configPath); - console.log('Initial env file path:', envFilePath); - - // Parse command-line arguments - for (let i = 1; i < args.length; i += 2) { - console.log(`Checking argument: ${args[i]}`); - if (args[i] === '--config') { - configPath = args[i + 1] || configPath; - console.log('Updated config path:', configPath); - } else if (args[i] === '--env') { - envFilePath = args[i + 1] || envFilePath; - console.log('Updated env file path:', envFilePath); - } - } - - console.log(`Final config path: ${configPath}`); - console.log(`Final env file path: ${envFilePath}`); - - // Check if the config file exists - if (!fs.existsSync(configPath)) { - console.error(`Configuration file not found: ${configPath}`); - process.exit(1); - } - - // Check if the .env file exists - if (!fs.existsSync(envFilePath)) { - console.warn(`Warning: Environment file not found: ${envFilePath}`); - console.warn('Proceeding without environment variables. Make sure STRIPE_SECRET_KEY is set.'); - } - - try { - await deploy(configPath, envFilePath); - } catch (error) { - console.error('Error during deployment:', error); - if (error instanceof Error && error.message.includes('Cannot find module')) { - console.error(`Make sure the configuration file exists at: ${path.resolve(process.cwd(), configPath)}`); - } - process.exit(1); - } - } else { - console.error('Unknown command. Use "srm deploy --config [path-to-config] --env [path-to-env-file]"'); - process.exit(1); - } -} - -main().catch((error) => { - console.error('Error executing SRM command:', error); - process.exit(1); -}); \ No newline at end of file diff --git a/web/package.json b/web/package.json index e175b3be..048481c4 100644 --- a/web/package.json +++ b/web/package.json @@ -8,6 +8,7 @@ "build": "pnpm run db:migrate && pnpm next build", "start": "pnpm next start", "lint": "pnpm next lint", + "ts:check": "pnpm tsc --noEmit", "db:generate": "pnpm drizzle-kit generate", "db:migrate": "pnpm dotenv -c -- drizzle-kit migrate", "db:studio": "pnpm dotenv -c -- drizzle-kit studio",