chore: update readme files of modules

This commit is contained in:
javayhu 2025-04-14 01:29:42 +08:00
parent f0d89970ee
commit 3ff522cff2
4 changed files with 124 additions and 50 deletions

View File

@ -8,7 +8,8 @@ The email system is designed with the following components:
- **Provider Interface**: A common interface for email providers in `types.ts`
- **Email Templates**: React-based email templates for different purposes in the `templates` directory
- **Configuration**: Configuration for email defaults and settings
- **Email Components**: Reusable email components in the `components` directory
- **Configuration**: Configuration for email defaults and settings in `src/config/website.tsx`
## Usage
@ -123,10 +124,26 @@ export interface EmailTemplates {
## Configuration
The email system configuration is defined in `config/mail-config.ts`. It includes settings like:
The email system configuration is defined in `src/config/website.tsx`. It includes settings like:
- Default "from" email address
- Default locale for emails
- Mail provider selection
- Default "to" email address for contact forms
Example configuration:
```typescript
// In src/config/website.tsx
export const websiteConfig = {
// ...other config
mail: {
provider: 'resend',
from: 'support@example.com',
to: 'contact@example.com',
},
// ...other config
}
```
## Providers

View File

@ -7,8 +7,8 @@ This module provides functionality for managing newsletter subscriptions using v
The newsletter system is designed with the following components:
- **Provider Interface**: A common interface for newsletter providers in `types.ts`
- **Providers**: Implementations for different newsletter service providers
- **Configuration**: Configuration for newsletter defaults and settings
- **Providers**: Implementations for different newsletter service providers in the `provider` directory
- **Configuration**: Configuration for newsletter defaults and settings in `src/config/website.tsx`
## Features
@ -35,7 +35,22 @@ const subscribed = await isSubscribed('user@example.com');
## Configuration
The newsletter module is configured using environment variables:
The newsletter module is configured in two ways:
1. In `src/config/website.tsx`:
```typescript
// In src/config/website.tsx
export const websiteConfig = {
// ...other config
newsletter: {
provider: 'resend',
},
// ...other config
}
```
2. Using environment variables:
```
# Required for Resend provider
@ -43,7 +58,7 @@ RESEND_API_KEY=your-resend-api-key
RESEND_AUDIENCE_ID=your-audience-id
```
Or you can configure it programmatically:
You can also configure it programmatically:
```typescript
import { initializeNewsletterProvider } from '@/newsletter';
@ -72,20 +87,20 @@ const result = await provider.subscribe({ email: 'user@example.com' });
You can create and use your own newsletter provider implementation:
```typescript
import { NewsletterProvider, SubscribeNewsletterProps } from '@/newsletter';
import { NewsletterProvider, SubscribeNewsletterParams } from '@/newsletter/types';
class CustomNewsletterProvider implements NewsletterProvider {
async subscribe(params: SubscribeNewsletterProps): Promise<boolean> {
async subscribe(params: SubscribeNewsletterParams): Promise<boolean> {
// Your implementation
return true;
}
async unsubscribe(params: UnsubscribeNewsletterProps): Promise<boolean> {
async unsubscribe(params: SubscribeNewsletterParams): Promise<boolean> {
// Your implementation
return true;
}
async checkSubscribeStatus(params: CheckSubscribeStatusProps): Promise<boolean> {
async checkSubscribeStatus(params: SubscribeNewsletterParams): Promise<boolean> {
// Your implementation
return true;
}

View File

@ -7,9 +7,7 @@ This module provides a flexible payment integration with Stripe, supporting both
- `/payment/types.ts` - Type definitions for the payment module
- `/payment/index.ts` - Main payment interface and global provider instance
- `/payment/provider/stripe.ts` - Stripe payment provider implementation
- `/payment/config/payment-config.ts` - Payment plans configuration
- `/actions/create-checkout-session.ts` - Server actions for creating checkout session
- `/actions/create-customer-portal-session.ts` - Server actions for creating portal session
- `/actions/payment.ts` - Server actions for payment operations
- `/app/api/webhooks/stripe/route.ts` - API route for Stripe webhook events
- `/app/[locale]/(marketing)/payment/success/page.tsx` - Success page for completed checkout
- `/app/[locale]/(marketing)/payment/cancel/page.tsx` - Cancel page for abandoned checkout
@ -28,42 +26,69 @@ The following environment variables are required:
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
# Public Stripe Variables (used in client components)
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
# Stripe Price IDs
STRIPE_PRICE_PRO_MONTHLY=price_...
STRIPE_PRICE_PRO_YEARLY=price_...
STRIPE_PRICE_LIFETIME=price_...
NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLY=price_...
NEXT_PUBLIC_STRIPE_PRICE_PRO_YEARLY=price_...
NEXT_PUBLIC_STRIPE_PRICE_LIFETIME=price_...
```
## Payment Plans
Payment plans are defined in `/payment/config/payment-config.ts`. Each plan can have multiple pricing options (monthly, yearly, one-time) with the following structure:
Payment plans are defined in `src/config/website.tsx`. Each plan can have multiple pricing options (monthly, yearly, one-time) with the following structure:
```typescript
{
id: "pro",
name: "Pro Plan",
description: "For professional users",
isFree: false,
recommended: true,
features: ["Feature 1", "Feature 2"],
prices: [
{
productId: process.env.STRIPE_PRICE_PRO_MONTHLY!,
type: "SUBSCRIPTION",
interval: "month",
amount: 2900,
currency: "USD",
trialPeriodDays: 7
},
{
productId: process.env.STRIPE_PRICE_PRO_YEARLY!,
type: "SUBSCRIPTION",
interval: "year",
amount: 24900,
currency: "USD",
trialPeriodDays: 7
// In src/config/website.tsx
export const websiteConfig = {
// ...other config
payment: {
provider: 'stripe',
plans: {
free: {
id: "free",
prices: [],
isFree: true,
isLifetime: false,
},
pro: {
id: "pro",
prices: [
{
type: PaymentTypes.SUBSCRIPTION,
priceId: process.env.NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLY!,
amount: 990,
currency: "USD",
interval: PlanIntervals.MONTH,
},
{
type: PaymentTypes.SUBSCRIPTION,
priceId: process.env.NEXT_PUBLIC_STRIPE_PRICE_PRO_YEARLY!,
amount: 9900,
currency: "USD",
interval: PlanIntervals.YEAR,
},
],
isFree: false,
isLifetime: false,
recommended: true,
},
lifetime: {
id: "lifetime",
prices: [
{
type: PaymentTypes.ONE_TIME,
priceId: process.env.NEXT_PUBLIC_STRIPE_PRICE_LIFETIME!,
amount: 19900,
currency: "USD",
},
],
isFree: false,
isLifetime: true,
}
}
]
}
}
```
@ -100,7 +125,7 @@ Creates a Stripe checkout session and redirects the user:
```tsx
<CheckoutButton
planId="pro"
priceId={process.env.STRIPE_PRICE_PRO_MONTHLY!}
priceId={process.env.NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLY!}
email="user@example.com"
metadata={{ userId: "user_123" }}
variant="default"
@ -166,7 +191,7 @@ The webhook handler processes events like:
- `payment_intent.succeeded`
- `payment_intent.payment_failed`
The webhook functionality is implemented in the `defaultWebhookHandler` method of the Stripe provider.
The webhook functionality is implemented in the `handleWebhookEvent` method of the payment module.
## Integration Steps

View File

@ -12,7 +12,7 @@ This module provides a unified interface for storing and retrieving files using
## Basic Usage
```typescript
import { uploadFile, deleteFile, getPresignedUploadUrl } from '@/src/storage';
import { uploadFile, deleteFile, getPresignedUploadUrl } from '@/storage';
// Upload a file
const { url, key } = await uploadFile(
@ -40,7 +40,7 @@ For client-side uploads, use the `uploadFileFromBrowser` function:
```typescript
'use client';
import { uploadFileFromBrowser } from '@/src/storage';
import { uploadFileFromBrowser } from '@/storage';
// In your component
async function handleFileUpload(event) {
@ -59,7 +59,22 @@ async function handleFileUpload(event) {
## Configuration
The storage module is configured using environment variables:
The storage module is configured in two ways:
1. In `src/config/website.tsx`:
```typescript
// In src/config/website.tsx
export const websiteConfig = {
// ...other config
storage: {
provider: 's3',
},
// ...other config
}
```
2. Using environment variables:
```
# Required
@ -79,7 +94,7 @@ STORAGE_FORCE_PATH_STYLE=true
If you need more control, you can interact with the storage provider directly:
```typescript
import { getStorageProvider } from '@/src/storage';
import { getStorageProvider } from '@/storage';
const provider = getStorageProvider();
@ -97,20 +112,22 @@ const result = await provider.uploadFile({
You can create and use your own storage provider implementation:
```typescript
import { StorageProvider, UploadFileParams, UploadFileResult } from '@/src/storage';
import { StorageProvider, UploadFileParams, UploadFileResult } from '@/storage/types';
class CustomStorageProvider implements StorageProvider {
// Implement the required methods
async uploadFile(params: UploadFileParams): Promise<UploadFileResult> {
// Your implementation
return { url: 'https://example.com/file.jpg', key: 'file.jpg' };
}
async deleteFile(key: string): Promise<void> {
// Your implementation
}
async getPresignedUploadUrl(params: PresignedUploadUrlParams): Promise<UploadFileResult> {
async getPresignedUploadUrl(params: PresignedUploadUrlParams): Promise<PresignedUploadUrlResult> {
// Your implementation
return { url: 'https://example.com/upload', key: 'file.jpg' };
}
getProviderName(): string {