@pintahub/database-schemas 4.3.6 → 4.3.8

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,174 @@
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
+ - **ProductProfile** — Per-product-type settings (features_html, ship_from)
86
+ - **ProductImport** — Import job tracking (url, platform, status)
87
+ - **Customize** — Product customization config
88
+ - **CustomField** — Dynamic fields for customization
89
+
90
+ ### Collections & Groups
91
+ - **Collection** — Product collections (title, handle, SEO, featured_image)
92
+ - **Group** — Product grouping/bundles (items_count, style, tags)
93
+ - **GroupItem** — Items within a group (refs: group, product)
94
+ - **GroupArtwork** — Artwork assigned to groups
95
+
96
+ ### Orders & Fulfillment
97
+ - **Order** — Orders (shipping_address, fulfillment_status, financial_status, total_price). Full-text index on name/id/email/phone
98
+ - **OrderItem** — Line items (quantity, price, variant info)
99
+ - **Fulfillment** — Shipment tracking (tracking_number, tracking_url)
100
+ - **Payout** — Payment payouts (net amount, status, type)
101
+
102
+ ### Content & Pages
103
+ - **Page** — Static pages (handle, title, body_html)
104
+ - **Post** — Blog posts (title, body_html, excerpt, author, tags, SEO)
105
+ - **Menu** / **MenuItem** — Navigation menus (hierarchical via parent ref)
106
+ - **AnnouncementBar** — Store banner announcements
107
+
108
+ ### Media & Assets
109
+ - **Image** — Stored images (path, dimension, mimetype, size)
110
+ - **Artwork** — Design artwork uploads with processing status
111
+ - **Media** — General media files
112
+ - **MediaUpload** — Media upload tracking per product
113
+
114
+ ### Analytics & Tracking
115
+ - **StoreEvent** — Store activity events (TTL index on created_at)
116
+ - **LatestEvent** — Latest event snapshots (TTL: 30 days)
117
+ - **RecentView** — Recently viewed products (TTL: 90 days)
118
+ - **SearchTerm** — Search term tracking
119
+ - **FavoriteItem** — Favorited products per session
120
+ - **TrackPage** — Page access logs (TTL: 7 days)
121
+ - **MarketingCost** — Ad campaign cost tracking per product
122
+
123
+ ### Short URLs
124
+ - **ShortUrl** — Short links (slug + domain, clicks_count)
125
+ - **ShortDomain** — Short link domains
126
+ - **ShortLog** — Click tracking for short URLs
127
+ - **LogURL** — General URL logging
128
+
129
+ ### Jobs & Events
130
+ - **ExportJob** — Data export jobs (status, path_file)
131
+ - **TransferJob** — Product transfer between stores
132
+ - **WebhookEvent** — Webhook event queue (TTL: 2 days)
133
+
134
+ ### Settings & Config
135
+ - **StoreSetting** — Store configuration (brand, logo, socials, integrations)
136
+ - **BlockedLocation** — Geographic blocking rules
137
+ - **Publication** — Product publication channels
138
+ - **ShopifyObject** — Synced Shopify data
139
+
140
+ ### Reviews
141
+ - **Review** — Product reviews (vote_value, content, country_code, source)
142
+
143
+ ## Common Embedded Types
144
+
145
+ Used as sub-documents across multiple schemas:
146
+
147
+ | Type | Fields | Used In |
148
+ |------|--------|---------|
149
+ | **MoneyObject** | amount, currency (default: 'USD') | Order, OrderItem, Payout, MarketingCost |
150
+ | **ImageObject** | id, altText, url, width, height | Product, Collection, Post, StoreSetting |
151
+ | **DimensionObject** | width, height | Image, ProductImage |
152
+ | **SeoObject** | title, description | Collection, ProductRaw |
153
+ | **VideoObject** | id, url, width, height, mime_type | ProductFeature |
154
+ | **MediaObject** | id, url, alt_text, width, height, mime_type, content_type | ProductRaw |
155
+ | **PriceRange** | minVariantPrice, maxVariantPrice | Product |
156
+
157
+ ### Store Setting Types (schemas/types/)
158
+
159
+ BrandSettings, DMCASetting, FacebookObject, FooterSetting, FreeShippingSetting, GoogleAnalytics, KlaviyoObject, MerchizeSettings, SocialsObject, TopBarSettings, TrustpilotObject
160
+
161
+ ## Conventions
162
+
163
+ - Each schema file exports a Mongoose Schema (not a Model) — consumers register models themselves
164
+ - All schemas with store data include a `store` ref field indexed for query performance
165
+ - Timestamps: most schemas use `created_at` / `updated_at` fields (not Mongoose timestamps option)
166
+ - Status fields use string enums (e.g., `'active'|'inactive'`, `'pending'|'completed'|'failed'`)
167
+ - Embedded types in `schemas/types/` and `schemas/products/` have `{ _id: false }`
168
+ - TTL indexes are used for ephemeral data (events, webhooks, page tracking)
169
+ - Text indexes exist on Product (title, alternative_title, code, tags) and Order (name, id, email, phone)
170
+ - Consumers use `schemis` to create a store: `createStore({connection, schemas})` → `store.getModel('Name')`
171
+ - Use `.lean()` for read-only queries (returns plain objects instead of Mongoose documents)
172
+ - Use `.populate()` with explicit `model` parameter for references
173
+ - Use `Promise.all()` for parallel queries (e.g., fetch + countDocuments)
174
+ - 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.6",
3
+ "version": "4.3.8",
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"
@@ -5,6 +5,7 @@ const Account = new Schema({
5
5
  name: {
6
6
  type: String,
7
7
  trim: true,
8
+ index: true
8
9
  },
9
10
 
10
11
  email: {
@@ -15,7 +16,7 @@ const Account = new Schema({
15
16
 
16
17
  password: {
17
18
  type: String,
18
- trim: true,
19
+ trim: true
19
20
  },
20
21
 
21
22
  role: {
@@ -27,7 +28,7 @@ const Account = new Schema({
27
28
  is_creator: {
28
29
  type: Boolean,
29
30
  default: false,
30
- index: true,
31
+ index: true
31
32
  },
32
33
 
33
34
  status: {
@@ -38,7 +39,12 @@ const Account = new Schema({
38
39
  },
39
40
 
40
41
  last_active_at: {
41
- type: Date,
42
+ type: Date
43
+ },
44
+
45
+ ad_accounts: {
46
+ type: [String],
47
+ default: []
42
48
  },
43
49
 
44
50
  updated_at: {