@pintahub/database-schemas 4.3.7 → 4.3.9

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 ADDED
@@ -0,0 +1,175 @@
1
+ # @pintahub/database-schemas
2
+
3
+ Shared Mongoose schema definitions for PintaHub microservices. This package is the single source of truth for all MongoDB data models — services import schemas from here to ensure consistency.
4
+
5
+ ## Usage
6
+
7
+ This package is used via the **schemis** library — it does not work standalone.
8
+
9
+ ### Database Connection Setup
10
+
11
+ ```js
12
+ // src/connections/database.js
13
+ const {createConnection, createStore} = require('schemis')
14
+ const schemas = require('@pintahub/database-schemas')
15
+
16
+ const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017/dev'
17
+ const connection = createConnection(uri)
18
+
19
+ const store = createStore({
20
+ connection,
21
+ schemas
22
+ })
23
+
24
+ module.exports = store
25
+ ```
26
+
27
+ ### Using Models in Actions
28
+
29
+ ```js
30
+ const {getModel} = require('../../connections/database')
31
+
32
+ const Product = getModel('Product')
33
+
34
+ // Standard Mongoose operations
35
+ const product = await Product.findOne({_id: productId, store: storeId}).lean()
36
+ await Product.updateOne({_id: productId}, {$set: {status: 'active', updated_at: Date.now()}})
37
+ ```
38
+
39
+ ### Populate with Explicit Model
40
+
41
+ ```js
42
+ const {getModel} = require('../../connections/database')
43
+
44
+ const TransferJob = getModel('TransferJob')
45
+ const Product = getModel('Product')
46
+ const Store = getModel('Store')
47
+
48
+ const items = await TransferJob
49
+ .find({store: storeId})
50
+ .populate({path: 'product', model: Product, select: {title: 1, code: 1}})
51
+ .populate({path: 'destination_store', model: Store, select: {name: 1}})
52
+ .lean()
53
+ ```
54
+
55
+ ## Dependencies
56
+
57
+ - **mongoose** `^9.1.3` (peer dependency)
58
+ - **schemis** `^2.0.2` — used by consumers to create database store and register models from schemas
59
+
60
+ ## Directory Structure
61
+
62
+ ```
63
+ schemas/ # Main schema files (~60 schemas)
64
+ schemas/types/ # Embedded sub-document types (BrandSettings, FacebookObject, etc.)
65
+ schemas/products/ # Product-specific embedded types (MediaObject, SeoObject, VideoObject)
66
+ index.js # Exports path to schemas/ directory
67
+ ```
68
+
69
+ ## Schema Catalog
70
+
71
+ ### Accounts & Auth
72
+ - **Account** — Seller accounts (email, password, role, status)
73
+ - **User** — User-to-Store relationship (refs: store, account)
74
+ - **Store** — Main store entity (subdomain, primary_domain, status, users[])
75
+ - **Shop** — Shop within a Store (handle, products_count)
76
+ - **ShopifyAPI** — Shopify API credentials per store
77
+
78
+ ### Products
79
+ - **Product** — Core product (title, handle, status, price_range, tags, collections). Full-text index on title/alternative_title/code/tags
80
+ - **ProductFeature** — Extended details (body_html, size_guide, shipping_time, video)
81
+ - **ProductImage** — Product images with dimensions and upload status
82
+ - **ProductRaw** — Raw synced product data from source platforms
83
+ - **ProductType** — Product type classification
84
+ - **ProductTag** — Tag with aggregated counts
85
+ - **ProductImport** — Import job tracking (url, platform, status)
86
+ - **Customize** — Product customization config
87
+ - **CustomField** — Dynamic fields for customization
88
+
89
+ ### Collections & Groups
90
+ - **Collection** — Product collections (title, handle, SEO, featured_image)
91
+ - **Group** — Product grouping/bundles (items_count, style, tags)
92
+ - **GroupItem** — Items within a group (refs: group, product)
93
+ - **GroupArtwork** — Artwork assigned to groups
94
+
95
+ ### Orders & Fulfillment
96
+ - **Order** — Orders (shipping_address, fulfillment_status, financial_status, total_price). Full-text index on name/id/email/phone
97
+ - **OrderItem** — Line items (quantity, price, variant info)
98
+ - **Fulfillment** — Shipment tracking (tracking_number, tracking_url)
99
+ - **Payout** — Payment payouts (net amount, status, type)
100
+
101
+ ### Content & Pages
102
+ - **Post** — Blog posts (title, body_html, excerpt, author, tags, SEO)
103
+ - **Menu** / **MenuItem** — Navigation menus (hierarchical via parent ref)
104
+ - **AnnouncementBar** — Store banner announcements
105
+
106
+ ### Media & Assets
107
+ - **Image** — Stored images (path, dimension, mimetype, size)
108
+ - **Artwork** — Design artwork uploads with processing status
109
+ - **Media** — General media files
110
+ - **MediaUpload** — Media upload tracking per product
111
+
112
+ ### Analytics & Tracking
113
+ - **StoreEvent** — Store activity events (TTL index on created_at)
114
+ - **LatestEvent** — Latest event snapshots (TTL: 30 days)
115
+ - **RecentView** — Recently viewed products (TTL: 90 days)
116
+ - **SearchTerm** — Search term tracking
117
+ - **FavoriteItem** — Favorited products per session
118
+ - **TrackPage** — Page access logs (TTL: 7 days)
119
+ - **MarketingCost** — Ad campaign cost tracking per product
120
+
121
+ ### Short URLs
122
+ - **ShortUrl** — Short links (slug + domain, clicks_count)
123
+ - **ShortDomain** — Short link domains
124
+ - **ShortLog** — Click tracking for short URLs
125
+ - **LogURL** — General URL logging
126
+
127
+ ### Jobs & Events
128
+ - **ExportJob** — Data export jobs (status, path_file)
129
+ - **TransferJob** — Product transfer between stores
130
+ - **WebhookEvent** — Webhook event queue (TTL: 2 days)
131
+
132
+ ### Settings & Config
133
+ - **StoreSetting** — Store configuration (brand, logo, socials, integrations)
134
+ - **BlockedLocation** — Geographic blocking rules
135
+ - **Publication** — Product publication channels
136
+ - **ShopifyObject** — Synced Shopify data
137
+
138
+ ### Reports
139
+ - **CreatorReport** — Monthly creator performance report per store (account ref, period "YYYY-MM", orders_count, items_sold, revenue, ads_spent, profit, status: active|completed|deleted, last_aggregated_at)
140
+
141
+ ### Reviews
142
+ - **Review** — Product reviews (vote_value, content, country_code, source)
143
+
144
+ ## Common Embedded Types
145
+
146
+ Used as sub-documents across multiple schemas:
147
+
148
+ | Type | Fields | Used In |
149
+ |------|--------|---------|
150
+ | **MoneyObject** | amount, currency (default: 'USD') | Order, OrderItem, Payout, MarketingCost |
151
+ | **ImageObject** | id, altText, url, width, height | Product, Collection, Post, StoreSetting |
152
+ | **DimensionObject** | width, height | Image, ProductImage |
153
+ | **SeoObject** | title, description | Collection, ProductRaw |
154
+ | **VideoObject** | id, url, width, height, mime_type | ProductFeature |
155
+ | **MediaObject** | id, url, alt_text, width, height, mime_type, content_type | ProductRaw |
156
+ | **PriceRange** | minVariantPrice, maxVariantPrice | Product |
157
+
158
+ ### Store Setting Types (schemas/types/)
159
+
160
+ BrandSettings, DMCASetting, FacebookObject, FooterSetting, FreeShippingSetting, GoogleAnalytics, KlaviyoObject, MerchizeSettings, SocialsObject, TopBarSettings, TrustpilotObject
161
+
162
+ ## Conventions
163
+
164
+ - Each schema file exports a Mongoose Schema (not a Model) — consumers register models themselves
165
+ - All schemas with store data include a `store` ref field indexed for query performance
166
+ - Timestamps: most schemas use `created_at` / `updated_at` fields (not Mongoose timestamps option)
167
+ - Status fields use string enums (e.g., `'active'|'inactive'`, `'pending'|'completed'|'failed'`)
168
+ - Embedded types in `schemas/types/` and `schemas/products/` have `{ _id: false }`
169
+ - TTL indexes are used for ephemeral data (events, webhooks, page tracking)
170
+ - Text indexes exist on Product (title, alternative_title, code, tags) and Order (name, id, email, phone)
171
+ - Consumers use `schemis` to create a store: `createStore({connection, schemas})` → `store.getModel('Name')`
172
+ - Use `.lean()` for read-only queries (returns plain objects instead of Mongoose documents)
173
+ - Use `.populate()` with explicit `model` parameter for references
174
+ - Use `Promise.all()` for parallel queries (e.g., fetch + countDocuments)
175
+ - Multi-tenancy: most queries filter by `store` field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pintahub/database-schemas",
3
- "version": "4.3.7",
3
+ "version": "4.3.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,8 @@
15
15
  "license": "ISC",
16
16
  "homepage": "https://gitlab.com/pintahub/packages/database-schemas#readme",
17
17
  "peerDependencies": {
18
- "mongoose": "^9.1.3"
18
+ "mongoose": "^9.1.3",
19
+ "schemis": "^2.0.2"
19
20
  },
20
21
  "devDependencies": {
21
22
  "mongoose": "^9.1.3"
@@ -0,0 +1,77 @@
1
+ const {Schema} = require('mongoose')
2
+ const MoneyObject = require('./MoneyObject')
3
+
4
+
5
+ const CreatorReport = new Schema({
6
+ store: {
7
+ type: Schema.Types.ObjectId,
8
+ index: true,
9
+ required: true,
10
+ },
11
+
12
+ account: {
13
+ type: Schema.Types.ObjectId,
14
+ index: true,
15
+ required: true,
16
+ },
17
+
18
+ period: {
19
+ type: String,
20
+ trim: true,
21
+ required: true,
22
+ index: true,
23
+ },
24
+
25
+ orders_count: {
26
+ type: Number,
27
+ default: 0,
28
+ },
29
+
30
+ items_sold: {
31
+ type: Number,
32
+ default: 0,
33
+ },
34
+
35
+ revenue: {
36
+ type: MoneyObject,
37
+ },
38
+
39
+ ads_spent: {
40
+ type: MoneyObject,
41
+ },
42
+
43
+ profit: {
44
+ type: MoneyObject,
45
+ },
46
+
47
+ status: {
48
+ type: String,
49
+ trim: true,
50
+ default: 'active',
51
+ enum: ['active', 'completed', 'deleted'],
52
+ index: true,
53
+ },
54
+
55
+ note: {
56
+ type: String,
57
+ trim: true,
58
+ },
59
+
60
+ last_aggregated_at: {
61
+ type: Date,
62
+ },
63
+
64
+ updated_at: {
65
+ type: Date,
66
+ default: Date.now,
67
+ },
68
+
69
+ created_at: {
70
+ type: Date,
71
+ default: Date.now,
72
+ index: true,
73
+ },
74
+ })
75
+
76
+
77
+ module.exports = CreatorReport
package/schemas/Page.js DELETED
@@ -1,50 +0,0 @@
1
- const {Schema} = require('mongoose')
2
-
3
-
4
- const Page = new Schema({
5
- store: {
6
- type: Schema.Types.ObjectId,
7
- index: true,
8
- required: true,
9
- },
10
-
11
- id: {
12
- type: String,
13
- index: true,
14
- required: true,
15
- },
16
-
17
- handle: {
18
- type: String,
19
- trim: true,
20
- index: true,
21
- },
22
-
23
- status: {
24
- type: String,
25
- index: true,
26
- },
27
-
28
- title: {
29
- type: String,
30
- trim: true,
31
- },
32
-
33
- body_html: {
34
- type: String,
35
- trim: true,
36
- },
37
-
38
- updated_at: {
39
- type: Date,
40
- default: Date.now
41
- },
42
-
43
- created_at: {
44
- type: Date,
45
- default: Date.now
46
- }
47
- })
48
-
49
- module.exports = Page
50
-
@@ -1,52 +0,0 @@
1
- const {Schema} = require('mongoose')
2
-
3
-
4
- const ProductProfile = new Schema({
5
- store: {
6
- type: Schema.Types.ObjectId,
7
- index: true,
8
- required: true,
9
- },
10
-
11
- product_type: {
12
- type: String,
13
- trim: true,
14
- required: true,
15
- index: true,
16
- },
17
-
18
- features_html: {
19
- type: String,
20
- trim: true,
21
- },
22
-
23
- size_chart_image: {
24
- type: Schema.Types.ObjectId,
25
- ref: 'Image',
26
- },
27
-
28
- ship_from: {
29
- type: String,
30
- trim: true,
31
- },
32
-
33
- status: {
34
- type: String,
35
- enum: ['active', 'inactive'],
36
- default: 'inactive',
37
- index: true,
38
- },
39
-
40
- updated_at: {
41
- type: Date,
42
- default: Date.now,
43
- },
44
-
45
- created_at: {
46
- type: Date,
47
- default: Date.now,
48
- index: true,
49
- }
50
- })
51
-
52
- module.exports = ProductProfile