@api-client/core 0.18.17 → 0.18.19
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/build/src/{modeling → decorators}/observed.d.ts +3 -3
- package/build/src/decorators/observed.d.ts.map +1 -0
- package/build/src/{modeling → decorators}/observed.js +4 -4
- package/build/src/decorators/observed.js.map +1 -0
- package/build/src/modeling/ApiModel.js +1 -1
- package/build/src/modeling/ApiModel.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +35 -1
- package/build/src/modeling/DataDomain.d.ts.map +1 -1
- package/build/src/modeling/DataDomain.js +120 -0
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +7 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +44 -1
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/DomainEntity.d.ts +6 -0
- package/build/src/modeling/DomainEntity.d.ts.map +1 -1
- package/build/src/modeling/DomainEntity.js +21 -1
- package/build/src/modeling/DomainEntity.js.map +1 -1
- package/build/src/modeling/DomainModel.js +1 -1
- package/build/src/modeling/DomainModel.js.map +1 -1
- package/build/src/modeling/DomainNamespace.js +1 -1
- package/build/src/modeling/DomainNamespace.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +15 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +64 -3
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/DomainSerialization.d.ts.map +1 -1
- package/build/src/modeling/DomainSerialization.js +2 -2
- package/build/src/modeling/DomainSerialization.js.map +1 -1
- package/build/src/modeling/definitions/SKU.d.ts.map +1 -1
- package/build/src/modeling/definitions/SKU.js +2 -0
- package/build/src/modeling/definitions/SKU.js.map +1 -1
- package/build/src/modeling/helpers/Intelisense.d.ts +472 -0
- package/build/src/modeling/helpers/Intelisense.d.ts.map +1 -0
- package/build/src/modeling/helpers/Intelisense.js +1200 -0
- package/build/src/modeling/helpers/Intelisense.js.map +1 -0
- package/build/src/modeling/templates/blog-domain.d.ts +40 -0
- package/build/src/modeling/templates/blog-domain.d.ts.map +1 -0
- package/build/src/modeling/templates/blog-domain.js +621 -0
- package/build/src/modeling/templates/blog-domain.js.map +1 -0
- package/build/src/modeling/templates/ecommerce-domain.d.ts +39 -0
- package/build/src/modeling/templates/ecommerce-domain.d.ts.map +1 -0
- package/build/src/modeling/templates/ecommerce-domain.js +663 -0
- package/build/src/modeling/templates/ecommerce-domain.js.map +1 -0
- package/build/src/modeling/types.d.ts +49 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/Thing.js +1 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +6 -6
- package/package.json +2 -1
- package/src/{modeling → decorators}/observed.ts +5 -5
- package/src/modeling/ApiModel.ts +1 -1
- package/src/modeling/DataDomain.ts +144 -0
- package/src/modeling/DomainAssociation.ts +51 -1
- package/src/modeling/DomainEntity.ts +24 -1
- package/src/modeling/DomainModel.ts +1 -1
- package/src/modeling/DomainNamespace.ts +1 -1
- package/src/modeling/DomainProperty.ts +66 -1
- package/src/modeling/DomainSerialization.ts +2 -4
- package/src/modeling/definitions/SKU.ts +2 -0
- package/src/modeling/helpers/Intelisense.ts +1345 -0
- package/src/modeling/templates/blog-domain.ts +787 -0
- package/src/modeling/templates/ecommerce-domain.ts +834 -0
- package/src/modeling/types.ts +63 -0
- package/src/models/Thing.ts +1 -1
- package/tests/unit/decorators/observed.spec.ts +527 -0
- package/tests/unit/modeling/DataDomain.search.spec.ts +188 -0
- package/tests/unit/modeling/data_domain_serialization.spec.ts +6 -2
- package/tests/unit/modeling/domain_asociation.spec.ts +376 -0
- package/tests/unit/modeling/domain_entity.spec.ts +147 -0
- package/tests/unit/modeling/domain_property.spec.ts +273 -0
- package/build/src/modeling/observed.d.ts.map +0 -1
- package/build/src/modeling/observed.js.map +0 -1
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E-Commerce Data Domain Example
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to create a comprehensive e-commerce data domain
|
|
5
|
+
* using the API Client Core modeling system. It follows the business-first approach
|
|
6
|
+
* and demonstrates proper use of namespaces, models, entities, properties,
|
|
7
|
+
* associations, and semantic annotations.
|
|
8
|
+
*
|
|
9
|
+
* The example includes:
|
|
10
|
+
* - User Management domain with proper authentication setup
|
|
11
|
+
* - Product Catalog with categories and inventory
|
|
12
|
+
* - Order Management with cart functionality and payment processing
|
|
13
|
+
* - Proper semantic annotations for security, timestamps, and business logic
|
|
14
|
+
* - Realistic associations between entities with proper cardinality
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createEcommerceDomain } from './ecommerce-domain.js'
|
|
19
|
+
*
|
|
20
|
+
* const domain = createEcommerceDomain()
|
|
21
|
+
* console.log('Domain created with', domain.graph.nodeCount(), 'nodes')
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { DataDomain } from '../DataDomain.js'
|
|
26
|
+
import { SemanticType } from '../Semantics.js'
|
|
27
|
+
import { createCalculatedSemantic } from '../definitions/Calculated.js'
|
|
28
|
+
import { createCurrencySemantic } from '../definitions/Currency.js'
|
|
29
|
+
import { createSummarySemantic } from '../definitions/Summary.js'
|
|
30
|
+
import {
|
|
31
|
+
addAvatarUrlField,
|
|
32
|
+
addCreatedAtField,
|
|
33
|
+
addDescriptionField,
|
|
34
|
+
addEmailField,
|
|
35
|
+
addFirstNameField,
|
|
36
|
+
addIdField,
|
|
37
|
+
addLastNameField,
|
|
38
|
+
addNameField,
|
|
39
|
+
addPasswordField,
|
|
40
|
+
addPhoneField,
|
|
41
|
+
addPublicUniqueNameField,
|
|
42
|
+
addUpdatedAtField,
|
|
43
|
+
addSkuField,
|
|
44
|
+
addPriceField,
|
|
45
|
+
addQuantityField,
|
|
46
|
+
addWeightField,
|
|
47
|
+
addImagesField,
|
|
48
|
+
addCustomStatusField,
|
|
49
|
+
addBooleanField,
|
|
50
|
+
addSessionIdField,
|
|
51
|
+
addExpiresAtField,
|
|
52
|
+
addUnitPriceField,
|
|
53
|
+
addCurrencyAmountField,
|
|
54
|
+
} from '../helpers/Intelisense.js'
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a comprehensive e-commerce data domain following domain-driven design principles.
|
|
58
|
+
*
|
|
59
|
+
* This function demonstrates the proper hierarchy and organization for a business domain:
|
|
60
|
+
* 1. Creates the root DataDomain
|
|
61
|
+
* 2. Organizes functionality into logical namespaces (User Management, Product Catalog, etc.)
|
|
62
|
+
* 3. Groups related entities into models within each namespace
|
|
63
|
+
* 4. Defines entities with proper semantic annotations
|
|
64
|
+
* 5. Establishes associations with appropriate cardinality and business rules
|
|
65
|
+
*
|
|
66
|
+
* @returns A fully configured DataDomain with all e-commerce entities and relationships
|
|
67
|
+
*/
|
|
68
|
+
export function createEcommerceDomain(): DataDomain {
|
|
69
|
+
// Create the root data domain
|
|
70
|
+
const domain = new DataDomain({
|
|
71
|
+
key: 'ecommerce-platform',
|
|
72
|
+
info: {
|
|
73
|
+
name: 'E-Commerce Platform',
|
|
74
|
+
displayName: 'E-Commerce Platform',
|
|
75
|
+
description:
|
|
76
|
+
'A comprehensive e-commerce platform with user management, product catalog, and order processing capabilities',
|
|
77
|
+
version: '1.0.0',
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
// 1. USER MANAGEMENT NAMESPACE
|
|
83
|
+
//
|
|
84
|
+
const userManagement = domain.addNamespace({
|
|
85
|
+
info: {
|
|
86
|
+
name: 'UserManagement',
|
|
87
|
+
displayName: 'User Management',
|
|
88
|
+
description: 'Handles user authentication, authorization, and profile management',
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// User Authentication Model
|
|
93
|
+
const authModel = userManagement.addModel({
|
|
94
|
+
info: {
|
|
95
|
+
name: 'Authentication',
|
|
96
|
+
displayName: 'User Authentication',
|
|
97
|
+
description: 'User accounts and authentication data',
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
// User Entity - The core user account
|
|
102
|
+
const userEntity = authModel.addEntity({
|
|
103
|
+
info: {
|
|
104
|
+
name: 'User',
|
|
105
|
+
displayName: 'User Account',
|
|
106
|
+
description: 'Represents a user account in the system',
|
|
107
|
+
},
|
|
108
|
+
semantics: [{ id: SemanticType.User }], // Mark this as a User entity for system-wide recognition
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// User properties with proper semantic annotations
|
|
112
|
+
addIdField(userEntity, { displayName: 'User ID', description: 'Unique identifier for the user' })
|
|
113
|
+
addEmailField(userEntity, { description: 'User email address for login and communication' })
|
|
114
|
+
addPasswordField(userEntity, { description: 'User password for authentication' })
|
|
115
|
+
|
|
116
|
+
const fName = addFirstNameField(userEntity, { description: 'User first name' })
|
|
117
|
+
fName.required = true
|
|
118
|
+
|
|
119
|
+
const lName = addLastNameField(userEntity, { description: 'User last name' })
|
|
120
|
+
lName.required = true
|
|
121
|
+
|
|
122
|
+
userEntity.addProperty({
|
|
123
|
+
info: { name: 'role', displayName: 'User Role', description: 'User role for permission management' },
|
|
124
|
+
type: 'string',
|
|
125
|
+
required: true,
|
|
126
|
+
schema: {
|
|
127
|
+
enum: ['customer', 'admin', 'moderator'],
|
|
128
|
+
defaultValue: {
|
|
129
|
+
type: 'literal',
|
|
130
|
+
value: 'customer',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
semantics: [{ id: SemanticType.UserRole }],
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
userEntity.addProperty({
|
|
137
|
+
info: {
|
|
138
|
+
name: 'email_verified',
|
|
139
|
+
displayName: 'Email Verified',
|
|
140
|
+
description: 'Whether the user has verified their email address',
|
|
141
|
+
},
|
|
142
|
+
type: 'boolean',
|
|
143
|
+
required: true,
|
|
144
|
+
schema: {
|
|
145
|
+
defaultValue: {
|
|
146
|
+
type: 'literal',
|
|
147
|
+
value: 'false',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
addCreatedAtField(userEntity, { description: 'When the user account was created' })
|
|
153
|
+
addUpdatedAtField(userEntity, { description: 'When the user account was last updated' })
|
|
154
|
+
|
|
155
|
+
// User Profile Model
|
|
156
|
+
const profileModel = userManagement.addModel({
|
|
157
|
+
info: {
|
|
158
|
+
name: 'UserProfile',
|
|
159
|
+
displayName: 'User Profile',
|
|
160
|
+
description: 'Extended user profile information',
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
// User Profile Entity
|
|
165
|
+
const userProfileEntity = profileModel.addEntity({
|
|
166
|
+
info: {
|
|
167
|
+
name: 'user_profile',
|
|
168
|
+
displayName: 'User Profile',
|
|
169
|
+
description: 'Extended profile information for users',
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
addIdField(userProfileEntity, { displayName: 'Profile ID', description: 'Unique identifier for the profile' })
|
|
174
|
+
|
|
175
|
+
userProfileEntity.addProperty({
|
|
176
|
+
info: { name: 'birthdate', displayName: 'Date of Birth', description: 'User date of birth' },
|
|
177
|
+
type: 'date',
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
addPhoneField(userProfileEntity, { description: 'User phone number' })
|
|
181
|
+
addAvatarUrlField(userProfileEntity, { description: 'URL to user profile picture' })
|
|
182
|
+
|
|
183
|
+
// User-Profile Association (One-to-One), not required for registration flows.
|
|
184
|
+
userEntity.addAssociation(
|
|
185
|
+
{ key: userProfileEntity.key },
|
|
186
|
+
{
|
|
187
|
+
info: { name: 'profile', displayName: 'User Profile', description: 'Link to extended profile information' },
|
|
188
|
+
required: false,
|
|
189
|
+
multiple: false,
|
|
190
|
+
}
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
// Address Entity
|
|
194
|
+
const addressEntity = profileModel.addEntity({
|
|
195
|
+
info: {
|
|
196
|
+
name: 'address',
|
|
197
|
+
displayName: 'Address',
|
|
198
|
+
description: 'Physical address information',
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
addIdField(addressEntity, { displayName: 'Address ID', description: 'Unique identifier for the address' })
|
|
203
|
+
|
|
204
|
+
addressEntity.addProperty({
|
|
205
|
+
info: { name: 'type', displayName: 'Address Type', description: 'Type of address (shipping, billing, etc.)' },
|
|
206
|
+
type: 'string',
|
|
207
|
+
required: true,
|
|
208
|
+
schema: {
|
|
209
|
+
enum: ['shipping', 'billing', 'both'],
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
addressEntity.addProperty({
|
|
214
|
+
info: {
|
|
215
|
+
name: 'line1',
|
|
216
|
+
displayName: 'Address Line 1',
|
|
217
|
+
description: 'Primary street address, including house number and street name',
|
|
218
|
+
},
|
|
219
|
+
type: 'string',
|
|
220
|
+
required: true,
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
addressEntity.addProperty({
|
|
224
|
+
info: {
|
|
225
|
+
name: 'line2',
|
|
226
|
+
displayName: 'Address Line 2',
|
|
227
|
+
description: 'Optional field for additional street-level information like apartment numbers or building names.',
|
|
228
|
+
},
|
|
229
|
+
type: 'string',
|
|
230
|
+
required: false,
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
addressEntity.addProperty({
|
|
234
|
+
info: {
|
|
235
|
+
name: 'line3',
|
|
236
|
+
displayName: 'Address Line 3',
|
|
237
|
+
description: 'Optional field for additional street-level information like apartment numbers or building names.',
|
|
238
|
+
},
|
|
239
|
+
type: 'string',
|
|
240
|
+
required: false,
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
addressEntity.addProperty({
|
|
244
|
+
info: { name: 'city', displayName: 'City', description: 'City name' },
|
|
245
|
+
type: 'string',
|
|
246
|
+
required: true,
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
addressEntity.addProperty({
|
|
250
|
+
info: { name: 'state', displayName: 'State/Province', description: 'State or province' },
|
|
251
|
+
type: 'string',
|
|
252
|
+
required: true,
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
addressEntity.addProperty({
|
|
256
|
+
info: { name: 'postal_code', displayName: 'ZIP/Postal Code', description: 'ZIP or postal code' },
|
|
257
|
+
type: 'string',
|
|
258
|
+
required: true,
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
addressEntity.addProperty({
|
|
262
|
+
info: { name: 'country', displayName: 'Country', description: 'Country name' },
|
|
263
|
+
type: 'string',
|
|
264
|
+
required: true,
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
// User-Address Association (One-to-Many)
|
|
268
|
+
userEntity.addAssociation(
|
|
269
|
+
{ key: addressEntity.key },
|
|
270
|
+
{
|
|
271
|
+
info: { name: 'addresses', displayName: 'User Addresses', description: 'User shipping and billing addresses' },
|
|
272
|
+
required: false,
|
|
273
|
+
multiple: true,
|
|
274
|
+
}
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
//
|
|
278
|
+
// 2. PRODUCT CATALOG NAMESPACE
|
|
279
|
+
//
|
|
280
|
+
const productCatalog = domain.addNamespace({
|
|
281
|
+
info: {
|
|
282
|
+
name: 'ProductCatalog',
|
|
283
|
+
displayName: 'Product Catalog',
|
|
284
|
+
description: 'Product information, categories, and inventory management',
|
|
285
|
+
},
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
// Product Management Model
|
|
289
|
+
const productModel = productCatalog.addModel({
|
|
290
|
+
info: {
|
|
291
|
+
name: 'Products',
|
|
292
|
+
displayName: 'Product Management',
|
|
293
|
+
description: 'Core product entities and relationships',
|
|
294
|
+
},
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
// Category Entity
|
|
298
|
+
const categoryEntity = productModel.addEntity({
|
|
299
|
+
info: {
|
|
300
|
+
name: 'category',
|
|
301
|
+
displayName: 'Product Category',
|
|
302
|
+
description: 'Product categorization for organization and navigation',
|
|
303
|
+
},
|
|
304
|
+
})
|
|
305
|
+
addIdField(categoryEntity, { displayName: 'Category ID', description: 'Unique identifier for the category' })
|
|
306
|
+
addNameField(categoryEntity, { displayName: 'Category Name', description: 'Display name of the category' })
|
|
307
|
+
addPublicUniqueNameField(categoryEntity, {
|
|
308
|
+
displayName: 'URL Slug',
|
|
309
|
+
description: 'URL-friendly identifier for the category',
|
|
310
|
+
})
|
|
311
|
+
addDescriptionField(categoryEntity, { description: 'Category description' })
|
|
312
|
+
|
|
313
|
+
// Self-referencing association for category hierarchy
|
|
314
|
+
categoryEntity.addAssociation(
|
|
315
|
+
{ key: categoryEntity.key },
|
|
316
|
+
{
|
|
317
|
+
info: {
|
|
318
|
+
name: 'parent_category',
|
|
319
|
+
displayName: 'Parent Category',
|
|
320
|
+
description: 'Parent category for hierarchical organization',
|
|
321
|
+
},
|
|
322
|
+
required: false,
|
|
323
|
+
multiple: false,
|
|
324
|
+
}
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
// Product Entity
|
|
328
|
+
const productEntity = productModel.addEntity({
|
|
329
|
+
info: {
|
|
330
|
+
name: 'product',
|
|
331
|
+
displayName: 'Product',
|
|
332
|
+
description: 'Core product information and specifications',
|
|
333
|
+
},
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
addIdField(productEntity, { displayName: 'Product ID', description: 'Unique identifier for the product' })
|
|
337
|
+
addNameField(productEntity, { displayName: 'Product Name', description: 'Display name of the product' })
|
|
338
|
+
addPublicUniqueNameField(productEntity, {
|
|
339
|
+
displayName: 'URL Slug',
|
|
340
|
+
description: 'URL-friendly identifier for the product',
|
|
341
|
+
})
|
|
342
|
+
addDescriptionField(productEntity, { description: 'Detailed product description' })
|
|
343
|
+
|
|
344
|
+
productEntity.addProperty({
|
|
345
|
+
info: { name: 'short_description', displayName: 'Short Description', description: 'Brief product summary' },
|
|
346
|
+
type: 'string',
|
|
347
|
+
semantics: [createSummarySemantic()],
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
addSkuField(productEntity, { description: 'Stock Keeping Unit - unique product identifier' })
|
|
351
|
+
|
|
352
|
+
addPriceField(productEntity, { description: 'Product price in cents (USD)' })
|
|
353
|
+
|
|
354
|
+
productEntity.addProperty({
|
|
355
|
+
info: {
|
|
356
|
+
name: 'compare_at_price',
|
|
357
|
+
displayName: 'Compare at Price',
|
|
358
|
+
description: 'Original price for discount display',
|
|
359
|
+
},
|
|
360
|
+
type: 'number',
|
|
361
|
+
schema: {
|
|
362
|
+
maximum: 0,
|
|
363
|
+
},
|
|
364
|
+
bindings: [
|
|
365
|
+
{
|
|
366
|
+
type: 'web',
|
|
367
|
+
schema: {
|
|
368
|
+
dataType: 'float',
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
semantics: [
|
|
373
|
+
createCurrencySemantic({
|
|
374
|
+
storageFormat: 'integer_cents',
|
|
375
|
+
defaultCurrency: 'USD',
|
|
376
|
+
decimalPlaces: 2,
|
|
377
|
+
allowNegative: false,
|
|
378
|
+
validateCurrencyCode: true,
|
|
379
|
+
}),
|
|
380
|
+
],
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
addCustomStatusField(productEntity, ['inactive', 'active', 'pending', 'archived'], {
|
|
384
|
+
description: 'Current status of the product',
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
addWeightField(productEntity, { description: 'Product weight in grams' })
|
|
388
|
+
|
|
389
|
+
addImagesField(productEntity, { description: 'Array of product image URLs' })
|
|
390
|
+
|
|
391
|
+
addCreatedAtField(productEntity, { description: 'When the product was created' })
|
|
392
|
+
addUpdatedAtField(productEntity, { description: 'When the product was last updated' })
|
|
393
|
+
|
|
394
|
+
// Product-Category Association (Many-to-Many)
|
|
395
|
+
productEntity.addAssociation(
|
|
396
|
+
{ key: categoryEntity.key },
|
|
397
|
+
{
|
|
398
|
+
info: {
|
|
399
|
+
name: 'categories',
|
|
400
|
+
displayName: 'Product Categories',
|
|
401
|
+
description: 'Categories this product belongs to',
|
|
402
|
+
},
|
|
403
|
+
required: true,
|
|
404
|
+
multiple: true,
|
|
405
|
+
semantics: [{ id: SemanticType.Categories }],
|
|
406
|
+
}
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
// Inventory Model
|
|
410
|
+
const inventoryModel = productCatalog.addModel({
|
|
411
|
+
info: {
|
|
412
|
+
name: 'Inventory',
|
|
413
|
+
displayName: 'Inventory Management',
|
|
414
|
+
description: 'Stock levels and inventory tracking',
|
|
415
|
+
},
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
// Inventory Entity
|
|
419
|
+
const inventoryEntity = inventoryModel.addEntity({
|
|
420
|
+
info: {
|
|
421
|
+
name: 'inventory',
|
|
422
|
+
displayName: 'Inventory',
|
|
423
|
+
description: 'Stock levels and inventory information for products',
|
|
424
|
+
},
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
addIdField(inventoryEntity, {
|
|
428
|
+
displayName: 'Inventory ID',
|
|
429
|
+
description: 'Unique identifier for the inventory record',
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
addQuantityField(inventoryEntity, { displayName: 'Stock Quantity', description: 'Available stock quantity' })
|
|
433
|
+
|
|
434
|
+
const reservedQty = addQuantityField(inventoryEntity, {
|
|
435
|
+
name: 'reserved_quantity',
|
|
436
|
+
displayName: 'Reserved Quantity',
|
|
437
|
+
description: 'Quantity reserved for pending orders',
|
|
438
|
+
})
|
|
439
|
+
reservedQty.schema = {
|
|
440
|
+
defaultValue: {
|
|
441
|
+
type: 'literal',
|
|
442
|
+
value: '0',
|
|
443
|
+
},
|
|
444
|
+
minimum: 0,
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
addBooleanField(inventoryEntity, 'trackQuantity', 'true', {
|
|
448
|
+
displayName: 'Track Quantity',
|
|
449
|
+
description: 'Whether to track inventory for this product',
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
addBooleanField(inventoryEntity, 'allowBackorder', 'false', {
|
|
453
|
+
displayName: 'Allow Backorder',
|
|
454
|
+
description: 'Whether to allow ordering when out of stock',
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
// Product-Inventory Association (One-to-One)
|
|
458
|
+
productEntity.addAssociation(
|
|
459
|
+
{ key: inventoryEntity.key },
|
|
460
|
+
{
|
|
461
|
+
info: {
|
|
462
|
+
name: 'inventory',
|
|
463
|
+
displayName: 'Product Inventory',
|
|
464
|
+
description: 'Inventory information for this product',
|
|
465
|
+
},
|
|
466
|
+
required: true,
|
|
467
|
+
multiple: false,
|
|
468
|
+
}
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
//
|
|
472
|
+
// 3. ORDER MANAGEMENT NAMESPACE
|
|
473
|
+
//
|
|
474
|
+
const orderManagement = domain.addNamespace({
|
|
475
|
+
info: {
|
|
476
|
+
name: 'OrderManagement',
|
|
477
|
+
displayName: 'Order Management',
|
|
478
|
+
description: 'Shopping cart, orders, and payment processing',
|
|
479
|
+
},
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
// Shopping Cart Model
|
|
483
|
+
const cartModel = orderManagement.addModel({
|
|
484
|
+
info: {
|
|
485
|
+
name: 'ShoppingCart',
|
|
486
|
+
displayName: 'Shopping Cart',
|
|
487
|
+
description: 'Shopping cart and cart items',
|
|
488
|
+
},
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
// Cart Entity
|
|
492
|
+
const cartEntity = cartModel.addEntity({
|
|
493
|
+
info: {
|
|
494
|
+
name: 'cart',
|
|
495
|
+
displayName: 'Shopping Cart',
|
|
496
|
+
description: 'User shopping cart',
|
|
497
|
+
},
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
addIdField(cartEntity, { displayName: 'Cart ID', description: 'Unique identifier for the cart' })
|
|
501
|
+
|
|
502
|
+
addSessionIdField(cartEntity, { description: 'Session identifier for guest carts' })
|
|
503
|
+
|
|
504
|
+
addExpiresAtField(cartEntity, { description: 'When the cart expires for cleanup' })
|
|
505
|
+
|
|
506
|
+
addCreatedAtField(cartEntity, { description: 'When the cart was created' })
|
|
507
|
+
addUpdatedAtField(cartEntity, { description: 'When the cart was last updated' })
|
|
508
|
+
|
|
509
|
+
// Cart-User Association (Many-to-One)
|
|
510
|
+
cartEntity.addAssociation(
|
|
511
|
+
{ key: userEntity.key },
|
|
512
|
+
{
|
|
513
|
+
info: { name: 'user', displayName: 'Cart Owner', description: 'User who owns this cart' },
|
|
514
|
+
required: false,
|
|
515
|
+
multiple: false,
|
|
516
|
+
semantics: [{ id: SemanticType.ResourceOwnerIdentifier }],
|
|
517
|
+
}
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
// Cart Item Entity
|
|
521
|
+
const cartItemEntity = cartModel.addEntity({
|
|
522
|
+
info: {
|
|
523
|
+
name: 'cart_item',
|
|
524
|
+
displayName: 'Cart Item',
|
|
525
|
+
description: 'Individual items in a shopping cart',
|
|
526
|
+
},
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
addIdField(cartItemEntity, { displayName: 'Cart Item ID', description: 'Unique identifier for the cart item' })
|
|
530
|
+
|
|
531
|
+
const cartItemQuantity = addQuantityField(cartItemEntity, { description: 'Number of items' })
|
|
532
|
+
cartItemQuantity.schema = { minimum: 1 }
|
|
533
|
+
|
|
534
|
+
const cartUnitPrice = addUnitPriceField(cartItemEntity, { description: 'Price per unit at time of adding to cart' })
|
|
535
|
+
|
|
536
|
+
cartItemEntity.addProperty({
|
|
537
|
+
info: { name: 'total_price', displayName: 'Total Price', description: 'Total price for this line item' },
|
|
538
|
+
type: 'number',
|
|
539
|
+
required: true,
|
|
540
|
+
readOnly: true,
|
|
541
|
+
semantics: [
|
|
542
|
+
createCurrencySemantic({
|
|
543
|
+
storageFormat: 'integer_cents',
|
|
544
|
+
defaultCurrency: 'USD',
|
|
545
|
+
decimalPlaces: 2,
|
|
546
|
+
allowNegative: false,
|
|
547
|
+
}),
|
|
548
|
+
createCalculatedSemantic({
|
|
549
|
+
formula: '{{unitPrice}} * {{quantity}}',
|
|
550
|
+
dependencies: [cartUnitPrice.key, cartItemQuantity.key],
|
|
551
|
+
recalculateOnUpdate: true,
|
|
552
|
+
}),
|
|
553
|
+
],
|
|
554
|
+
})
|
|
555
|
+
|
|
556
|
+
// Cart-CartItem Association (One-to-Many)
|
|
557
|
+
cartEntity.addAssociation(
|
|
558
|
+
{ key: cartItemEntity.key },
|
|
559
|
+
{
|
|
560
|
+
info: { name: 'items', displayName: 'Cart Items', description: 'Items in this cart' },
|
|
561
|
+
required: false,
|
|
562
|
+
multiple: true,
|
|
563
|
+
onDelete: 'cascade',
|
|
564
|
+
}
|
|
565
|
+
)
|
|
566
|
+
|
|
567
|
+
// CartItem-Product Association (Many-to-One)
|
|
568
|
+
cartItemEntity.addAssociation(
|
|
569
|
+
{ key: productEntity.key },
|
|
570
|
+
{
|
|
571
|
+
info: { name: 'product', displayName: 'Product', description: 'Product for this cart item' },
|
|
572
|
+
required: true,
|
|
573
|
+
multiple: false,
|
|
574
|
+
}
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
// Order Processing Model
|
|
578
|
+
const orderModel = orderManagement.addModel({
|
|
579
|
+
info: {
|
|
580
|
+
name: 'Orders',
|
|
581
|
+
displayName: 'Order Processing',
|
|
582
|
+
description: 'Orders and order fulfillment',
|
|
583
|
+
},
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
// Order Entity
|
|
587
|
+
const orderEntity = orderModel.addEntity({
|
|
588
|
+
info: {
|
|
589
|
+
name: 'order',
|
|
590
|
+
displayName: 'Order',
|
|
591
|
+
description: 'Customer order',
|
|
592
|
+
},
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
addIdField(orderEntity, { displayName: 'Order ID', description: 'Unique identifier for the order' })
|
|
596
|
+
|
|
597
|
+
orderEntity.addProperty({
|
|
598
|
+
info: { name: 'order_number', displayName: 'Order Number', description: 'Human-readable order number' },
|
|
599
|
+
type: 'string',
|
|
600
|
+
required: true,
|
|
601
|
+
unique: true,
|
|
602
|
+
})
|
|
603
|
+
|
|
604
|
+
addCustomStatusField(
|
|
605
|
+
orderEntity,
|
|
606
|
+
['pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled', 'refunded'],
|
|
607
|
+
{
|
|
608
|
+
displayName: 'Order Status',
|
|
609
|
+
description: 'Current status of the order',
|
|
610
|
+
}
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
const subtotal = addCurrencyAmountField(orderEntity, 'subtotal', 'Subtotal', {
|
|
614
|
+
description: 'Order subtotal before taxes and shipping',
|
|
615
|
+
})
|
|
616
|
+
|
|
617
|
+
const taxAmount = addCurrencyAmountField(orderEntity, 'taxAmount', 'Tax Amount', {
|
|
618
|
+
description: 'Total tax amount',
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
const shippingAmount = addCurrencyAmountField(orderEntity, 'shippingAmount', 'Shipping Amount', {
|
|
622
|
+
description: 'Shipping cost',
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
orderEntity.addProperty({
|
|
626
|
+
info: { name: 'total_amount', displayName: 'Total Amount', description: 'Final order total' },
|
|
627
|
+
type: 'number',
|
|
628
|
+
required: true,
|
|
629
|
+
semantics: [
|
|
630
|
+
createCurrencySemantic({
|
|
631
|
+
storageFormat: 'integer_cents',
|
|
632
|
+
defaultCurrency: 'USD',
|
|
633
|
+
decimalPlaces: 2,
|
|
634
|
+
allowNegative: false,
|
|
635
|
+
}),
|
|
636
|
+
createCalculatedSemantic({
|
|
637
|
+
formula: '{{subtotal}} + {{taxAmount}} + {{shippingAmount}}',
|
|
638
|
+
dependencies: [subtotal.key, taxAmount.key, shippingAmount.key],
|
|
639
|
+
recalculateOnUpdate: true,
|
|
640
|
+
}),
|
|
641
|
+
],
|
|
642
|
+
})
|
|
643
|
+
|
|
644
|
+
orderEntity.addProperty({
|
|
645
|
+
info: { name: 'notes', displayName: 'Order Notes', description: 'Customer notes or special instructions' },
|
|
646
|
+
type: 'string',
|
|
647
|
+
})
|
|
648
|
+
|
|
649
|
+
addCreatedAtField(orderEntity, { description: 'When the order was created' })
|
|
650
|
+
addUpdatedAtField(orderEntity, { description: 'When the order was last updated' })
|
|
651
|
+
|
|
652
|
+
// Order-User Association (Many-to-One)
|
|
653
|
+
orderEntity.addAssociation(
|
|
654
|
+
{ key: userEntity.key },
|
|
655
|
+
{
|
|
656
|
+
info: { name: 'customer', displayName: 'Customer', description: 'Customer who placed this order' },
|
|
657
|
+
required: true,
|
|
658
|
+
multiple: false,
|
|
659
|
+
semantics: [{ id: SemanticType.ResourceOwnerIdentifier }],
|
|
660
|
+
}
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
// Order-Address Associations (Many-to-One)
|
|
664
|
+
orderEntity.addAssociation(
|
|
665
|
+
{ key: addressEntity.key },
|
|
666
|
+
{
|
|
667
|
+
info: { name: 'shipping_address', displayName: 'Shipping Address', description: 'Address for order delivery' },
|
|
668
|
+
required: true,
|
|
669
|
+
multiple: false,
|
|
670
|
+
}
|
|
671
|
+
)
|
|
672
|
+
|
|
673
|
+
orderEntity.addAssociation(
|
|
674
|
+
{ key: addressEntity.key },
|
|
675
|
+
{
|
|
676
|
+
info: { name: 'billing_address', displayName: 'Billing Address', description: 'Address for billing purposes' },
|
|
677
|
+
required: true,
|
|
678
|
+
multiple: false,
|
|
679
|
+
}
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
// Order Line Item Entity
|
|
683
|
+
const orderItemEntity = orderModel.addEntity({
|
|
684
|
+
info: {
|
|
685
|
+
name: 'order_item',
|
|
686
|
+
displayName: 'Order Line Item',
|
|
687
|
+
description: 'Individual line items in an order',
|
|
688
|
+
},
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
addIdField(orderItemEntity, { displayName: 'Order Item ID', description: 'Unique identifier for the order item' })
|
|
692
|
+
|
|
693
|
+
const quantity = addQuantityField(orderItemEntity, { description: 'Number of items ordered' })
|
|
694
|
+
quantity.schema = { minimum: 1 }
|
|
695
|
+
|
|
696
|
+
const unitPrice = addUnitPriceField(orderItemEntity, { description: 'Price per unit at time of order' })
|
|
697
|
+
|
|
698
|
+
orderItemEntity.addProperty({
|
|
699
|
+
info: { name: 'total_price', displayName: 'Total Price', description: 'Total price for this line item' },
|
|
700
|
+
type: 'number',
|
|
701
|
+
required: true,
|
|
702
|
+
readOnly: true,
|
|
703
|
+
semantics: [
|
|
704
|
+
createCurrencySemantic({
|
|
705
|
+
storageFormat: 'integer_cents',
|
|
706
|
+
defaultCurrency: 'USD',
|
|
707
|
+
decimalPlaces: 2,
|
|
708
|
+
allowNegative: false,
|
|
709
|
+
}),
|
|
710
|
+
createCalculatedSemantic({
|
|
711
|
+
formula: '{{quantity}} * {{unitPrice}}',
|
|
712
|
+
dependencies: [quantity.key, unitPrice.key],
|
|
713
|
+
recalculateOnUpdate: true,
|
|
714
|
+
}),
|
|
715
|
+
],
|
|
716
|
+
})
|
|
717
|
+
|
|
718
|
+
// orderItemEntity.addProperty({
|
|
719
|
+
// info: {
|
|
720
|
+
// name: 'productSnapshot',
|
|
721
|
+
// displayName: 'Product Snapshot',
|
|
722
|
+
// description: 'Snapshot of product data at time of order',
|
|
723
|
+
// },
|
|
724
|
+
// type: 'object',
|
|
725
|
+
// required: true,
|
|
726
|
+
// readOnly: true,
|
|
727
|
+
// })
|
|
728
|
+
|
|
729
|
+
// Order-OrderItem Association (One-to-Many)
|
|
730
|
+
orderEntity.addAssociation(
|
|
731
|
+
{ key: orderItemEntity.key },
|
|
732
|
+
{
|
|
733
|
+
info: { name: 'items', displayName: 'Order Items', description: 'Items in this order' },
|
|
734
|
+
required: true,
|
|
735
|
+
multiple: true,
|
|
736
|
+
onDelete: 'cascade',
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
|
|
740
|
+
// OrderItem-Product Association (Many-to-One)
|
|
741
|
+
orderItemEntity.addAssociation(
|
|
742
|
+
{ key: productEntity.key },
|
|
743
|
+
{
|
|
744
|
+
info: { name: 'product', displayName: 'Product', description: 'Product for this order item' },
|
|
745
|
+
required: true,
|
|
746
|
+
multiple: false,
|
|
747
|
+
}
|
|
748
|
+
)
|
|
749
|
+
|
|
750
|
+
// Payment Model
|
|
751
|
+
const paymentModel = orderManagement.addModel({
|
|
752
|
+
info: {
|
|
753
|
+
name: 'Payments',
|
|
754
|
+
displayName: 'Payment Processing',
|
|
755
|
+
description: 'Payment methods and transactions',
|
|
756
|
+
},
|
|
757
|
+
})
|
|
758
|
+
|
|
759
|
+
// Payment Entity
|
|
760
|
+
const paymentEntity = paymentModel.addEntity({
|
|
761
|
+
info: {
|
|
762
|
+
name: 'payment',
|
|
763
|
+
displayName: 'Payment',
|
|
764
|
+
description: 'Payment transaction record',
|
|
765
|
+
},
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
addIdField(paymentEntity, { displayName: 'Payment ID', description: 'Unique identifier for the payment' })
|
|
769
|
+
|
|
770
|
+
paymentEntity.addProperty({
|
|
771
|
+
info: { name: 'method', displayName: 'Payment Method', description: 'Method used for payment' },
|
|
772
|
+
type: 'string',
|
|
773
|
+
required: true,
|
|
774
|
+
schema: {
|
|
775
|
+
enum: ['credit_card', 'debit_card', 'paypal', 'bank_transfer', 'apple_pay', 'google_pay'],
|
|
776
|
+
},
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
addCustomStatusField(paymentEntity, ['pending', 'authorized', 'captured', 'failed', 'cancelled', 'refunded'], {
|
|
780
|
+
displayName: 'Payment Status',
|
|
781
|
+
description: 'Current status of the payment',
|
|
782
|
+
})
|
|
783
|
+
|
|
784
|
+
addCurrencyAmountField(paymentEntity, 'amount', 'Payment Amount', { description: 'Amount charged' })
|
|
785
|
+
|
|
786
|
+
paymentEntity.addProperty({
|
|
787
|
+
info: { name: 'currency', displayName: 'Currency', description: 'Currency code for the payment' },
|
|
788
|
+
type: 'string',
|
|
789
|
+
required: true,
|
|
790
|
+
schema: {
|
|
791
|
+
defaultValue: {
|
|
792
|
+
type: 'literal',
|
|
793
|
+
value: 'USD',
|
|
794
|
+
},
|
|
795
|
+
},
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
paymentEntity.addProperty({
|
|
799
|
+
info: {
|
|
800
|
+
name: 'transaction_id',
|
|
801
|
+
displayName: 'Transaction ID',
|
|
802
|
+
description: 'External payment processor transaction ID',
|
|
803
|
+
},
|
|
804
|
+
type: 'string',
|
|
805
|
+
})
|
|
806
|
+
|
|
807
|
+
// paymentEntity.addProperty({
|
|
808
|
+
// info: {
|
|
809
|
+
// name: 'gatewayResponse',
|
|
810
|
+
// displayName: 'Gateway Response',
|
|
811
|
+
// description: 'Raw response from payment gateway',
|
|
812
|
+
// },
|
|
813
|
+
// type: 'object',
|
|
814
|
+
// readOnly: true,
|
|
815
|
+
// })
|
|
816
|
+
|
|
817
|
+
addCreatedAtField(paymentEntity, { description: 'When the payment was created' })
|
|
818
|
+
|
|
819
|
+
// Order-Payment Association (One-to-Many)
|
|
820
|
+
orderEntity.addAssociation(
|
|
821
|
+
{ key: paymentEntity.key },
|
|
822
|
+
{
|
|
823
|
+
info: { name: 'payments', displayName: 'Order Payments', description: 'Payment transactions for this order' },
|
|
824
|
+
required: false,
|
|
825
|
+
multiple: true,
|
|
826
|
+
onDelete: 'restrict', // Don't allow order deletion if payments exist
|
|
827
|
+
}
|
|
828
|
+
)
|
|
829
|
+
|
|
830
|
+
return domain
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// Export the creation function for use in other files
|
|
834
|
+
export default createEcommerceDomain
|