@cendo/database-schemas 2.1.9 → 2.2.1

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/CLAUDE.md CHANGED
@@ -119,6 +119,8 @@ index.js # Exports path to schemas/ directory
119
119
 
120
120
  ## Schema Catalog
121
121
 
122
+ > Field-level descriptions are documented as JSDoc comments directly in each schema file.
123
+
122
124
  ### Orders & Fulfillment
123
125
  - **Order** — Main order entity (order_id, type, shop, fulfillment_status, validation_status, amount, shipping_address). Compound indexes on (order_id, type), (shipping_address.username), (shipping_address.email), (logistic_data.tracking_number), (fulfillments.number)
124
126
  - **OrderItem** — Line items in orders (order, sku_id, product_name, quantity, fulfillment_sku, customize_id, mockup, design). Compound indexes on (order, sku_id) and (order, sync_id)
@@ -127,7 +129,7 @@ index.js # Exports path to schemas/ directory
127
129
  - **OrderLog** — Order event logging (order, level, label, message, meta). TTL: 90 days
128
130
 
129
131
  ### Products
130
- - **Product** — Product/SKU catalog (shop, name, sku_id, seller_sku, fulfillment_sku, customize_sku, status). Full-text index on name/sku_id/fulfillment_sku/customize_sku
132
+ - **Product** — Product/SKU catalog (shop, name, sku_id, seller_sku, fulfillment_sku, customize_sku, design_type, mockup, design, status). Full-text index on name/sku_id/fulfillment_sku/customize_sku
131
133
 
132
134
  ### Shops & Settings
133
135
  - **Shop** — Store/shop configuration (shop_id, type, status, fulfillment_store, default_carrier, nhanh_id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cendo/database-schemas",
3
- "version": "2.1.9",
3
+ "version": "2.2.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -1,28 +1,37 @@
1
1
  const {Schema} = require('mongoose')
2
2
 
3
3
 
4
+ /**
5
+ * CarrierSetting — Key-value settings per shipping carrier.
6
+ * Stores carrier-specific configuration (e.g., API credentials, routing rules).
7
+ */
4
8
  const CarrierSetting = new Schema({
9
+ /** Reference to the ShippingCarrier */
5
10
  shipping_carrier: {
6
11
  type: Schema.Types.ObjectId,
7
12
  required: true,
8
13
  index: true,
9
14
  },
10
15
 
16
+ /** Setting key name */
11
17
  key: {
12
18
  type: String,
13
19
  trim: true,
14
20
  index: true,
15
21
  },
16
22
 
23
+ /** Setting value (any type) */
17
24
  value: {
18
25
  type: Schema.Types.Mixed,
19
26
  },
20
27
 
28
+ /** Last modification timestamp */
21
29
  updated_at: {
22
30
  type: Date,
23
31
  default: Date.now
24
32
  },
25
33
 
34
+ /** Creation timestamp */
26
35
  created_at: {
27
36
  type: Date,
28
37
  default: Date.now,
@@ -32,4 +41,3 @@ const CarrierSetting = new Schema({
32
41
 
33
42
 
34
43
  module.exports = CarrierSetting
35
-
@@ -1,12 +1,18 @@
1
1
  const {Schema} = require('mongoose')
2
2
 
3
3
 
4
+ /**
5
+ * FulfillmentStore — Fulfillment provider/warehouse configuration.
6
+ * Stores API credentials and identifiers for connecting to fulfillment providers.
7
+ */
4
8
  const FulfillmentStore = new Schema({
9
+ /** Display name of the fulfillment provider */
5
10
  name: {
6
11
  type: String,
7
12
  trim: true,
8
13
  },
9
14
 
15
+ /** Provider status: 'active' | 'inactive' */
10
16
  status: {
11
17
  type: String,
12
18
  enum: ['active', 'inactive'],
@@ -14,31 +20,37 @@ const FulfillmentStore = new Schema({
14
20
  index: true,
15
21
  },
16
22
 
23
+ /** API authentication key for the provider */
17
24
  api_key: {
18
25
  type: String,
19
26
  trim: true,
20
27
  },
21
28
 
29
+ /** Base URL of the provider's API */
22
30
  api_url: {
23
31
  type: String,
24
32
  trim: true,
25
33
  },
26
34
 
35
+ /** Store/account ID on the provider's system */
27
36
  store_id: {
28
37
  type: String,
29
38
  trim: true,
30
39
  },
31
40
 
41
+ /** Team ID on the provider's system */
32
42
  team_id: {
33
43
  type: String,
34
44
  trim: true,
35
45
  },
36
46
 
47
+ /** Last modification timestamp */
37
48
  updated_at: {
38
49
  type: Date,
39
50
  default: Date.now
40
51
  },
41
52
 
53
+ /** Creation timestamp */
42
54
  created_at: {
43
55
  type: Date,
44
56
  default: Date.now,
@@ -1,17 +1,24 @@
1
1
  const {Schema} = require('mongoose')
2
2
 
3
3
 
4
+ /**
5
+ * ImportFile — Bulk import file tracking.
6
+ * A container for imported rows from a CSV/Excel upload.
7
+ */
4
8
  const ImportFile = new Schema({
9
+ /** Original filename of the imported file */
5
10
  name: {
6
11
  type: String,
7
12
  trim: true,
8
13
  },
9
14
 
15
+ /** Last modification timestamp */
10
16
  updated_at: {
11
17
  type: Date,
12
18
  default: Date.now
13
19
  },
14
20
 
21
+ /** Creation timestamp */
15
22
  created_at: {
16
23
  type: Date,
17
24
  default: Date.now
@@ -19,4 +26,3 @@ const ImportFile = new Schema({
19
26
  })
20
27
 
21
28
  module.exports = ImportFile
22
-
@@ -1,29 +1,38 @@
1
1
  const {Schema} = require('mongoose')
2
2
 
3
3
 
4
+ /**
5
+ * ImportRow — Individual rows from a bulk import.
6
+ * Auto-deleted after 12 months via TTL index.
7
+ */
4
8
  const ImportRow = new Schema({
9
+ /** Reference to the parent ImportFile */
5
10
  file: {
6
11
  type: Schema.Types.ObjectId,
7
12
  index: true,
8
13
  required: true
9
14
  },
10
15
 
16
+ /** Row/line number in the import file */
11
17
  line: {
12
18
  type: Number,
13
19
  required: true
14
20
  },
15
21
 
22
+ /** Deduplication key for this row */
16
23
  unique_id: {
17
24
  type: String,
18
25
  required: true,
19
26
  trim: true,
20
27
  },
21
28
 
29
+ /** Raw row data from the import file */
22
30
  data: {
23
31
  type: Schema.Types.Mixed,
24
32
  default: {}
25
33
  },
26
34
 
35
+ /** Processing status: 'pending' | 'completed' | 'failed' | 'cancelled' */
27
36
  status: {
28
37
  type: String,
29
38
  default: 'pending',
@@ -31,10 +40,12 @@ const ImportRow = new Schema({
31
40
  index: true
32
41
  },
33
42
 
43
+ /** Last modification timestamp */
34
44
  updated_at: {
35
45
  type: Date,
36
46
  },
37
47
 
48
+ /** Creation timestamp (TTL: 12 months) */
38
49
  created_at: {
39
50
  type: Date,
40
51
  default: Date.now
package/schemas/Label.js CHANGED
@@ -1,60 +1,75 @@
1
1
  const {Schema} = require('mongoose')
2
2
 
3
3
 
4
+ /**
5
+ * Label — Shipping label records.
6
+ * Tracks label generation, storage, and push status to the source platform.
7
+ */
4
8
  const Label = new Schema({
9
+ /** Reference to the Order */
5
10
  order: {
6
11
  type: Schema.Types.ObjectId,
7
12
  ref: 'Order',
8
13
  index: true,
9
14
  },
10
15
 
16
+ /** External order ID for lookup */
11
17
  order_id: {
12
18
  type: String,
13
19
  trim: true,
14
20
  index: true,
15
21
  },
16
22
 
23
+ /** Tracking number printed on the label */
17
24
  tracking_number: {
18
25
  type: String,
19
26
  trim: true,
20
27
  index: true,
21
28
  },
22
29
 
30
+ /** Carrier name/code for this label */
23
31
  carrier: {
24
32
  type: String,
25
33
  trim: true,
26
34
  },
27
35
 
36
+ /** Public URL to download/view the label */
28
37
  url: {
29
38
  type: String,
30
39
  trim: true,
31
40
  },
32
41
 
42
+ /** Internal file storage path for the label */
33
43
  path_file: {
34
44
  type: String,
35
45
  trim: true,
36
46
  },
37
47
 
48
+ /** Label status (e.g., 'created', 'printed') */
38
49
  status: {
39
50
  type: String,
40
51
  trim: true,
41
52
  index: true,
42
53
  },
43
54
 
55
+ /** Whether this label has been pushed to the source platform */
44
56
  is_pushed: {
45
57
  type: Boolean,
46
58
  default: false,
47
59
  },
48
60
 
61
+ /** Timestamp when the label was pushed to the platform */
49
62
  pushed_at: {
50
63
  type: Date,
51
64
  },
52
65
 
66
+ /** Last modification timestamp */
53
67
  updated_at: {
54
68
  type: Date,
55
69
  default: Date.now
56
70
  },
57
71
 
72
+ /** Creation timestamp */
58
73
  created_at: {
59
74
  type: Date,
60
75
  default: Date.now,
package/schemas/Media.js CHANGED
@@ -2,23 +2,31 @@ const {Schema} = require('mongoose')
2
2
  const DimensionObject = require('./types/DimensionObject')
3
3
 
4
4
 
5
+ /**
6
+ * Media — Design/mockup files.
7
+ * Tracks file processing status and storage location for print-ready designs and mockups.
8
+ */
5
9
  const Media = new Schema({
10
+ /** Public URL of the media file */
6
11
  url: {
7
12
  type: String,
8
13
  trim: true,
9
14
  },
10
15
 
16
+ /** Internal file storage path */
11
17
  path_file: {
12
18
  type: String,
13
19
  trim: true,
14
20
  },
15
21
 
22
+ /** Media type (default 'design') — e.g., 'design', 'mockup' */
16
23
  type: {
17
24
  type: String,
18
25
  trim: true,
19
26
  default: 'design'
20
27
  },
21
28
 
29
+ /** Storage location: 'external' | 'internal' */
22
30
  location: {
23
31
  type: String,
24
32
  default: 'external',
@@ -26,15 +34,18 @@ const Media = new Schema({
26
34
  index: true,
27
35
  },
28
36
 
37
+ /** MIME type of the file (e.g., 'image/png') */
29
38
  mimetype: {
30
39
  type: String,
31
40
  trim: true,
32
41
  },
33
42
 
43
+ /** File size in bytes */
34
44
  size: {
35
45
  type: Number,
36
46
  },
37
47
 
48
+ /** Processing status: 'pending' | 'completed' | 'failed' */
38
49
  status: {
39
50
  type: String,
40
51
  trim: true,
@@ -42,26 +53,31 @@ const Media = new Schema({
42
53
  enum: ['pending', 'completed', 'failed'],
43
54
  },
44
55
 
56
+ /** Image dimensions in pixels (embedded) */
45
57
  dimension: {
46
58
  type: DimensionObject
47
59
  },
48
60
 
61
+ /** Number of processing attempts */
49
62
  process_attempts: {
50
63
  type: Number,
51
64
  default: 0,
52
65
  index: true
53
66
  },
54
67
 
68
+ /** Error details if processing failed */
55
69
  error_message: {
56
70
  type: String,
57
71
  trim: true,
58
72
  },
59
73
 
74
+ /** Last modification timestamp */
60
75
  updated_at: {
61
76
  type: Date,
62
77
  default: Date.now
63
78
  },
64
79
 
80
+ /** Creation timestamp */
65
81
  created_at: {
66
82
  type: Date,
67
83
  default: Date.now,
package/schemas/Order.js CHANGED
@@ -5,13 +5,19 @@ const AttachmentObject = require('./types/AttachmentObject')
5
5
  const FulfillmentObject = require('./types/FulfillmentObject')
6
6
 
7
7
 
8
+ /**
9
+ * Order — Main order entity.
10
+ * Tracks e-commerce orders from multiple sales channels (TikTok, Shopify, etc.).
11
+ */
8
12
  const Order = new Schema({
13
+ /** Display name of the order (e.g., "#1001") */
9
14
  name: {
10
15
  type: String,
11
16
  trim: true,
12
17
  index: true,
13
18
  },
14
19
 
20
+ /** External order ID from the source platform */
15
21
  order_id: {
16
22
  type: String,
17
23
  trim: true,
@@ -19,6 +25,7 @@ const Order = new Schema({
19
25
  required: true
20
26
  },
21
27
 
28
+ /** Sales channel type, default 'tiktok' */
22
29
  type: {
23
30
  type: String,
24
31
  trim: true,
@@ -26,52 +33,62 @@ const Order = new Schema({
26
33
  index: true,
27
34
  },
28
35
 
36
+ /** Reference to the Shop this order belongs to */
29
37
  shop: {
30
38
  type: Schema.Types.ObjectId,
31
39
  index: true,
32
40
  },
33
41
 
42
+ /** Type of shop at the time of order creation */
34
43
  shop_type: {
35
44
  type: String,
36
45
  trim: true,
37
46
  index: true,
38
47
  },
39
48
 
49
+ /** Reference to the FulfillmentStore handling this order */
40
50
  fulfillment_store: {
41
51
  type: Schema.Types.ObjectId,
42
52
  index: true,
43
53
  },
44
54
 
55
+ /** Reference to the current OrderFulfillment record */
45
56
  fulfillment: {
46
57
  type: Schema.Types.ObjectId,
47
58
  index: true,
48
59
  },
49
60
 
61
+ /** Recipient's shipping address (embedded) */
50
62
  shipping_address: {
51
63
  type: ShippingAddress,
52
64
  },
53
65
 
66
+ /** Internal note visible to staff */
54
67
  note: {
55
68
  type: String,
56
69
  trim: true,
57
70
  },
58
71
 
72
+ /** Note from the customer or source platform */
59
73
  external_note: {
60
74
  type: String,
61
75
  trim: true,
62
76
  },
63
77
 
78
+ /** Payment method used (e.g., 'cod', 'online') */
64
79
  payment_method: {
65
80
  type: String,
66
81
  trim: true,
67
82
  },
68
83
 
84
+ /** Order status on the source platform */
69
85
  platform_status: {
70
86
  type: String,
71
87
  trim: true,
72
88
  index: true,
73
89
  },
74
90
 
91
+ /** Fulfillment progress: 'unfulfilled' | 'processing' | 'fulfilled' | 'cancelled' */
75
92
  fulfillment_status: {
76
93
  type: String,
77
94
  default: 'unfulfilled',
@@ -79,6 +96,7 @@ const Order = new Schema({
79
96
  index: true
80
97
  },
81
98
 
99
+ /** Approval status: 'pending' | 'approved' | 'rejected' */
82
100
  validation_status: {
83
101
  type: String,
84
102
  default: 'pending',
@@ -86,141 +104,168 @@ const Order = new Schema({
86
104
  index: true
87
105
  },
88
106
 
107
+ /** Total item quantity in this order */
89
108
  quantity: {
90
109
  type: Number,
91
110
  default: 1,
92
111
  },
93
112
 
113
+ /** Order total amount with currency (embedded) */
94
114
  amount: {
95
115
  type: MoneyObject,
96
116
  },
97
117
 
118
+ /** Special instructions for fulfillment */
98
119
  fulfillment_note: {
99
120
  type: String,
100
121
  trim: true,
101
122
  },
102
123
 
124
+ /** Timestamp when the order was created on the source platform */
103
125
  order_created_at: {
104
126
  type: Date,
105
127
  index: true,
106
128
  default: Date.now,
107
129
  },
108
130
 
131
+ /** Last time this order was synced from the source platform */
109
132
  last_synced_at: {
110
133
  type: Date,
111
134
  default: Date.now,
112
135
  index: true
113
136
  },
114
137
 
138
+ /** How many times this order has been synced */
115
139
  sync_count: {
116
140
  type: Number,
117
141
  default: 0,
118
142
  },
119
143
 
144
+ /** Error message from the last failed sync attempt */
120
145
  last_sync_error: {
121
146
  type: String,
122
147
  trim: true,
123
148
  },
124
149
 
150
+ /** Mapped order ID in the Nhanh.vn system */
125
151
  nhanh_id: {
126
152
  type: String,
127
153
  trim: true,
128
154
  },
129
155
 
156
+ /** List of validation steps that have passed */
130
157
  valid_steps: {
131
158
  type: [String],
132
159
  default: [],
133
160
  index: true
134
161
  },
135
162
 
163
+ /** Number of attempts to map SKU for this order */
136
164
  map_sku_attempts: {
137
165
  type: Number,
138
166
  default: 0,
139
167
  index: true
140
168
  },
141
169
 
170
+ /** Reference to the most recent shipping Label */
142
171
  last_label: {
143
172
  type: Schema.Types.ObjectId,
144
173
  index: true,
145
174
  },
146
175
 
176
+ /** Flexible metadata from the source platform */
147
177
  metadata: {
148
178
  type: Schema.Types.Mixed,
149
179
  default: {}
150
180
  },
151
181
 
182
+ /** Logistics/carrier data (tracking info, carrier responses) */
152
183
  logistic_data: {
153
184
  type: Schema.Types.Mixed,
154
185
  default: {}
155
186
  },
156
187
 
188
+ /** Storage location identifier for the shipping label file */
157
189
  label_location: {
158
190
  type: String,
159
191
  trim: true,
160
192
  },
161
193
 
194
+ /** Attached images (e.g., customer-uploaded design files) */
162
195
  attachments: {
163
196
  type: [AttachmentObject],
164
197
  default: []
165
198
  },
166
199
 
200
+ /** Categorization tags for filtering and grouping */
167
201
  tags: {
168
202
  type: [String],
169
203
  default: [],
170
204
  index: true
171
205
  },
172
206
 
207
+ /** Number of attempts to push this order to a shipping carrier */
173
208
  push_to_carrier_attempts: {
174
209
  type: Number,
175
210
  default: 0,
176
211
  index: true
177
212
  },
178
213
 
214
+ /** Reference to the ShippingCarrier assigned to this order */
179
215
  shipping_carrier: {
180
216
  type: Schema.Types.ObjectId,
181
217
  index: true
182
218
  },
183
219
 
220
+ /** List of fulfillment number + production status pairs (embedded) */
184
221
  fulfillments: {
185
222
  type: [FulfillmentObject],
186
223
  default: []
187
224
  },
188
225
 
226
+ /** External sync identifier for deduplication */
189
227
  sync_id: {
190
228
  type: String,
191
229
  trim: true,
192
230
  },
193
231
 
232
+ /** Mapped order ID in the Pancake system */
194
233
  pancake_system_id: {
195
234
  type: String,
196
235
  trim: true,
197
236
  },
198
237
 
238
+ /** Whether this order was imported from a legacy system */
199
239
  is_legacy: {
200
240
  type: Boolean,
201
241
  },
202
242
 
243
+ /** Whether this order comes from a marketplace channel */
203
244
  is_marketplace: {
204
245
  type: Boolean,
205
246
  default: false,
206
247
  index: true
207
248
  },
208
249
 
250
+ /** Estimated delivery date from the carrier */
209
251
  estimate_delivery_date: {
210
252
  type: Date,
211
253
  index: true,
212
254
  },
213
255
 
256
+ /** Timestamp when this order was pushed to the carrier */
214
257
  pushed_at: {
215
258
  type: Date,
216
259
  index: true
217
260
  },
218
261
 
262
+ /** Last modification timestamp */
219
263
  updated_at: {
220
264
  type: Date,
221
265
  default: Date.now
222
266
  },
223
267
 
268
+ /** Creation timestamp */
224
269
  created_at: {
225
270
  type: Date,
226
271
  default: Date.now,
@@ -250,4 +295,3 @@ Order.index({
250
295
  })
251
296
 
252
297
  module.exports = Order
253
-