Skip to content

Commit 5c15e68

Browse files
committed
feat: add authentication, storage, and metadata schemas for enhanced API functionality
1 parent fa1659c commit 5c15e68

4 files changed

Lines changed: 159 additions & 0 deletions

File tree

packages/spec/src/api/auth.zod.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { z } from 'zod';
2+
import { BaseResponseSchema } from './contract.zod';
3+
4+
/**
5+
* Authentication Service Protocol
6+
*
7+
* Defines the standard API contracts for Identity, Session Management,
8+
* and Access Control.
9+
*/
10+
11+
// ==========================================
12+
// Authentication Types
13+
// ==========================================
14+
15+
export const AuthProvider = z.enum([
16+
'local',
17+
'google',
18+
'github',
19+
'microsoft',
20+
'ldap',
21+
'saml'
22+
]);
23+
24+
export const SessionUserSchema = z.object({
25+
id: z.string().describe('User ID'),
26+
username: z.string().describe('Username'),
27+
email: z.string().email().describe('Email address'),
28+
name: z.string().describe('Display name'),
29+
roles: z.array(z.string()).describe('Assigned role IDs'),
30+
tenantId: z.string().describe('Current tenant ID'),
31+
avatar: z.string().optional().describe('Avatar URL'),
32+
language: z.string().default('en').describe('Preferred language'),
33+
timezone: z.string().optional().describe('Preferred timezone'),
34+
});
35+
36+
// ==========================================
37+
// Requests
38+
// ==========================================
39+
40+
export const LoginRequestSchema = z.object({
41+
username: z.string().describe('Username or Email'),
42+
password: z.string().describe('Password credential'),
43+
type: z.literal('password').default('password'),
44+
});
45+
46+
export const RefreshTokenRequestSchema = z.object({
47+
refreshToken: z.string().describe('Refresh token'),
48+
});
49+
50+
// ==========================================
51+
// Responses
52+
// ==========================================
53+
54+
export const SessionResponseSchema = BaseResponseSchema.extend({
55+
data: z.object({
56+
accessToken: z.string().describe('JWT Access Token'),
57+
refreshToken: z.string().optional().describe('Refresh Token (if enabled)'),
58+
expiresIn: z.number().describe('Token expiry in seconds'),
59+
user: SessionUserSchema.describe('Current user details'),
60+
}),
61+
});
62+
63+
export const UserProfileResponseSchema = BaseResponseSchema.extend({
64+
data: SessionUserSchema,
65+
});

packages/spec/src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ export * from './documentation.zod';
3030
// Legacy interface export (deprecated)
3131
// export type { IObjectStackProtocol } from './protocol';
3232

33+
export * from './auth.zod';
34+
export * from './storage.zod';
35+
export * from './metadata.zod';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { z } from 'zod';
2+
import { BaseResponseSchema } from './contract.zod';
3+
import { ObjectSchema } from '../data/object.zod';
4+
import { AppSchema } from '../ui/app.zod';
5+
6+
/**
7+
* Metadata Service Protocol
8+
*
9+
* Defines the standard API contracts for fetching system metadata.
10+
* Frontend, IDEs, and Mobile apps use this to build dynamic UIs.
11+
*/
12+
13+
// ==========================================
14+
// Responses
15+
// ==========================================
16+
17+
/**
18+
* Single Object Definition Response
19+
* Returns the full JSON schema for an Entity (Fields, Actions, Config).
20+
*/
21+
export const ObjectDefinitionResponseSchema = BaseResponseSchema.extend({
22+
data: ObjectSchema.describe('Full Object Schema'),
23+
});
24+
25+
/**
26+
* App Definition Response
27+
* Returns the navigation, branding, and layout for an App.
28+
*/
29+
export const AppDefinitionResponseSchema = BaseResponseSchema.extend({
30+
data: AppSchema.describe('Full App Configuration'),
31+
});
32+
33+
/**
34+
* All Concepts Response
35+
* Bulk load lightweight definitions for autocomplete/pickers.
36+
*/
37+
export const ConceptListResponseSchema = BaseResponseSchema.extend({
38+
data: z.array(z.object({
39+
name: z.string(),
40+
label: z.string(),
41+
icon: z.string().optional(),
42+
description: z.string().optional(),
43+
})).describe('List of available concepts (Objects, Apps, Flows)'),
44+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { z } from 'zod';
2+
import { BaseResponseSchema } from './contract.zod';
3+
import { FileMetadataSchema } from '../system/object-storage.zod';
4+
5+
/**
6+
* Storage Service Protocol
7+
*
8+
* Defines the API contract for client-side file operations.
9+
* Focuses on secure, direct-to-cloud uploads (Presigned URLs)
10+
* rather than proxying bytes through the API server.
11+
*/
12+
13+
// ==========================================
14+
// Requests
15+
// ==========================================
16+
17+
export const GetPresignedUrlRequestSchema = z.object({
18+
filename: z.string().describe('Original filename'),
19+
mimeType: z.string().describe('File MIME type'),
20+
size: z.number().describe('File size in bytes'),
21+
scope: z.string().default('user').describe('Target storage scope (e.g. user, private, public)'),
22+
bucket: z.string().optional().describe('Specific bucket override (admin only)'),
23+
});
24+
25+
export const CompleteUploadRequestSchema = z.object({
26+
fileId: z.string().describe('File ID returned from presigned request'),
27+
eTag: z.string().optional().describe('S3 ETag verification'),
28+
});
29+
30+
// ==========================================
31+
// Responses
32+
// ==========================================
33+
34+
export const PresignedUrlResponseSchema = BaseResponseSchema.extend({
35+
data: z.object({
36+
uploadUrl: z.string().describe('PUT/POST URL for direct upload'),
37+
downloadUrl: z.string().optional().describe('Public/Private preview URL'),
38+
fileId: z.string().describe('Temporary File ID'),
39+
method: z.enum(['PUT', 'POST']).describe('HTTP Method to use'),
40+
headers: z.record(z.string()).optional().describe('Required headers for upload'),
41+
expiresIn: z.number().describe('URL expiry in seconds'),
42+
}),
43+
});
44+
45+
export const FileUploadResponseSchema = BaseResponseSchema.extend({
46+
data: FileMetadataSchema.describe('Uploaded file metadata'),
47+
});

0 commit comments

Comments
 (0)