@fjell/client-api 4.4.6 ā 4.4.7
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.
- package/dist/Instance.d.ts +19 -0
- package/dist/Instance.js +19 -0
- package/dist/Instance.js.map +1 -0
- package/dist/InstanceFactory.d.ts +8 -0
- package/dist/InstanceFactory.js +19 -0
- package/dist/InstanceFactory.js.map +1 -0
- package/dist/Registry.d.ts +15 -0
- package/dist/Registry.js +31 -0
- package/dist/Registry.js.map +1 -0
- package/dist/index.cjs +106 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/examples/README.md +387 -0
- package/examples/enterprise-example.ts +852 -0
- package/examples/multi-level-keys.ts +467 -0
- package/examples/simple-example.ts +346 -0
- package/package.json +4 -3
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
/* eslint-disable no-undefined */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
/**
|
|
4
|
+
* Enterprise Fjell-Client-API Example - Complete Business Application
|
|
5
|
+
*
|
|
6
|
+
* This example demonstrates a comprehensive enterprise application using fjell-client-api
|
|
7
|
+
* for a complete e-commerce platform with customer management, order processing,
|
|
8
|
+
* and support systems.
|
|
9
|
+
*
|
|
10
|
+
* This enterprise example covers:
|
|
11
|
+
* - Multiple interconnected business entities
|
|
12
|
+
* - Complex business workflows and state management
|
|
13
|
+
* - Customer order lifecycle management
|
|
14
|
+
* - Support ticket and resolution tracking
|
|
15
|
+
* - Product catalog and inventory management
|
|
16
|
+
* - Analytics and business intelligence facets
|
|
17
|
+
* - Real-world business logic patterns
|
|
18
|
+
*
|
|
19
|
+
* Run this example with: npx tsx examples/enterprise-example.ts
|
|
20
|
+
*
|
|
21
|
+
* Note: This is a conceptual example showing enterprise API patterns.
|
|
22
|
+
* In production, use actual fjell-client-api with proper types.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Enterprise E-Commerce Platform Architecture:
|
|
27
|
+
*
|
|
28
|
+
* Primary Entities:
|
|
29
|
+
* - Customer (Primary) - Customer profiles and account management
|
|
30
|
+
* - Product (Primary) - Product catalog and inventory
|
|
31
|
+
* - Order (Primary) - Order processing and fulfillment
|
|
32
|
+
*
|
|
33
|
+
* Contained Entities:
|
|
34
|
+
* - OrderItem (Contained in Order) - Individual items within orders
|
|
35
|
+
* - SupportTicket (Contained in Customer) - Customer support cases
|
|
36
|
+
* - ProductReview (Contained in Product) - Customer product reviews
|
|
37
|
+
*
|
|
38
|
+
* API Structure:
|
|
39
|
+
* - /customers/{customerId}
|
|
40
|
+
* - /customers/{customerId}/tickets/{ticketId}
|
|
41
|
+
* - /products/{productId}
|
|
42
|
+
* - /products/{productId}/reviews/{reviewId}
|
|
43
|
+
* - /orders/{orderId}
|
|
44
|
+
* - /orders/{orderId}/items/{itemId}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// ===== Enterprise Mock API Implementation =====
|
|
48
|
+
|
|
49
|
+
interface EnterpriseApiBase {
|
|
50
|
+
all(query: any, locations?: any[]): Promise<any[]>;
|
|
51
|
+
create(item: any, locations?: any[]): Promise<any>;
|
|
52
|
+
get(key: any): Promise<any>;
|
|
53
|
+
update(key: any, updates: any): Promise<any>;
|
|
54
|
+
remove(key: any): Promise<boolean>;
|
|
55
|
+
action(key: any, action: string, body?: any): Promise<any>;
|
|
56
|
+
find(finder: string, params?: any, locations?: any[]): Promise<any[]>;
|
|
57
|
+
facet(key: any, facet: string, params?: any): Promise<any>;
|
|
58
|
+
allAction(action: string, body?: any, locations?: any[]): Promise<any[]>;
|
|
59
|
+
allFacet(facet: string, params?: any, locations?: any[]): Promise<any>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const createEnterpriseApi = (entityType: string, isContained: boolean = false): EnterpriseApiBase => {
|
|
63
|
+
const mockData = new Map();
|
|
64
|
+
let idCounter = 1;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
async all(query: any, locations?: any[]) {
|
|
68
|
+
const locationInfo = locations ? ` in ${locations.join('/')}` : '';
|
|
69
|
+
console.log(`š Enterprise.all(${entityType})${locationInfo} - query:`, query);
|
|
70
|
+
|
|
71
|
+
// Generate realistic mock data based on entity type
|
|
72
|
+
const items = Array.from({ length: Math.floor(Math.random() * 5) + 2 }, (_, i) =>
|
|
73
|
+
generateMockData(entityType, i + 1, locations)
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return items;
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
async create(item: any, locations?: any[]) {
|
|
80
|
+
const id = `${entityType}-${Date.now()}-${idCounter++}`;
|
|
81
|
+
const created = {
|
|
82
|
+
...item,
|
|
83
|
+
id,
|
|
84
|
+
createdAt: new Date(),
|
|
85
|
+
updatedAt: new Date(),
|
|
86
|
+
...(locations && { parentPath: locations })
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
mockData.set(id, created);
|
|
90
|
+
|
|
91
|
+
const locationInfo = locations ? ` in ${locations.join('/')}` : '';
|
|
92
|
+
console.log(`ā Enterprise.create(${entityType})${locationInfo} - created:`, id);
|
|
93
|
+
|
|
94
|
+
return created;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
async get(key: any) {
|
|
98
|
+
console.log(`š Enterprise.get(${entityType}) - key:`, key.id);
|
|
99
|
+
|
|
100
|
+
const existing = mockData.get(key.id);
|
|
101
|
+
if (existing) {
|
|
102
|
+
return existing;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Generate mock data if not exists
|
|
106
|
+
return generateMockData(entityType, 1, undefined, key.id);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
async update(key: any, updates: any) {
|
|
110
|
+
console.log(`āļø Enterprise.update(${entityType}) - key:`, key.id, 'updates:', Object.keys(updates));
|
|
111
|
+
|
|
112
|
+
const existing = mockData.get(key.id) || generateMockData(entityType, 1, undefined, key.id);
|
|
113
|
+
const updated = {
|
|
114
|
+
...existing,
|
|
115
|
+
...updates,
|
|
116
|
+
updatedAt: new Date()
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
mockData.set(key.id, updated);
|
|
120
|
+
return updated;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
async remove(key: any) {
|
|
124
|
+
console.log(`šļø Enterprise.remove(${entityType}) - key:`, key.id);
|
|
125
|
+
mockData.delete(key.id);
|
|
126
|
+
return true;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
async action(key: any, action: string, body?: any) {
|
|
130
|
+
console.log(`ā” Enterprise.action(${entityType}) - action:`, action, 'on:', key.id);
|
|
131
|
+
|
|
132
|
+
// Simulate business logic based on action
|
|
133
|
+
const result = simulateBusinessAction(entityType, action, body);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
action,
|
|
138
|
+
entityType,
|
|
139
|
+
entityId: key.id,
|
|
140
|
+
result,
|
|
141
|
+
timestamp: new Date()
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
async find(finder: string, params?: any, locations?: any[]) {
|
|
146
|
+
const locationInfo = locations ? ` in ${locations.join('/')}` : '';
|
|
147
|
+
console.log(`š Enterprise.find(${entityType})${locationInfo} - finder:`, finder, 'params:', params);
|
|
148
|
+
|
|
149
|
+
const results = Array.from({ length: Math.floor(Math.random() * 3) + 1 }, (_, i) =>
|
|
150
|
+
generateMockData(entityType, i + 1, locations)
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return results;
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
async facet(key: any, facet: string, params?: any) {
|
|
157
|
+
console.log(`š Enterprise.facet(${entityType}) - facet:`, facet, 'on:', key.id);
|
|
158
|
+
|
|
159
|
+
return generateBusinessFacet(entityType, facet, params, key.id);
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
async allAction(action: string, body?: any, locations?: any[]) {
|
|
163
|
+
const locationInfo = locations ? ` in ${locations.join('/')}` : '';
|
|
164
|
+
console.log(`š¦ Enterprise.allAction(${entityType})${locationInfo} - action:`, action);
|
|
165
|
+
|
|
166
|
+
const affectedCount = Math.floor(Math.random() * 10) + 1;
|
|
167
|
+
return Array.from({ length: affectedCount }, (_, i) => ({
|
|
168
|
+
id: `${entityType}-${i + 1}`,
|
|
169
|
+
action,
|
|
170
|
+
result: 'updated',
|
|
171
|
+
timestamp: new Date()
|
|
172
|
+
}));
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
async allFacet(facet: string, params?: any, locations?: any[]) {
|
|
176
|
+
const locationInfo = locations ? ` in ${locations.join('/')}` : '';
|
|
177
|
+
console.log(`š Enterprise.allFacet(${entityType})${locationInfo} - facet:`, facet);
|
|
178
|
+
|
|
179
|
+
return generateAggregatedFacet(entityType, facet, params, locations);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// ===== Mock Data Generators =====
|
|
185
|
+
|
|
186
|
+
function generateMockData(entityType: string, index: number, locations?: any[], id?: string): any {
|
|
187
|
+
const baseId = id || `${entityType}-${index}`;
|
|
188
|
+
const timestamp = new Date();
|
|
189
|
+
|
|
190
|
+
switch (entityType) {
|
|
191
|
+
case 'customer':
|
|
192
|
+
return {
|
|
193
|
+
id: baseId,
|
|
194
|
+
name: `Customer ${index}`,
|
|
195
|
+
email: `customer${index}@example.com`,
|
|
196
|
+
type: ['individual', 'business'][index % 2],
|
|
197
|
+
status: 'active',
|
|
198
|
+
joinedAt: timestamp,
|
|
199
|
+
totalOrders: Math.floor(Math.random() * 50),
|
|
200
|
+
lifetimeValue: Math.floor(Math.random() * 10000) + 1000,
|
|
201
|
+
tier: ['bronze', 'silver', 'gold', 'platinum'][index % 4],
|
|
202
|
+
keyType: 'customer'
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
case 'product':
|
|
206
|
+
return {
|
|
207
|
+
id: baseId,
|
|
208
|
+
name: `Product ${index}`,
|
|
209
|
+
sku: `SKU-${baseId}`,
|
|
210
|
+
category: ['electronics', 'clothing', 'books', 'home'][index % 4],
|
|
211
|
+
price: Math.floor(Math.random() * 500) + 10,
|
|
212
|
+
stock: Math.floor(Math.random() * 100),
|
|
213
|
+
rating: (Math.random() * 2 + 3).toFixed(1), // 3.0 - 5.0
|
|
214
|
+
reviewCount: Math.floor(Math.random() * 200),
|
|
215
|
+
keyType: 'product'
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
case 'order':
|
|
219
|
+
return {
|
|
220
|
+
id: baseId,
|
|
221
|
+
customerId: `customer-${Math.floor(Math.random() * 5) + 1}`,
|
|
222
|
+
status: ['pending', 'processing', 'shipped', 'delivered'][index % 4],
|
|
223
|
+
total: Math.floor(Math.random() * 1000) + 50,
|
|
224
|
+
itemCount: Math.floor(Math.random() * 5) + 1,
|
|
225
|
+
orderDate: timestamp,
|
|
226
|
+
shippingAddress: `${index} Main St, City, State`,
|
|
227
|
+
keyType: 'order'
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
case 'orderItem':
|
|
231
|
+
return {
|
|
232
|
+
id: baseId,
|
|
233
|
+
productId: `product-${Math.floor(Math.random() * 10) + 1}`,
|
|
234
|
+
productName: `Product ${index}`,
|
|
235
|
+
quantity: Math.floor(Math.random() * 3) + 1,
|
|
236
|
+
unitPrice: Math.floor(Math.random() * 200) + 10,
|
|
237
|
+
total: 0, // Will be calculated
|
|
238
|
+
keyType: 'orderItem',
|
|
239
|
+
parentPath: locations
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
case 'supportTicket':
|
|
243
|
+
return {
|
|
244
|
+
id: baseId,
|
|
245
|
+
subject: `Support Issue ${index}`,
|
|
246
|
+
category: ['technical', 'billing', 'shipping', 'returns'][index % 4],
|
|
247
|
+
priority: ['low', 'medium', 'high', 'critical'][index % 4],
|
|
248
|
+
status: ['open', 'in-progress', 'resolved', 'closed'][index % 4],
|
|
249
|
+
description: `Customer support ticket description ${index}`,
|
|
250
|
+
assignedAgent: `agent-${Math.floor(Math.random() * 5) + 1}`,
|
|
251
|
+
createdAt: timestamp,
|
|
252
|
+
keyType: 'supportTicket',
|
|
253
|
+
parentPath: locations
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
case 'productReview':
|
|
257
|
+
return {
|
|
258
|
+
id: baseId,
|
|
259
|
+
customerId: `customer-${Math.floor(Math.random() * 10) + 1}`,
|
|
260
|
+
rating: Math.floor(Math.random() * 5) + 1,
|
|
261
|
+
title: `Review Title ${index}`,
|
|
262
|
+
content: `Review content for product ${index}`,
|
|
263
|
+
verified: Math.random() > 0.3,
|
|
264
|
+
helpful: Math.floor(Math.random() * 20),
|
|
265
|
+
createdAt: timestamp,
|
|
266
|
+
keyType: 'productReview',
|
|
267
|
+
parentPath: locations
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
default:
|
|
271
|
+
return { id: baseId, name: `${entityType} ${index}`, keyType: entityType };
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function simulateBusinessAction(entityType: string, action: string, body?: any): any {
|
|
276
|
+
const actionResults = {
|
|
277
|
+
customer: {
|
|
278
|
+
'upgrade-tier': { newTier: 'gold', benefits: ['free-shipping', 'priority-support'] },
|
|
279
|
+
'suspend-account': { status: 'suspended', reason: body?.reason },
|
|
280
|
+
'send-promotion': { sent: true, promoCode: 'SAVE20' }
|
|
281
|
+
},
|
|
282
|
+
product: {
|
|
283
|
+
'update-inventory': { newStock: (body?.quantity || 100), lastUpdated: new Date() },
|
|
284
|
+
'apply-discount': { discountPercent: body?.percent || 10, validUntil: new Date() },
|
|
285
|
+
'mark-featured': { featured: true, featuredUntil: new Date() }
|
|
286
|
+
},
|
|
287
|
+
order: {
|
|
288
|
+
'fulfill-order': { status: 'fulfilled', trackingNumber: `TRK-${Date.now()}` },
|
|
289
|
+
'cancel-order': { status: 'cancelled', refundAmount: body?.amount },
|
|
290
|
+
'expedite-shipping': { newShippingMethod: 'express', estimatedDelivery: new Date() }
|
|
291
|
+
},
|
|
292
|
+
orderItem: {
|
|
293
|
+
'update-quantity': { newQuantity: body?.quantity, priceAdjusted: true },
|
|
294
|
+
'apply-item-discount': { discountAmount: body?.discount }
|
|
295
|
+
},
|
|
296
|
+
supportTicket: {
|
|
297
|
+
'escalate-ticket': { escalatedTo: 'senior-support', priority: 'high' },
|
|
298
|
+
'resolve-ticket': { resolution: body?.resolution, resolvedAt: new Date() },
|
|
299
|
+
'assign-agent': { assignedTo: body?.agentId }
|
|
300
|
+
},
|
|
301
|
+
productReview: {
|
|
302
|
+
'moderate-review': { status: body?.action, moderatedBy: 'admin' },
|
|
303
|
+
'mark-helpful': { helpfulCount: (body?.currentCount || 0) + 1 }
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// @ts-ignore
|
|
308
|
+
return actionResults[entityType]?.[action] || { action, completed: true };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function generateBusinessFacet(entityType: string, facet: string, params?: any, entityId?: string): any {
|
|
312
|
+
const baseFacets = {
|
|
313
|
+
customer: {
|
|
314
|
+
'purchase-history': {
|
|
315
|
+
totalOrders: Math.floor(Math.random() * 20) + 5,
|
|
316
|
+
totalSpent: Math.floor(Math.random() * 5000) + 500,
|
|
317
|
+
averageOrderValue: Math.floor(Math.random() * 200) + 50,
|
|
318
|
+
favoriteCategories: ['electronics', 'books'],
|
|
319
|
+
lastPurchase: new Date()
|
|
320
|
+
},
|
|
321
|
+
'loyalty-metrics': {
|
|
322
|
+
loyaltyPoints: Math.floor(Math.random() * 1000),
|
|
323
|
+
tier: 'gold',
|
|
324
|
+
nextTierRequirement: 200,
|
|
325
|
+
rewardsEarned: Math.floor(Math.random() * 50)
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
product: {
|
|
329
|
+
'performance-metrics': {
|
|
330
|
+
totalSales: Math.floor(Math.random() * 1000),
|
|
331
|
+
revenue: Math.floor(Math.random() * 50000),
|
|
332
|
+
averageRating: (Math.random() * 2 + 3).toFixed(1),
|
|
333
|
+
returnRate: (Math.random() * 0.1).toFixed(3)
|
|
334
|
+
},
|
|
335
|
+
'inventory-analytics': {
|
|
336
|
+
currentStock: Math.floor(Math.random() * 100),
|
|
337
|
+
reorderPoint: 20,
|
|
338
|
+
turnoverRate: (Math.random() * 5 + 1).toFixed(2),
|
|
339
|
+
daysOfSupply: Math.floor(Math.random() * 30) + 10
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
order: {
|
|
343
|
+
'fulfillment-status': {
|
|
344
|
+
stage: 'processing',
|
|
345
|
+
estimatedDelivery: new Date(),
|
|
346
|
+
trackingEvents: [
|
|
347
|
+
{ timestamp: new Date(), event: 'Order received' },
|
|
348
|
+
{ timestamp: new Date(), event: 'Processing started' }
|
|
349
|
+
]
|
|
350
|
+
},
|
|
351
|
+
'financial-breakdown': {
|
|
352
|
+
subtotal: Math.floor(Math.random() * 500) + 50,
|
|
353
|
+
tax: Math.floor(Math.random() * 50) + 5,
|
|
354
|
+
shipping: Math.floor(Math.random() * 20) + 5,
|
|
355
|
+
discounts: Math.floor(Math.random() * 30),
|
|
356
|
+
total: Math.floor(Math.random() * 600) + 100
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// @ts-ignore
|
|
362
|
+
return baseFacets[entityType]?.[facet] || { facet, data: 'Mock facet data', timestamp: new Date() };
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function generateAggregatedFacet(entityType: string, facet: string, params?: any, locations?: any[]): any {
|
|
366
|
+
const aggregatedFacets = {
|
|
367
|
+
customer: {
|
|
368
|
+
'revenue-analytics': {
|
|
369
|
+
totalRevenue: Math.floor(Math.random() * 100000) + 50000,
|
|
370
|
+
averageCustomerValue: Math.floor(Math.random() * 500) + 200,
|
|
371
|
+
customerCount: Math.floor(Math.random() * 1000) + 500,
|
|
372
|
+
growthRate: (Math.random() * 0.2 + 0.05).toFixed(3)
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
product: {
|
|
376
|
+
'catalog-analytics': {
|
|
377
|
+
totalProducts: Math.floor(Math.random() * 500) + 100,
|
|
378
|
+
categoriesCount: Math.floor(Math.random() * 20) + 5,
|
|
379
|
+
averagePrice: Math.floor(Math.random() * 100) + 50,
|
|
380
|
+
topCategories: ['electronics', 'clothing', 'books']
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
order: {
|
|
384
|
+
'order-analytics': {
|
|
385
|
+
totalOrders: Math.floor(Math.random() * 10000) + 1000,
|
|
386
|
+
averageOrderValue: Math.floor(Math.random() * 150) + 75,
|
|
387
|
+
conversionRate: (Math.random() * 0.1 + 0.02).toFixed(3),
|
|
388
|
+
fulfillmentRate: (Math.random() * 0.1 + 0.9).toFixed(3)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// @ts-ignore
|
|
394
|
+
return aggregatedFacets[entityType]?.[facet] || {
|
|
395
|
+
facet,
|
|
396
|
+
aggregatedData: 'Mock aggregated data',
|
|
397
|
+
timestamp: new Date(),
|
|
398
|
+
locations
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ===== Enterprise Business Workflows =====
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Customer Management Workflow
|
|
406
|
+
*/
|
|
407
|
+
async function demonstrateCustomerManagement() {
|
|
408
|
+
console.log('\nš === Customer Management Workflow ===');
|
|
409
|
+
|
|
410
|
+
const customerApi = createEnterpriseApi('customer');
|
|
411
|
+
const supportTicketApi = createEnterpriseApi('supportTicket', true);
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
// 1. Customer lifecycle management
|
|
415
|
+
console.log('\nš„ Customer lifecycle management...');
|
|
416
|
+
|
|
417
|
+
// Create new customers
|
|
418
|
+
const customers = await Promise.all([
|
|
419
|
+
customerApi.create({
|
|
420
|
+
name: 'John Enterprise',
|
|
421
|
+
email: 'john@enterprise.com',
|
|
422
|
+
type: 'business',
|
|
423
|
+
company: 'Enterprise Corp'
|
|
424
|
+
}),
|
|
425
|
+
customerApi.create({
|
|
426
|
+
name: 'Jane Consumer',
|
|
427
|
+
email: 'jane@consumer.com',
|
|
428
|
+
type: 'individual'
|
|
429
|
+
})
|
|
430
|
+
]);
|
|
431
|
+
|
|
432
|
+
console.log(`Created ${customers.length} customers`);
|
|
433
|
+
|
|
434
|
+
// 2. Customer analytics and segmentation
|
|
435
|
+
console.log('\nš Customer analytics and segmentation...');
|
|
436
|
+
|
|
437
|
+
const customerAnalytics = await customerApi.allFacet('revenue-analytics', {
|
|
438
|
+
period: 'quarterly',
|
|
439
|
+
segmentation: true
|
|
440
|
+
});
|
|
441
|
+
console.log('Customer analytics:', customerAnalytics);
|
|
442
|
+
|
|
443
|
+
// 3. Support ticket management
|
|
444
|
+
console.log('\nš« Support ticket management...');
|
|
445
|
+
|
|
446
|
+
const businessCustomer = customers[0];
|
|
447
|
+
const customerLocation = [businessCustomer.id];
|
|
448
|
+
|
|
449
|
+
// Create support tickets
|
|
450
|
+
const tickets = await Promise.all([
|
|
451
|
+
supportTicketApi.create({
|
|
452
|
+
subject: 'API Integration Issue',
|
|
453
|
+
category: 'technical',
|
|
454
|
+
priority: 'high',
|
|
455
|
+
description: 'Having trouble with API authentication'
|
|
456
|
+
}, customerLocation),
|
|
457
|
+
supportTicketApi.create({
|
|
458
|
+
subject: 'Billing Inquiry',
|
|
459
|
+
category: 'billing',
|
|
460
|
+
priority: 'medium',
|
|
461
|
+
description: 'Question about enterprise plan pricing'
|
|
462
|
+
}, customerLocation)
|
|
463
|
+
]);
|
|
464
|
+
|
|
465
|
+
console.log(`Created ${tickets.length} support tickets for ${businessCustomer.name}`);
|
|
466
|
+
|
|
467
|
+
// 4. Ticket resolution workflow
|
|
468
|
+
console.log('\nš§ Ticket resolution workflow...');
|
|
469
|
+
|
|
470
|
+
const technicalTicket = tickets[0];
|
|
471
|
+
const ticketKey = { keyType: 'supportTicket', id: technicalTicket.id };
|
|
472
|
+
|
|
473
|
+
// Assign ticket to agent
|
|
474
|
+
await supportTicketApi.action(ticketKey, 'assign-agent', {
|
|
475
|
+
agentId: 'agent-senior-001'
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// Escalate if needed
|
|
479
|
+
await supportTicketApi.action(ticketKey, 'escalate-ticket', {
|
|
480
|
+
reason: 'Complex technical issue requiring senior expertise'
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
// Resolve ticket
|
|
484
|
+
await supportTicketApi.action(ticketKey, 'resolve-ticket', {
|
|
485
|
+
resolution: 'Provided updated API documentation and auth examples'
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
console.log('Ticket resolution workflow completed');
|
|
489
|
+
|
|
490
|
+
// 5. Customer tier management
|
|
491
|
+
console.log('\nā Customer tier management...');
|
|
492
|
+
|
|
493
|
+
const customerKey = { keyType: 'customer', id: businessCustomer.id };
|
|
494
|
+
|
|
495
|
+
// Check customer loyalty metrics
|
|
496
|
+
const loyaltyMetrics = await customerApi.facet(customerKey, 'loyalty-metrics');
|
|
497
|
+
console.log('Customer loyalty:', loyaltyMetrics);
|
|
498
|
+
|
|
499
|
+
// Upgrade customer tier
|
|
500
|
+
await customerApi.action(customerKey, 'upgrade-tier', {
|
|
501
|
+
newTier: 'platinum',
|
|
502
|
+
reason: 'High volume business customer'
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
console.log('Customer tier upgraded to platinum');
|
|
506
|
+
|
|
507
|
+
return customers.map(c => c.id);
|
|
508
|
+
|
|
509
|
+
} catch (error) {
|
|
510
|
+
console.error('ā Error in customer management:', error);
|
|
511
|
+
return [];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Product Catalog and Inventory Management
|
|
517
|
+
*/
|
|
518
|
+
async function demonstrateProductManagement() {
|
|
519
|
+
console.log('\nš === Product Catalog and Inventory Management ===');
|
|
520
|
+
|
|
521
|
+
const productApi = createEnterpriseApi('product');
|
|
522
|
+
const reviewApi = createEnterpriseApi('productReview', true);
|
|
523
|
+
|
|
524
|
+
try {
|
|
525
|
+
// 1. Product catalog setup
|
|
526
|
+
console.log('\nš¦ Product catalog setup...');
|
|
527
|
+
|
|
528
|
+
const products = await Promise.all([
|
|
529
|
+
productApi.create({
|
|
530
|
+
name: 'Enterprise Laptop Pro',
|
|
531
|
+
sku: 'ELP-2024-001',
|
|
532
|
+
category: 'electronics',
|
|
533
|
+
price: 2499.99,
|
|
534
|
+
stock: 50,
|
|
535
|
+
description: 'High-performance laptop for enterprise users'
|
|
536
|
+
}),
|
|
537
|
+
productApi.create({
|
|
538
|
+
name: 'Business Software Suite',
|
|
539
|
+
sku: 'BSS-2024-001',
|
|
540
|
+
category: 'software',
|
|
541
|
+
price: 499.99,
|
|
542
|
+
stock: 1000, // Digital product
|
|
543
|
+
description: 'Comprehensive business productivity software'
|
|
544
|
+
})
|
|
545
|
+
]);
|
|
546
|
+
|
|
547
|
+
console.log(`Added ${products.length} products to catalog`);
|
|
548
|
+
|
|
549
|
+
// 2. Inventory management
|
|
550
|
+
console.log('\nš Inventory management...');
|
|
551
|
+
|
|
552
|
+
const laptopProduct = products[0];
|
|
553
|
+
const productKey = { keyType: 'product', id: laptopProduct.id };
|
|
554
|
+
|
|
555
|
+
// Get inventory analytics
|
|
556
|
+
const inventoryAnalytics = await productApi.facet(productKey, 'inventory-analytics');
|
|
557
|
+
console.log('Inventory analytics:', inventoryAnalytics);
|
|
558
|
+
|
|
559
|
+
// Update inventory
|
|
560
|
+
await productApi.action(productKey, 'update-inventory', {
|
|
561
|
+
quantity: 75,
|
|
562
|
+
reason: 'New shipment received'
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
// Set reorder alerts
|
|
566
|
+
await productApi.action(productKey, 'set-reorder-alert', {
|
|
567
|
+
threshold: 20,
|
|
568
|
+
autoReorder: true
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
console.log('Inventory management configured');
|
|
572
|
+
|
|
573
|
+
// 3. Product reviews and ratings
|
|
574
|
+
console.log('\nā Product reviews and ratings...');
|
|
575
|
+
|
|
576
|
+
const productLocation = [laptopProduct.id];
|
|
577
|
+
|
|
578
|
+
// Add customer reviews
|
|
579
|
+
const reviews = await Promise.all([
|
|
580
|
+
reviewApi.create({
|
|
581
|
+
customerId: 'customer-1',
|
|
582
|
+
rating: 5,
|
|
583
|
+
title: 'Excellent Performance',
|
|
584
|
+
content: 'Great laptop for enterprise work, fast and reliable.',
|
|
585
|
+
verified: true
|
|
586
|
+
}, productLocation),
|
|
587
|
+
reviewApi.create({
|
|
588
|
+
customerId: 'customer-2',
|
|
589
|
+
rating: 4,
|
|
590
|
+
title: 'Good Value',
|
|
591
|
+
content: 'Solid laptop, good value for the price.',
|
|
592
|
+
verified: true
|
|
593
|
+
}, productLocation)
|
|
594
|
+
]);
|
|
595
|
+
|
|
596
|
+
console.log(`Added ${reviews.length} product reviews`);
|
|
597
|
+
|
|
598
|
+
// 4. Product performance analytics
|
|
599
|
+
console.log('\nš Product performance analytics...');
|
|
600
|
+
|
|
601
|
+
const performanceMetrics = await productApi.facet(productKey, 'performance-metrics');
|
|
602
|
+
console.log('Product performance:', performanceMetrics);
|
|
603
|
+
|
|
604
|
+
// 5. Catalog-wide analytics
|
|
605
|
+
console.log('\nš Catalog-wide analytics...');
|
|
606
|
+
|
|
607
|
+
const catalogAnalytics = await productApi.allFacet('catalog-analytics', {
|
|
608
|
+
includeCategories: true,
|
|
609
|
+
includeTrends: true
|
|
610
|
+
});
|
|
611
|
+
console.log('Catalog analytics:', catalogAnalytics);
|
|
612
|
+
|
|
613
|
+
return products.map(p => p.id);
|
|
614
|
+
|
|
615
|
+
} catch (error) {
|
|
616
|
+
console.error('ā Error in product management:', error);
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Order Processing and Fulfillment Workflow
|
|
623
|
+
*/
|
|
624
|
+
async function demonstrateOrderManagement(customerIds: string[], productIds: string[]) {
|
|
625
|
+
console.log('\nš === Order Processing and Fulfillment Workflow ===');
|
|
626
|
+
|
|
627
|
+
const orderApi = createEnterpriseApi('order');
|
|
628
|
+
const orderItemApi = createEnterpriseApi('orderItem', true);
|
|
629
|
+
|
|
630
|
+
try {
|
|
631
|
+
// 1. Order creation and processing
|
|
632
|
+
console.log('\nš Order creation and processing...');
|
|
633
|
+
|
|
634
|
+
const customerId = customerIds[0];
|
|
635
|
+
const productId = productIds[0];
|
|
636
|
+
|
|
637
|
+
// Create order
|
|
638
|
+
const order = await orderApi.create({
|
|
639
|
+
customerId: customerId,
|
|
640
|
+
shippingAddress: '123 Enterprise Blvd, Business City, BC 12345',
|
|
641
|
+
billingAddress: '123 Enterprise Blvd, Business City, BC 12345',
|
|
642
|
+
paymentMethod: 'corporate-card',
|
|
643
|
+
notes: 'Expedited delivery requested'
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
console.log(`Created order: ${order.id}`);
|
|
647
|
+
|
|
648
|
+
// 2. Add order items
|
|
649
|
+
console.log('\nš Adding order items...');
|
|
650
|
+
|
|
651
|
+
const orderLocation = [order.id];
|
|
652
|
+
|
|
653
|
+
const orderItems = await Promise.all([
|
|
654
|
+
orderItemApi.create({
|
|
655
|
+
productId: productId,
|
|
656
|
+
productName: 'Enterprise Laptop Pro',
|
|
657
|
+
quantity: 2,
|
|
658
|
+
unitPrice: 2499.99
|
|
659
|
+
}, orderLocation),
|
|
660
|
+
orderItemApi.create({
|
|
661
|
+
productId: productIds[1] || 'product-software',
|
|
662
|
+
productName: 'Business Software Suite',
|
|
663
|
+
quantity: 1,
|
|
664
|
+
unitPrice: 499.99
|
|
665
|
+
}, orderLocation)
|
|
666
|
+
]);
|
|
667
|
+
|
|
668
|
+
console.log(`Added ${orderItems.length} items to order`);
|
|
669
|
+
|
|
670
|
+
// 3. Order fulfillment workflow
|
|
671
|
+
console.log('\nš Order fulfillment workflow...');
|
|
672
|
+
|
|
673
|
+
const orderKey = { keyType: 'order', id: order.id };
|
|
674
|
+
|
|
675
|
+
// Process payment
|
|
676
|
+
await orderApi.action(orderKey, 'process-payment', {
|
|
677
|
+
amount: 5499.97, // 2 * 2499.99 + 499.99
|
|
678
|
+
paymentMethod: 'corporate-card'
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
// Check inventory and reserve items
|
|
682
|
+
await orderApi.action(orderKey, 'reserve-inventory', {
|
|
683
|
+
items: orderItems.map(item => ({
|
|
684
|
+
productId: item.productId,
|
|
685
|
+
quantity: item.quantity
|
|
686
|
+
}))
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
// Fulfill order
|
|
690
|
+
await orderApi.action(orderKey, 'fulfill-order', {
|
|
691
|
+
warehouse: 'main-warehouse',
|
|
692
|
+
shippingMethod: 'express'
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
console.log('Order fulfillment completed');
|
|
696
|
+
|
|
697
|
+
// 4. Order tracking and analytics
|
|
698
|
+
console.log('\nš Order tracking and analytics...');
|
|
699
|
+
|
|
700
|
+
// Get fulfillment status
|
|
701
|
+
const fulfillmentStatus = await orderApi.facet(orderKey, 'fulfillment-status');
|
|
702
|
+
console.log('Fulfillment status:', fulfillmentStatus);
|
|
703
|
+
|
|
704
|
+
// Get financial breakdown
|
|
705
|
+
const financialBreakdown = await orderApi.facet(orderKey, 'financial-breakdown');
|
|
706
|
+
console.log('Financial breakdown:', financialBreakdown);
|
|
707
|
+
|
|
708
|
+
// 5. Order analytics across all orders
|
|
709
|
+
console.log('\nš Order analytics...');
|
|
710
|
+
|
|
711
|
+
const orderAnalytics = await orderApi.allFacet('order-analytics', {
|
|
712
|
+
period: 'monthly',
|
|
713
|
+
includeProjections: true
|
|
714
|
+
});
|
|
715
|
+
console.log('Order analytics:', orderAnalytics);
|
|
716
|
+
|
|
717
|
+
return [order.id];
|
|
718
|
+
|
|
719
|
+
} catch (error) {
|
|
720
|
+
console.error('ā Error in order management:', error);
|
|
721
|
+
return [];
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Business Intelligence and Reporting
|
|
727
|
+
*/
|
|
728
|
+
async function demonstrateBusinessIntelligence() {
|
|
729
|
+
console.log('\nš === Business Intelligence and Reporting ===');
|
|
730
|
+
|
|
731
|
+
const customerApi = createEnterpriseApi('customer');
|
|
732
|
+
const productApi = createEnterpriseApi('product');
|
|
733
|
+
const orderApi = createEnterpriseApi('order');
|
|
734
|
+
|
|
735
|
+
try {
|
|
736
|
+
// 1. Cross-entity analytics
|
|
737
|
+
console.log('\nš Cross-entity analytics...');
|
|
738
|
+
|
|
739
|
+
// Customer revenue analytics
|
|
740
|
+
const customerRevenue = await customerApi.allFacet('revenue-analytics', {
|
|
741
|
+
period: 'quarterly',
|
|
742
|
+
segmentation: ['tier', 'type']
|
|
743
|
+
});
|
|
744
|
+
console.log('Customer revenue analytics:', customerRevenue);
|
|
745
|
+
|
|
746
|
+
// Product performance analytics
|
|
747
|
+
const productPerformance = await productApi.allFacet('catalog-analytics', {
|
|
748
|
+
period: 'monthly',
|
|
749
|
+
metrics: ['sales', 'profit-margin', 'inventory-turnover']
|
|
750
|
+
});
|
|
751
|
+
console.log('Product performance analytics:', productPerformance);
|
|
752
|
+
|
|
753
|
+
// Order fulfillment analytics
|
|
754
|
+
const fulfillmentMetrics = await orderApi.allFacet('order-analytics', {
|
|
755
|
+
period: 'weekly',
|
|
756
|
+
metrics: ['fulfillment-rate', 'shipping-time', 'customer-satisfaction']
|
|
757
|
+
});
|
|
758
|
+
console.log('Fulfillment analytics:', fulfillmentMetrics);
|
|
759
|
+
|
|
760
|
+
// 2. Predictive analytics simulation
|
|
761
|
+
console.log('\nš® Predictive analytics simulation...');
|
|
762
|
+
|
|
763
|
+
// Simulate demand forecasting
|
|
764
|
+
await productApi.allAction('forecast-demand', {
|
|
765
|
+
period: 'next-quarter',
|
|
766
|
+
factors: ['seasonal', 'trends', 'promotions']
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
// Simulate customer churn prediction
|
|
770
|
+
await customerApi.allAction('predict-churn', {
|
|
771
|
+
model: 'ml-model-v2',
|
|
772
|
+
factors: ['purchase-frequency', 'support-tickets', 'engagement']
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
console.log('Predictive analytics completed');
|
|
776
|
+
|
|
777
|
+
// 3. Automated business rules
|
|
778
|
+
console.log('\nš¤ Automated business rules...');
|
|
779
|
+
|
|
780
|
+
// Auto-tier customers based on spending
|
|
781
|
+
await customerApi.allAction('auto-tier-customers', {
|
|
782
|
+
rules: [
|
|
783
|
+
{ tier: 'platinum', minSpending: 10000 },
|
|
784
|
+
{ tier: 'gold', minSpending: 5000 },
|
|
785
|
+
{ tier: 'silver', minSpending: 1000 }
|
|
786
|
+
]
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
// Auto-reorder low stock products
|
|
790
|
+
await productApi.allAction('auto-reorder', {
|
|
791
|
+
threshold: 10,
|
|
792
|
+
orderQuantity: 50
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
console.log('Automated business rules executed');
|
|
796
|
+
|
|
797
|
+
} catch (error) {
|
|
798
|
+
console.error('ā Error in business intelligence:', error);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Main function to run the enterprise example
|
|
804
|
+
*/
|
|
805
|
+
export async function runEnterpriseExample() {
|
|
806
|
+
console.log('šÆ Fjell-Client-API Enterprise Example');
|
|
807
|
+
console.log('=====================================');
|
|
808
|
+
console.log('Demonstrating a complete e-commerce platform with enterprise workflows\n');
|
|
809
|
+
|
|
810
|
+
try {
|
|
811
|
+
// Customer management workflow
|
|
812
|
+
const customerIds = await demonstrateCustomerManagement();
|
|
813
|
+
|
|
814
|
+
// Product catalog and inventory management
|
|
815
|
+
const productIds = await demonstrateProductManagement();
|
|
816
|
+
|
|
817
|
+
// Order processing and fulfillment
|
|
818
|
+
const orderIds = await demonstrateOrderManagement(customerIds, productIds);
|
|
819
|
+
|
|
820
|
+
// Business intelligence and reporting
|
|
821
|
+
await demonstrateBusinessIntelligence();
|
|
822
|
+
|
|
823
|
+
console.log('\nā
Enterprise example completed successfully!');
|
|
824
|
+
console.log('\nBusiness Workflows Demonstrated:');
|
|
825
|
+
console.log('⢠Customer lifecycle and tier management');
|
|
826
|
+
console.log('⢠Support ticket resolution workflow');
|
|
827
|
+
console.log('⢠Product catalog and inventory management');
|
|
828
|
+
console.log('⢠Order processing and fulfillment');
|
|
829
|
+
console.log('⢠Product reviews and ratings system');
|
|
830
|
+
console.log('⢠Cross-entity business analytics');
|
|
831
|
+
console.log('⢠Predictive analytics and forecasting');
|
|
832
|
+
console.log('⢠Automated business rule execution');
|
|
833
|
+
console.log('\nEnterprise Features Showcased:');
|
|
834
|
+
console.log('⢠Multi-tenant API configuration');
|
|
835
|
+
console.log('⢠Complex business logic through actions');
|
|
836
|
+
console.log('⢠Advanced analytics through facets');
|
|
837
|
+
console.log('⢠Hierarchical data management');
|
|
838
|
+
console.log('⢠Real-time business intelligence');
|
|
839
|
+
console.log('⢠Automated workflow orchestration');
|
|
840
|
+
console.log('\nNote: This is a conceptual example showing enterprise API patterns.');
|
|
841
|
+
console.log('In production, use actual fjell-client-api with proper types and authentication.');
|
|
842
|
+
|
|
843
|
+
} catch (error) {
|
|
844
|
+
console.error('ā Enterprise example failed:', error);
|
|
845
|
+
throw error;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
// Run the example if this file is executed directly
|
|
850
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
851
|
+
runEnterpriseExample().catch(console.error);
|
|
852
|
+
}
|