@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.
- package/dist/index.js +1 -1
- package/dist/templates/web-nextjs/apps/docs/.source/browser.ts +8 -18
- package/dist/templates/web-nextjs/apps/docs/.source/dynamic.ts +5 -11
- package/dist/templates/web-nextjs/apps/docs/.source/server.ts +17 -37
- package/dist/templates/web-nextjs/apps/web/.env.example +35 -0
- package/dist/templates/web-nextjs/apps/web/messages/en.json +70 -0
- package/dist/templates/web-nextjs/apps/web/messages/zh.json +71 -1
- package/dist/templates/web-nextjs/apps/web/next-env.d.ts +1 -1
- package/dist/templates/web-nextjs/apps/web/package.json +4 -0
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(auth)/forgot-password/page.tsx +4 -10
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/payment/[paymentId]/page.tsx +88 -0
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/payment/checkout/page.tsx +170 -0
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/pricing/page.tsx +120 -0
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/settings/layout.tsx +48 -1
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/(protected)/settings/subscription/page.tsx +128 -0
- package/dist/templates/web-nextjs/apps/web/src/app/[locale]/layout.tsx +1 -1
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/create/route.ts +43 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/notify/route.ts +105 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/query/route.ts +54 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/alipay/return/route.ts +20 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/create/route.ts +52 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/create/route.ts +58 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/notify/route.ts +92 -0
- package/dist/templates/web-nextjs/apps/web/src/app/api/payments/wechat/query/route.ts +54 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/alipay/client.ts +36 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/alipay/server.ts +83 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/index.ts +4 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/pro-badge.tsx +9 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/pro-feature-comparison.tsx +70 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/quota-warning-banner.tsx +37 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/components/upgrade-button.tsx +42 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/hooks.ts +141 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/payment-helpers.ts +27 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/payment-service.ts +56 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/service.ts +55 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/types.ts +73 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/wechat/client.ts +33 -0
- package/dist/templates/web-nextjs/apps/web/src/features/subscription/wechat/server.ts +147 -0
- package/dist/templates/web-nextjs/apps/web/src/lib/supabase/admin.ts +23 -0
- package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/client.ts +66 -0
- package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/crypto.ts +99 -0
- package/dist/templates/web-nextjs/apps/web/src/lib/wechat-pay/types.ts +10 -0
- package/dist/templates/web-nextjs/pnpm-lock.yaml +319 -0
- package/dist/templates/web-nextjs/supabase/migrations/20250608_add_subscription_tables.sql +125 -0
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates a random nonce string (16 hex chars, uppercase)
|
|
5
|
+
*/
|
|
6
|
+
export function generateNonce(): string {
|
|
7
|
+
return crypto.randomBytes(16).toString('hex').toUpperCase()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface SignRequestParams {
|
|
11
|
+
method: string
|
|
12
|
+
url: string
|
|
13
|
+
timestamp: string
|
|
14
|
+
nonce: string
|
|
15
|
+
body: string
|
|
16
|
+
privateKey: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Constructs the -line signature string and signs it with SHA256withRSA using the merchant private key.
|
|
21
|
+
* Returns Base64 encoded signature.
|
|
22
|
+
*/
|
|
23
|
+
export function signRequest(params: SignRequestParams): string {
|
|
24
|
+
const { method, url, timestamp, nonce, body, privateKey } = params
|
|
25
|
+
const signStr = `${method.toUpperCase()}\n${url}\n${timestamp}\n${nonce}\n${body}\n`
|
|
26
|
+
|
|
27
|
+
const signer = crypto.createSign('RSA-SHA256')
|
|
28
|
+
signer.update(signStr)
|
|
29
|
+
return signer.sign(privateKey, 'base64')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface BuildAuthorizationHeaderParams {
|
|
33
|
+
mchId: string
|
|
34
|
+
serialNo: string
|
|
35
|
+
timestamp: string
|
|
36
|
+
nonce: string
|
|
37
|
+
signature: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Builds the Authorization header for WeChat Pay V3 API requests.
|
|
42
|
+
*/
|
|
43
|
+
export function buildAuthorizationHeader(params: BuildAuthorizationHeaderParams): string {
|
|
44
|
+
const { mchId, serialNo, timestamp, nonce, signature } = params
|
|
45
|
+
return `WECHATPAY2-SHA256-RSA2048 mchid="${mchId}",nonce_str="${nonce}",timestamp="${timestamp}",serial_no="${serialNo}",signature="${signature}"`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface VerifySignatureParams {
|
|
49
|
+
timestamp: string
|
|
50
|
+
nonce: string
|
|
51
|
+
body: string
|
|
52
|
+
signature: string
|
|
53
|
+
platformPublicKey: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Verifies WeChat Pay notification signature using the platform public key.
|
|
58
|
+
*/
|
|
59
|
+
export function verifySignature(params: VerifySignatureParams): boolean {
|
|
60
|
+
const { timestamp, nonce, body, signature, platformPublicKey } = params
|
|
61
|
+
const verifyStr = `${timestamp}\n${nonce}\n${body}\n`
|
|
62
|
+
|
|
63
|
+
const verifier = crypto.createVerify('RSA-SHA256')
|
|
64
|
+
verifier.update(verifyStr)
|
|
65
|
+
return verifier.verify(platformPublicKey, signature, 'base64')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface DecryptResourceParams {
|
|
69
|
+
ciphertext: string
|
|
70
|
+
associatedData: string
|
|
71
|
+
nonce: string
|
|
72
|
+
apiV3Key: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Decrypts AEAD_AES_256_GCM encrypted resource.
|
|
77
|
+
* The ciphertext includes the auth tag as the last 16 bytes.
|
|
78
|
+
*/
|
|
79
|
+
export function decryptResource(params: DecryptResourceParams): string {
|
|
80
|
+
const { ciphertext, associatedData, nonce, apiV3Key } = params
|
|
81
|
+
const buf = Buffer.from(ciphertext, 'base64')
|
|
82
|
+
|
|
83
|
+
// AES-256-GCM: last 16 bytes are the auth tag
|
|
84
|
+
const authTagLength = 16
|
|
85
|
+
const encrypted = buf.slice(0, -authTagLength)
|
|
86
|
+
const authTag = buf.slice(-authTagLength)
|
|
87
|
+
|
|
88
|
+
const decipher = crypto.createDecipheriv(
|
|
89
|
+
'aes-256-gcm',
|
|
90
|
+
Buffer.from(apiV3Key),
|
|
91
|
+
Buffer.from(nonce, 'utf8'),
|
|
92
|
+
)
|
|
93
|
+
decipher.setAuthTag(authTag)
|
|
94
|
+
decipher.setAAD(Buffer.from(associatedData))
|
|
95
|
+
|
|
96
|
+
let decrypted = decipher.update(encrypted, undefined, 'utf8')
|
|
97
|
+
decrypted += decipher.final('utf8')
|
|
98
|
+
return decrypted
|
|
99
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface WechatPayConfig {
|
|
2
|
+
appId: string
|
|
3
|
+
mchId: string
|
|
4
|
+
privateKey: string // PKCS8 PEM format merchant private key
|
|
5
|
+
serialNo: string // Merchant certificate serial number
|
|
6
|
+
apiV3Key: string // 32-byte APIv3 key
|
|
7
|
+
platformPublicKey: string // WeChat platform public key PEM (downloaded from /v3/certificates)
|
|
8
|
+
baseUrl: string // Domestic: https://api.mch.weixin.qq.com; Overseas: https://apihk.mch.weixin.qq.com
|
|
9
|
+
notifyUrl: string
|
|
10
|
+
}
|