@fjell/client-api 4.4.9 → 4.4.10

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.
@@ -0,0 +1,150 @@
1
+ # Fjell-Client-API Examples
2
+
3
+ This directory contains examples demonstrating how to use fjell-client-api for HTTP-based data operations and client-side API management with different patterns and complexity levels.
4
+
5
+ ## Examples
6
+
7
+ ### 1. `simple-example.ts` ⭐ **Start Here!**
8
+ **Perfect for beginners!** Demonstrates the simplest way to use fjell-client-api for HTTP data operations:
9
+ - **Basic CRUD operations** - Create, Read, Update, Delete through HTTP endpoints
10
+ - **Primary and Contained APIs** - PItemApi for independent entities, CItemApi for hierarchical data
11
+ - **Client API configuration** - HTTP endpoints, authentication, and error handling
12
+ - **Actions and facets** - Business logic execution and analytics retrieval
13
+
14
+ Great for understanding the fundamentals of fjell-client-api HTTP operations.
15
+
16
+ ### 2. `multi-level-keys.ts`
17
+ **Advanced hierarchical data models!** Demonstrates complex data structures with multi-level contained items:
18
+ - **Hierarchical models**: Organization → Department → Employee
19
+ - **Multi-level location keys**: Complex organizational structure management
20
+ - **Nested API routing**: `/organizations/{orgId}/departments/{deptId}/employees/{empId}`
21
+ - **Cross-hierarchy operations**: Complex queries spanning multiple organizational levels
22
+ - **Location-based analytics**: Department and employee-specific metrics and operations
23
+
24
+ Shows how fjell-client-api handles enterprise organizational data patterns with deep hierarchies.
25
+
26
+ ### 3. `enterprise-example.ts` 🏗️ **Full Business Application**
27
+ **Complete enterprise e-commerce system!** Demonstrates advanced business application patterns:
28
+ - **Multiple interconnected entities**: Customer, Product, Order, OrderItem, SupportTicket, ProductReview
29
+ - **Business workflow automation**: Order fulfillment, support ticket resolution, inventory management
30
+ - **Advanced analytics facets**: Customer analytics, product performance, order metrics
31
+ - **Enterprise features**: Multi-tenant configuration, complex business logic, predictive analytics
32
+ - **Real business scenarios**: Complete e-commerce platform with customer lifecycle management
33
+
34
+ Perfect for understanding how to build complete enterprise applications with fjell-client-api.
35
+
36
+ ## Key Concepts Demonstrated
37
+
38
+ ### Basic Client API Operations (simple-example.ts)
39
+ ```typescript
40
+ // Import fjell-client-api functionality
41
+ import { createPItemApi, createCItemApi } from '@fjell/client-api';
42
+
43
+ // Configure API endpoints
44
+ const apiConfig = {
45
+ baseUrl: 'http://localhost:3000/api',
46
+ headers: { 'Authorization': 'Bearer token' }
47
+ };
48
+
49
+ // Create Primary Item API (independent entities)
50
+ const userApi = createPItemApi<User, 'user'>('user', ['users'], apiConfig);
51
+
52
+ // Create Contained Item API (hierarchical entities)
53
+ const taskApi = createCItemApi<Task, 'task', 'user'>('task', ['users', 'tasks'], apiConfig);
54
+
55
+ // Basic operations
56
+ const users = await userApi.all(query);
57
+ const user = await userApi.create(userData);
58
+ const tasks = await taskApi.all(query, [userId]); // Location-based query
59
+ ```
60
+
61
+ ### Hierarchical Data Management (multi-level-keys.ts)
62
+ ```typescript
63
+ // Multi-level organizational structure
64
+ // Organization (Level 0) → Department (Level 1) → Employee (Level 2)
65
+
66
+ // Organization API (Primary Items)
67
+ const orgApi = createPItemApi<Organization, 'organization'>('organization', ['organizations'], config);
68
+
69
+ // Department API (Contained in Organization)
70
+ const deptApi = createCItemApi<Department, 'department', 'organization'>(
71
+ 'department',
72
+ ['organizations', 'departments'],
73
+ config
74
+ );
75
+
76
+ // Employee API (Contained in Department within Organization)
77
+ const empApi = createCItemApi<Employee, 'employee', 'organization', 'department'>(
78
+ 'employee',
79
+ ['organizations', 'departments', 'employees'],
80
+ config
81
+ );
82
+
83
+ // Multi-level operations
84
+ const orgLocation = [organizationId];
85
+ const deptLocation = [organizationId, departmentId];
86
+
87
+ await deptApi.all(query, orgLocation); // All departments in org
88
+ await empApi.all(query, deptLocation); // All employees in dept
89
+ ```
90
+
91
+ ### Enterprise Business Workflows (enterprise-example.ts)
92
+ ```typescript
93
+ // Customer lifecycle management
94
+ const customerApi = createPItemApi<Customer, 'customer'>('customer', ['customers'], config);
95
+ const supportApi = createCItemApi<SupportTicket, 'supportTicket', 'customer'>(
96
+ 'supportTicket',
97
+ ['customers', 'tickets'],
98
+ config
99
+ );
100
+
101
+ // Business workflow example
102
+ // 1. Create customer
103
+ const customer = await customerApi.create(customerData);
104
+
105
+ // 2. Create support ticket for customer
106
+ const ticket = await supportApi.create(ticketData, [customer.id]);
107
+
108
+ // 3. Execute business actions
109
+ await supportApi.action(ticketKey, 'escalate-ticket', { reason: 'complex issue' });
110
+ await supportApi.action(ticketKey, 'resolve-ticket', { resolution: 'provided solution' });
111
+
112
+ // 4. Get business analytics
113
+ const customerMetrics = await customerApi.facet(customerKey, 'loyalty-metrics');
114
+ const supportAnalytics = await supportApi.allFacet('resolution-metrics', {}, [customer.id]);
115
+ ```
116
+
117
+ ## Running the Examples
118
+
119
+ ### Prerequisites
120
+ ```bash
121
+ # Install dependencies
122
+ npm install
123
+
124
+ # Ensure TypeScript is available
125
+ npm install -g tsx
126
+ ```
127
+
128
+ ### Run Individual Examples
129
+ ```bash
130
+ # Simple example (start here)
131
+ npx tsx examples/simple-example.ts
132
+
133
+ # Multi-level keys example
134
+ npx tsx examples/multi-level-keys.ts
135
+
136
+ # Enterprise example (most comprehensive)
137
+ npx tsx examples/enterprise-example.ts
138
+ ```
139
+
140
+ ## Next Steps
141
+
142
+ After exploring these examples:
143
+
144
+ 1. **Read the API Documentation** - Understand the full fjell-client-api specification
145
+ 2. **Set up your HTTP backend** - Implement corresponding server endpoints
146
+ 3. **Configure authentication** - Set up proper API authentication for your application
147
+ 4. **Implement error handling** - Add comprehensive error handling for production use
148
+ 5. **Add monitoring** - Implement logging and monitoring for API operations
149
+ 6. **Write tests** - Create tests for your specific API usage patterns
150
+ 7. **Optimize performance** - Add caching, pagination, and other performance optimizations
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@fjell/client-api",
3
+ "version": "4.4.9",
4
+ "description": "Client API for Fjell"
5
+ }