feat(api): 开发auth、login等接口,规范格式化
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
{
|
||||
"name": "@atlas/contracts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "4.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "7.0.2"
|
||||
}
|
||||
"name": "@atlas/contracts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "4.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "7.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const registerRequestSchema = z.object({
|
||||
email: z.string().trim().email().max(254),
|
||||
password: z.string().min(1),
|
||||
password_confirmation: z.string().min(1),
|
||||
display_name: z.string().trim().max(80).nullable().optional(),
|
||||
});
|
||||
export const loginRequestSchema = z.object({
|
||||
email: z.string().trim().email().max(254),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
|
||||
export const authUserSchema = z.object({
|
||||
id: z.uuid(),
|
||||
email: z.string().email(),
|
||||
display_name: z.string().nullable(),
|
||||
email_verified_at: z.iso.datetime().nullable(),
|
||||
created_at: z.iso.datetime(),
|
||||
});
|
||||
export const workspaceSchema = z.object({
|
||||
id: z.uuid(),
|
||||
name: z.string(),
|
||||
role: z.enum(['owner', 'admin', 'editor', 'viewer']),
|
||||
});
|
||||
export const authSessionResponseSchema = z.object({
|
||||
access_token: z.string(),
|
||||
access_token_expires_in: z.number().int().positive(),
|
||||
user: authUserSchema,
|
||||
workspace: workspaceSchema,
|
||||
});
|
||||
export type RegisterRequest = z.infer<typeof registerRequestSchema>;
|
||||
export type LoginRequest = z.infer<typeof loginRequestSchema>;
|
||||
export type AuthUser = z.infer<typeof authUserSchema>;
|
||||
export type Workspace = z.infer<typeof workspaceSchema>;
|
||||
export type AuthSessionResponse = z.infer<typeof authSessionResponseSchema>;
|
||||
@@ -5,20 +5,22 @@ import { z } from 'zod';
|
||||
* 领域字段会随采集模块实现逐步补全,不能在扩展侧绕过此契约直接构造 API 请求。
|
||||
*/
|
||||
export const collectedProductPayloadSchema = z.object({
|
||||
source: z.object({
|
||||
platform: z.enum(['ozon', '1688', 'taobao', 'tmall']),
|
||||
itemKey: z.string().min(1),
|
||||
canonicalUrl: z.url(),
|
||||
collectedAt: z.iso.datetime(),
|
||||
parserVersion: z.string().min(1),
|
||||
}),
|
||||
common: z.object({
|
||||
title: z.string().min(1).optional(),
|
||||
}),
|
||||
variantAxes: z.array(z.unknown()),
|
||||
variants: z.array(z.unknown()),
|
||||
assets: z.array(z.unknown()),
|
||||
evidence: z.array(z.unknown()),
|
||||
source: z.object({
|
||||
platform: z.enum(['ozon', '1688', 'taobao', 'tmall']),
|
||||
itemKey: z.string().min(1),
|
||||
canonicalUrl: z.url(),
|
||||
collectedAt: z.iso.datetime(),
|
||||
parserVersion: z.string().min(1),
|
||||
}),
|
||||
common: z.object({
|
||||
title: z.string().min(1).optional(),
|
||||
}),
|
||||
variantAxes: z.array(z.unknown()),
|
||||
variants: z.array(z.unknown()),
|
||||
assets: z.array(z.unknown()),
|
||||
evidence: z.array(z.unknown()),
|
||||
});
|
||||
|
||||
export type CollectedProductPayload = z.infer<typeof collectedProductPayloadSchema>;
|
||||
export type CollectedProductPayload = z.infer<
|
||||
typeof collectedProductPayloadSchema
|
||||
>;
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './collection';
|
||||
export * from './auth';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user