feat: implement license platform business flows and delivery tooling
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation.

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-09 15:33:22 +08:00
parent 3ab651d3a8
commit 54c318c615
142 changed files with 11105 additions and 178 deletions

30
frontend/src/api.ts Normal file
View File

@@ -0,0 +1,30 @@
import axios from 'axios'
export const api = axios.create({ baseURL: '/api/v1', timeout: 8000, withCredentials: true })
api.interceptors.response.use((response) => response, (error) => {
const message = error.response?.data?.error?.message || '请求失败,请稍后重试'
return Promise.reject(new Error(message))
})
export type Customer = { id:number; name:string; contact_email:string; status:string; created_at:string; updated_at:string }
export type Product = { id:number; code:string; name:string; description:string; active:boolean; created_at:string; updated_at:string }
export async function login(username:string,password:string) { return api.post('/auth/login',{username,password}) }
export async function logout() { return api.post('/auth/logout') }
export async function me() { return api.get('/me') }
export async function listCustomers(params?:Record<string,string|number>) { return api.get<{data:Customer[];meta:{page:number;page_size:number;total:number}}>('/customers',{params}) }
export async function createCustomer(value:Pick<Customer,'name'|'contact_email'>) { return api.post('/customers',value) }
export async function updateCustomer(id:number,value:Partial<Customer>) { return api.put(`/customers/${id}`,value) }
export async function deleteCustomer(id:number) { return api.delete(`/customers/${id}`) }
export async function listProducts() { return api.get<{data:Product[]}>('/products') }
export async function createProduct(value:Pick<Product,'code'|'name'|'description'>) { return api.post('/products',value) }
export async function updateProduct(id:number,value:Partial<Product>) { return api.put(`/products/${id}`,value) }
export async function deleteProduct(id:number) { return api.delete(`/products/${id}`) }
export type License = { id:number; license_key:string; customer_id:number; customer_name:string; product_id:number; product_name:string; product_code:string; status:'active'|'scheduled'|'expired'|'revoked'|string; starts_at:string; expires_at:string; created_at:string }
export async function listLicenses(params?:Record<string,string|number>) { return api.get<{data:License[];meta:{page:number;page_size:number;total:number}}>('/licenses',{params}) }
export async function issueLicense(value:{customer_id:number;product_id:number;starts_at:string;expires_at:string}, idempotencyKey:string) { return api.post('/licenses',value,{headers:{'Idempotency-Key':idempotencyKey}}) }
export type LicenseInstance = { id:number; instance_id:string; license_id:number; customer_id:number; product_id:number; status:string; activated_at?:string; certificate_version?:string; created_at:string; last_seen_at?:string; lease_expires_at?:string; freeze_state:string; observed_state:string; entitlement_state:string }
export async function setInstanceFrozen(instanceID:string,frozen:boolean,key:string) { return api.post(`/instances/${instanceID}/freeze`,{frozen},{headers:{'Idempotency-Key':key}}) }
export async function listLicenseInstances(id:number) { return api.get<{data:LicenseInstance[]}>(`/licenses/${id}/instances`) }
export async function getLicense(id:number) { return api.get<{data:License}>(`/licenses/${id}`) }
export async function revokeLicense(id:number,idempotencyKey:string) { return api.post(`/licenses/${id}/revoke`,{}, {headers:{'Idempotency-Key':idempotencyKey}}) }
export async function renewLicense(id:number,expires_at:string,idempotencyKey:string) { return api.post(`/licenses/${id}/renew`,{expires_at},{headers:{'Idempotency-Key':idempotencyKey}}) }