Skip to content

Commit d7e434a

Browse files
committed
feat(examples): update API examples to improve structure and security definitions
1 parent 3fa435f commit d7e434a

5 files changed

Lines changed: 94 additions & 87 deletions

File tree

examples/features/api-discovery-example.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const fullDiscoveryResponse: API.DiscoveryResponse = {
3939
search: true,
4040
websockets: true,
4141
files: true,
42+
analytics: false,
43+
hub: false,
4244
},
4345

4446
// Localization Info
@@ -70,6 +72,8 @@ export const devDiscoveryResponse: API.DiscoveryResponse = {
7072
search: true,
7173
websockets: false,
7274
files: true,
75+
analytics: false,
76+
hub: false,
7377
},
7478

7579
locale: {

examples/features/auth-permission-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* - Sharing and territory management
1111
*/
1212

13-
import type { Auth, Permission } from '@objectstack/spec';
13+
import { Identity as Auth, Security as Permission } from '@objectstack/spec';
1414

1515
/**
1616
* Example 1: User Identity

examples/features/hub-management-example.ts

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const createSpaceExample: CreateSpaceRequest = {
9090
/**
9191
* Space creation response
9292
*/
93-
export const spaceCreatedResponse: SpaceResponse = {
93+
export const spaceCreatedResponse = {
9494
id: '550e8400-e29b-41d4-a716-446655440000',
9595
name: 'Sales Team Workspace',
9696
slug: 'sales-team',
@@ -223,6 +223,7 @@ export const publishPluginExample: PublishPluginRequest = {
223223
* Searching plugins in the marketplace
224224
*/
225225
export const searchPluginsExample: SearchPluginsResponse = {
226+
success: true,
226227
data: [
227228
{
228229
...publishPluginExample,
@@ -310,28 +311,34 @@ export const issueLicenseExample: IssueLicenseRequest = {
310311
* License issued response
311312
*/
312313
export const licenseIssuedExample: LicenseResponse = {
313-
spaceId: '550e8400-e29b-41d4-a716-446655440000',
314-
planCode: 'enterprise_v1',
315-
status: 'active',
316-
issuedAt: '2024-01-01T00:00:00Z',
317-
expiresAt: '2025-12-31T23:59:59Z',
318-
customFeatures: ['advanced_analytics', 'ai_insights'],
319-
customLimits: {
320-
storage_gb: 500,
321-
api_calls_monthly: 10000000,
322-
},
323-
plugins: ['com.acme.advanced-crm'],
324-
signature: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
314+
success: true,
315+
data: {
316+
spaceId: '550e8400-e29b-41d4-a716-446655440000',
317+
planCode: 'enterprise_v1',
318+
status: 'active',
319+
issuedAt: '2024-01-01T00:00:00Z',
320+
expiresAt: '2025-12-31T23:59:59Z',
321+
customFeatures: ['advanced_analytics', 'ai_insights'],
322+
customLimits: {
323+
storage_gb: 500,
324+
api_calls_monthly: 10000000,
325+
},
326+
plugins: ['com.acme.advanced-crm'],
327+
signature: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
328+
}
325329
};
326330

327331
/**
328332
* Validating a license
329333
*/
330334
export const validateLicenseExample: ValidateLicenseResponse = {
331-
valid: true,
332-
license: licenseIssuedExample,
333-
errors: [],
334-
warnings: [],
335+
success: true,
336+
data: {
337+
valid: true,
338+
license: (licenseIssuedExample as any).data,
339+
errors: [],
340+
warnings: [],
341+
}
335342
};
336343

337344
// ============================================================================
@@ -760,14 +767,16 @@ export const compileManifestExample: CompileManifestRequest = {
760767
*/
761768
export const compileManifestResultExample: CompileManifestResponse = {
762769
success: true,
763-
buildId: 'build_abc123',
764-
timestamp: '2024-01-15T12:00:00Z',
765-
duration: 5420, // 5.4 seconds
766-
767-
manifestUrl: 'https://cdn.objectstack.com/manifests/build_abc123.json',
768-
769-
conflicts: [],
770-
errors: [],
770+
data: {
771+
buildId: 'build_abc123',
772+
timestamp: '2024-01-15T12:00:00Z',
773+
duration: 5420, // 5.4 seconds
774+
775+
manifestUrl: 'https://cdn.objectstack.com/manifests/build_abc123.json',
776+
777+
conflicts: [],
778+
errors: [],
779+
}
771780
};
772781

773782
// ============================================================================
@@ -778,56 +787,62 @@ export const compileManifestResultExample: CompileManifestResponse = {
778787
* Hub health check
779788
*/
780789
export const hubHealthExample: HubHealthResponse = {
781-
status: 'healthy',
782-
version: '1.0.0',
783-
uptime: 2592000, // 30 days
784-
services: {
785-
database: {
786-
status: 'healthy',
787-
latency: 3,
788-
},
789-
cache: {
790-
status: 'healthy',
791-
latency: 1,
792-
},
793-
composer: {
794-
status: 'healthy',
795-
latency: 12,
796-
},
797-
'plugin-registry': {
798-
status: 'healthy',
799-
latency: 8,
790+
success: true,
791+
data: {
792+
status: 'healthy',
793+
version: '1.0.0',
794+
uptime: 2592000, // 30 days
795+
services: {
796+
database: {
797+
status: 'healthy',
798+
latency: 3,
799+
},
800+
cache: {
801+
status: 'healthy',
802+
latency: 1,
803+
},
804+
composer: {
805+
status: 'healthy',
806+
latency: 12,
807+
},
808+
'plugin-registry': {
809+
status: 'healthy',
810+
latency: 8,
811+
},
800812
},
801-
},
802-
timestamp: '2024-01-15T12:00:00Z',
813+
timestamp: '2024-01-15T12:00:00Z',
814+
}
803815
};
804816

805817
/**
806818
* Hub metrics
807819
*/
808820
export const hubMetricsExample: HubMetricsResponse = {
809-
metrics: {
810-
spaces: {
811-
total: 2450,
812-
active: 1980,
813-
created_last_30d: 125,
814-
},
815-
tenants: {
816-
total: 580,
817-
active: 485,
818-
},
819-
plugins: {
820-
total: 342,
821-
published_last_30d: 18,
822-
total_downloads: 1245678,
823-
},
824-
api: {
825-
requests_per_minute: 1250,
826-
avg_response_time: 85,
827-
error_rate: 0.0012,
821+
success: true,
822+
data: {
823+
metrics: {
824+
spaces: {
825+
total: 2450,
826+
active: 1980,
827+
created_last_30d: 125,
828+
},
829+
tenants: {
830+
total: 580,
831+
active: 485,
832+
},
833+
plugins: {
834+
total: 342,
835+
published_last_30d: 18,
836+
total_downloads: 1245678,
837+
},
838+
api: {
839+
requests_per_minute: 1250,
840+
avg_response_time: 85,
841+
error_rate: 0.0012,
842+
},
828843
},
829-
},
830-
timestamp: '2024-01-15T12:00:00Z',
844+
timestamp: '2024-01-15T12:00:00Z',
845+
}
831846
};
832847

833848
// Uncomment to see the examples

examples/features/registry-example.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ const customerRestApi = ApiRegistryEntry.create({
8080
// Security requirements
8181
security: [
8282
{
83-
type: 'http',
84-
scheme: 'bearer',
83+
bearerAuth: [],
8584
},
8685
],
8786
}),
@@ -127,7 +126,7 @@ const customerRestApi = ApiRegistryEntry.create({
127126
},
128127
],
129128

130-
security: [{ type: 'http', scheme: 'bearer' }],
129+
security: [{ bearerAuth: [] }],
131130
}),
132131
],
133132

@@ -191,7 +190,7 @@ const graphqlApi = ApiRegistryEntry.create({
191190
},
192191
],
193192

194-
security: [{ type: 'http', scheme: 'bearer' }],
193+
security: [{ bearerAuth: [] }],
195194
}),
196195
],
197196

@@ -243,9 +242,7 @@ const pluginApi = ApiRegistryEntry.create({
243242

244243
security: [
245244
{
246-
type: 'apiKey',
247-
name: 'X-Webhook-Secret',
248-
in: 'header',
245+
webhookAuth: [],
249246
},
250247
],
251248
}),

examples/features/system-protocols-example.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ export const dailyReportJob: Job = {
5050
},
5151

5252
// Job handler
53-
handler: async () => {
54-
// Implementation: Generate and send daily sales report
55-
console.log('Generating daily sales report...');
56-
},
53+
handler: 'jobs.daily_sales_report',
5754

5855
// Retry policy
5956
retryPolicy: {
@@ -79,10 +76,7 @@ export const onAccountCreatedJob: Job = {
7976
at: new Date(Date.now() + 1000).toISOString(),
8077
},
8178

82-
handler: async () => {
83-
// Implementation: Send welcome email to new user
84-
console.log('Sending welcome email...');
85-
},
79+
handler: 'jobs.send_welcome_email',
8680

8781
timeout: 30000,
8882

@@ -107,10 +101,7 @@ export const dataCleanupJob: Job = {
107101
timezone: 'UTC',
108102
},
109103

110-
handler: async () => {
111-
// Implementation: Archive closed cases
112-
console.log('Archiving closed cases...');
113-
},
104+
handler: 'jobs.archive_closed_cases',
114105

115106
timeout: 3600000, // 1 hour
116107

0 commit comments

Comments
 (0)