@cogito.ai/cli 0.4.3 → 0.4.4

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.
Files changed (45) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/templates/web-nextjs/apps/docs/.source/browser.ts +8 -18
  3. package/dist/templates/web-nextjs/apps/docs/.source/dynamic.ts +5 -11
  4. package/dist/templates/web-nextjs/apps/docs/.source/server.ts +17 -37
  5. package/dist/templates/web-nextjs/apps/web/.env.example +35 -0
  6. package/dist/templates/web-nextjs/apps/web/messages/en.json +70 -0
  7. package/dist/templates/web-nextjs/apps/web/messages/zh.json +71 -1
  8. package/dist/templates/web-nextjs/apps/web/next-env.d.ts +1 -1
  9. package/dist/templates/web-nextjs/apps/web/package.json +4 -0
  10. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(auth)/forgot-password/page.tsx +4 -10
  11. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/payment/[paymentId]/page.tsx +88 -0
  12. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/payment/checkout/page.tsx +170 -0
  13. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/pricing/page.tsx +120 -0
  14. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/settings/layout.tsx +48 -1
  15. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/settings/subscription/page.tsx +128 -0
  16. package/dist/templates/web-nextjs/apps/web/src/app/[locale]/layout.tsx +1 -1
  17. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/create/route.ts +43 -0
  18. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/notify/route.ts +105 -0
  19. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/query/route.ts +54 -0
  20. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/return/route.ts +20 -0
  21. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/create/route.ts +52 -0
  22. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/create/route.ts +58 -0
  23. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/notify/route.ts +92 -0
  24. package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/query/route.ts +54 -0
  25. package/dist/templates/web-nextjs/apps/web/src/features/subscription/alipay/client.ts +36 -0
  26. package/dist/templates/web-nextjs/apps/web/src/features/subscription/alipay/server.ts +83 -0
  27. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/index.ts +4 -0
  28. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/pro-badge.tsx +9 -0
  29. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/pro-feature-comparison.tsx +70 -0
  30. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/quota-warning-banner.tsx +37 -0
  31. package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/upgrade-button.tsx +42 -0
  32. package/dist/templates/web-nextjs/apps/web/src/features/subscription/hooks.ts +141 -0
  33. package/dist/templates/web-nextjs/apps/web/src/features/subscription/payment-helpers.ts +27 -0
  34. package/dist/templates/web-nextjs/apps/web/src/features/subscription/payment-service.ts +56 -0
  35. package/dist/templates/web-nextjs/apps/web/src/features/subscription/service.ts +55 -0
  36. package/dist/templates/web-nextjs/apps/web/src/features/subscription/types.ts +73 -0
  37. package/dist/templates/web-nextjs/apps/web/src/features/subscription/wechat/client.ts +33 -0
  38. package/dist/templates/web-nextjs/apps/web/src/features/subscription/wechat/server.ts +147 -0
  39. package/dist/templates/web-nextjs/apps/web/src/lib/supabase/admin.ts +23 -0
  40. package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/client.ts +66 -0
  41. package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/crypto.ts +99 -0
  42. package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/types.ts +10 -0
  43. package/dist/templates/web-nextjs/pnpm-lock.yaml +319 -0
  44. package/dist/templates/web-nextjs/supabase/migrations/20250608_add_subscription_tables.sql +125 -0
  45. package/package.json +1 -1
@@ -0,0 +1,125 @@
1
+ -- Migration: add subscription tables for payments
2
+ -- Created: 2025-06-08
3
+
4
+ -- ============================================
5
+ -- subscription_plans: plan catalog
6
+ -- ============================================
7
+ create table if not exists subscription_plans (
8
+ id serial primary key,
9
+ plan_code text not null unique,
10
+ plan_name text not null,
11
+ description text,
12
+ price_monthly int not null default 0,
13
+ price_yearly int not null default 0,
14
+ features jsonb default '{}',
15
+ display_order int default 0,
16
+ is_active bool default true,
17
+ is_featured bool default false,
18
+ created_at timestamptz default now(),
19
+ updated_at timestamptz default now()
20
+ );
21
+
22
+ -- Enable RLS
23
+ alter table subscription_plans enable row level security;
24
+
25
+ -- RLS policies: all authenticated users can SELECT
26
+ create policy "Allow authenticated select on subscription_plans"
27
+ on subscription_plans for select
28
+ to authenticated
29
+ using (true);
30
+
31
+ -- service_role only for INSERT/UPDATE/DELETE
32
+ create policy "Allow service_role all on subscription_plans"
33
+ on subscription_plans for all
34
+ to service_role
35
+ using (true)
36
+ with check (true);
37
+
38
+ -- ============================================
39
+ -- user_subscriptions: user subscription records
40
+ -- ============================================
41
+ create table if not exists user_subscriptions (
42
+ id serial primary key,
43
+ user_id uuid references auth.users not null,
44
+ plan_id int references subscription_plans(id) not null,
45
+ status text not null default 'pending' check (status in ('trial', 'active', 'expired', 'cancelled', 'pending')),
46
+ billing_cycle text not null default 'monthly' check (billing_cycle in ('monthly', 'yearly')),
47
+ current_period_start timestamptz,
48
+ current_period_end timestamptz,
49
+ cancelled_at timestamptz,
50
+ cancel_at_period_end bool default false,
51
+ last_payment_id int,
52
+ next_billing_date date,
53
+ metadata jsonb default '{}',
54
+ created_at timestamptz default now(),
55
+ updated_at timestamptz default now()
56
+ );
57
+
58
+ -- Enable RLS
59
+ alter table user_subscriptions enable row level security;
60
+
61
+ -- Users can only SELECT their own records
62
+ create policy "Allow users select own subscriptions"
63
+ on user_subscriptions for select
64
+ to authenticated
65
+ using (user_id = auth.uid());
66
+
67
+ -- Users can UPDATE their own records (for cancel_at_period_end)
68
+ create policy "Allow users update own subscriptions"
69
+ on user_subscriptions for update
70
+ to authenticated
71
+ using (user_id = auth.uid());
72
+
73
+ -- service_role for INSERT
74
+ create policy "Allow service_role all on user_subscriptions"
75
+ on user_subscriptions for all
76
+ to service_role
77
+ using (true)
78
+ with check (true);
79
+
80
+ -- ============================================
81
+ -- payments: payment records
82
+ -- ============================================
83
+ create table if not exists payments (
84
+ id serial primary key,
85
+ user_id uuid references auth.users not null,
86
+ subscription_id int references user_subscriptions(id),
87
+ order_no text not null unique,
88
+ amount int not null,
89
+ currency text default 'CNY',
90
+ payment_method text not null check (payment_method in ('alipay', 'wechat', 'stripe')),
91
+ payment_channel text,
92
+ status text not null default 'pending' check (status in ('pending', 'paid', 'failed', 'refunded', 'cancelled')),
93
+ provider_trade_no text,
94
+ provider_response jsonb,
95
+ paid_at timestamptz,
96
+ refunded_at timestamptz,
97
+ metadata jsonb default '{}',
98
+ created_at timestamptz default now(),
99
+ updated_at timestamptz default now()
100
+ );
101
+
102
+ -- Enable RLS
103
+ alter table payments enable row level security;
104
+
105
+ -- Users can SELECT their own payment records
106
+ create policy "Allow users select own payments"
107
+ on payments for select
108
+ to authenticated
109
+ using (user_id = auth.uid());
110
+
111
+ -- service_role for INSERT/UPDATE
112
+ create policy "Allow service_role all on payments"
113
+ on payments for all
114
+ to service_role
115
+ using (true)
116
+ with check (true);
117
+
118
+ -- ============================================
119
+ -- Seed data: Free + Pro plans
120
+ -- ============================================
121
+ insert into subscription_plans (plan_code, plan_name, description, price_monthly, price_yearly, features, display_order, is_active, is_featured)
122
+ values
123
+ ('free', 'Free', '基础免费方案', 0, 0, '{"maxProjects": 3, "maxApiCalls": 1000}'::jsonb, 1, true, false),
124
+ ('pro', 'Pro', '专业版方案', 3900, 29900, '{"maxProjects": 50, "maxApiCalls": 100000, "prioritySupport": true}'::jsonb, 2, true, true)
125
+ on conflict (plan_code) do nothing;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cogito.ai/cli",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "description": "AgentDock CLI – scaffold projects for humans and AI agents",
6
6
  "publishConfig": {