@clidey/dory 0.1.0 → 0.2.0
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/README.md +1 -1
- package/docs/api-playground-demo.mdx +119 -0
- package/docs/api-reference/openapi.json +366 -0
- package/docs/api-reference/operations/create.mdx +5 -0
- package/docs/api-reference/operations/delete.mdx +5 -0
- package/docs/api-reference/operations/get.mdx +5 -0
- package/docs/api-reference/operations/update.mdx +5 -0
- package/docs/assets/dory.jpeg +0 -0
- package/docs/dory.json +12 -131
- package/docs/favicon.svg +75 -0
- package/docs/features.mdx +440 -0
- package/docs/introduction.mdx +44 -0
- package/docs/logo/logo.png +0 -0
- package/package.json +3 -2
- package/src/mdx/source.tsx +15 -4
- package/docs/README.md +0 -2
- package/docs/configuration/app-settings/feature-flags.mdx +0 -157
- package/docs/configuration/app-settings/user-settings.mdx +0 -201
- package/docs/configuration/installation-setup/env-vars.mdx +0 -198
- package/docs/configuration/installation-setup/installation.mdx +0 -127
- package/docs/integrations/analytics-monitoring/error-tracking.mdx +0 -199
- package/docs/integrations/analytics-monitoring/notifications.mdx +0 -189
- package/docs/integrations/analytics-monitoring/user-analytics.mdx +0 -182
- package/docs/integrations/shopify-integration/shopify-setup.mdx +0 -226
- package/docs/integrations/shopify-integration/shopify-webhooks.mdx +0 -207
- package/docs/overview/developer-overview/dev-architecture.mdx +0 -292
- package/docs/overview/product-intro/app-overview.mdx +0 -167
- package/docs/overview/product-intro/architecture.mdx +0 -203
- package/docs/overview/product-intro/core-concepts.mdx +0 -267
- package/docs/platform-admin/billing-subscriptions/billing.mdx +0 -176
- package/docs/platform-admin/system-maintenance/db-migrations.mdx +0 -184
- package/docs/platform-admin/system-maintenance/health-monitoring.mdx +0 -222
- package/docs/platform-admin/system-maintenance/queue-management.mdx +0 -234
- package/docs/platform-admin/user-team-management/teams.mdx +0 -170
- package/docs/platform-admin/user-team-management/users.mdx +0 -185
- package/docs/support/legal/dependency-analysis.mdx +0 -132
- package/docs/support/legal/privacy-terms.mdx +0 -73
- package/docs/support/troubleshooting/common-issues.mdx +0 -159
- package/docs/usage/api-usage/api-inventory.mdx +0 -213
- package/docs/usage/api-usage/api-products.mdx +0 -249
- package/docs/usage/api-usage/api-purchase-orders.mdx +0 -289
- package/docs/usage/api-usage/api-reports.mdx +0 -227
- package/docs/usage/api-usage/api-suppliers.mdx +0 -171
- package/docs/usage/api-usage/api-user-management.mdx +0 -171
- package/docs/usage/ui-workflows/bundles.mdx +0 -157
- package/docs/usage/ui-workflows/demand-planning.mdx +0 -210
- package/docs/usage/ui-workflows/favorites.mdx +0 -167
- package/docs/usage/ui-workflows/inventory-management.mdx +0 -179
- package/docs/usage/ui-workflows/onboarding.mdx +0 -215
- package/docs/usage/ui-workflows/purchase-orders.mdx +0 -200
- package/docs/usage/ui-workflows/reports.mdx +0 -257
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Inventory API'
|
|
3
|
-
description: 'Endpoints to get, export, ignore, and favorite inventory items.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## Inventory API
|
|
7
|
-
|
|
8
|
-
### 1. Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The **Inventory API** is a critical backend service component responsible for managing and exposing inventory-related data and operations within the Genie application. It acts as the interface between Shopify's data and internal business logic, providing aggregated, transformed, and actionable inventory information to both internal services and frontend clients.
|
|
11
|
-
|
|
12
|
-
Within the system's architecture, this API handles inventory retrieval, adjustments, categorizations, and supports various inventory-focused workflows such as reporting, demand planning, and purchase order generation.
|
|
13
|
-
|
|
14
|
-
### 2. Technical Overview
|
|
15
|
-
|
|
16
|
-
This API is implemented primarily through the `ShopifyProductsService` and `InventoryService` classes, leveraging NestJS framework patterns including dependency injection (`@Injectable`) for modularity and testability.
|
|
17
|
-
|
|
18
|
-
- **Main Integration Points:**
|
|
19
|
-
- **Shopify GraphQL and REST APIs:** Via the `ShopifyApiService`, it fetches real-time inventory and product information.
|
|
20
|
-
- **Database Views and Entities:** Uses PostgreSQL views such as `inventory_item` to consolidate product variant data with stock, sales metrics, supplier info, and location details.
|
|
21
|
-
- **Support Services:** Integrates with services for purchase order management, email notifications, and assets management.
|
|
22
|
-
|
|
23
|
-
#### Architecture Diagram
|
|
24
|
-
|
|
25
|
-
```mermaid
|
|
26
|
-
flowchart TD
|
|
27
|
-
subgraph "API Services"
|
|
28
|
-
invSrv["InventoryService"]:::service
|
|
29
|
-
shopifyProdSrv["ShopifyProductsService"]:::service
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
subgraph "Shopify Integration"
|
|
33
|
-
shopifyApi["ShopifyApiService"]:::external
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
subgraph "Database"
|
|
37
|
-
invItemView[("inventory_item (Postgres View)"):::database
|
|
38
|
-
productVariant["product_variant"]:::database
|
|
39
|
-
productSupplier["product_supplier"]:::database
|
|
40
|
-
purchaseOrder["purchase_order"]:::database
|
|
41
|
-
location["location"]:::database
|
|
42
|
-
inventoryItemHistory["inventory_item_history"]:::database
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
subgraph "Other Internal Services"
|
|
46
|
-
poService["PurchaseOrdersService"]:::service
|
|
47
|
-
emailService["EmailService"]:::service
|
|
48
|
-
assetService["AssetsService"]:::service
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
shopifyProdSrv -->|"Calls"| shopifyApi
|
|
52
|
-
invSrv -->|"Reads/Writes"| invItemView
|
|
53
|
-
invSrv -->|"Reads"| productVariant
|
|
54
|
-
invSrv -->|"Reads"| productSupplier
|
|
55
|
-
invSrv -->|"Reads"| purchaseOrder
|
|
56
|
-
invSrv -->|"Reads"| location
|
|
57
|
-
invSrv -->|"Reads/Writes"| inventoryItemHistory
|
|
58
|
-
invSrv -->|"Uses"| poService
|
|
59
|
-
invSrv -->|"Uses"| emailService
|
|
60
|
-
invSrv -->|"Uses"| assetService
|
|
61
|
-
|
|
62
|
-
shopifyProdSrv -->|"Manages"| inventoryItemHistory
|
|
63
|
-
|
|
64
|
-
classDef service fill:#f9f,stroke:#333,stroke-width:2px,color:#000;
|
|
65
|
-
classDef database fill:#ccf,stroke:#333,stroke-width:2px,color:#000;
|
|
66
|
-
classDef external fill:#cfc,stroke:#333,stroke-width:2px,color:#000;
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### 3. Core Concepts and Responsibilities
|
|
70
|
-
|
|
71
|
-
- **Inventory Items and Product Variants:** The system treats each product variant from Shopify as an inventory item, tracking its SKU, quantity, sales, pricing, and metadata.
|
|
72
|
-
|
|
73
|
-
- **Aggregated Inventory View:** Through the database `inventory_item` view, multiple data points are combined, including Shopify data, sales metrics, supplier info, and inventory at different locations.
|
|
74
|
-
|
|
75
|
-
- **Grading and Status:** Inventory items are assigned grading levels (A, B, C) and statuses (e.g., NEW_PRODUCT, OUT_OF_STOCK, RUNNING_LOW) based on sales and stock metrics, driven by configurable team settings.
|
|
76
|
-
|
|
77
|
-
- **Pagination and Chunking:** When dealing with large data sets like product categories or inventory items, the API breaks requests into manageable chunks (e.g., 250 or 300 item batches) for efficiency and API rate limit compliance.
|
|
78
|
-
|
|
79
|
-
- **Shopify ID Conversion:** Shopify uses global IDs; the system maps between internal numeric IDs and Shopify global IDs prefixed by `gid://shopify/`.
|
|
80
|
-
|
|
81
|
-
- **Exception Handling:** The API wraps Shopify and database calls within try/catch blocks, wrapping errors as `GenieException`s with context.
|
|
82
|
-
|
|
83
|
-
- **Inventory Adjustments:** Supports batch adjustments of inventory quantities per location via Shopify's GraphQL mutation.
|
|
84
|
-
|
|
85
|
-
- **Historical Data Management:** Periodically syncs history of inventory states and tracks events like last stockout to assist reporting and decision-making.
|
|
86
|
-
|
|
87
|
-
- **Filtering and Searching:** Supports complex filter criteria and full-text search across SKU, product title, and variant title with search weighting.
|
|
88
|
-
|
|
89
|
-
- **Ignore Flags:** Flags items or variants to be optionally excluded from certain operations via `ignore` flags.
|
|
90
|
-
|
|
91
|
-
### 4. Code Structure
|
|
92
|
-
|
|
93
|
-
- **Core Service:**
|
|
94
|
-
- `apps/api/src/shopify/services/shopify-products.service.ts` - Implements Shopify product-related APIs including fetching categories, products, inventory items, and inventory quantity adjustments.
|
|
95
|
-
|
|
96
|
-
- **Inventory Data Access:**
|
|
97
|
-
- `apps/api/src/pim/services/inventory.service.ts` - Handles deeper inventory item queries, filtering, sorting, history syncing, and exporting functions.
|
|
98
|
-
|
|
99
|
-
- **Database Views & Migrations:**
|
|
100
|
-
- `apps/api/src/migrations/db/*.ts` - Migration files defining and updating `inventory_item` view, including complex SQL that aggregates multiple inventory and sales-related fields and implements grading and status logic.
|
|
101
|
-
|
|
102
|
-
#### Example: Adjusting Inventory Quantities at a Location
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
async adjustLocationInventoryQuantities(
|
|
106
|
-
teamId: string,
|
|
107
|
-
itemsWithQuantities: AdjustInventoryQuantityItem[],
|
|
108
|
-
locationId: number
|
|
109
|
-
) {
|
|
110
|
-
const auth = await this.shopify.getAuthOrThrow(teamId);
|
|
111
|
-
|
|
112
|
-
const shopifyLocationId = `gid://shopify/Location/${locationId}`;
|
|
113
|
-
|
|
114
|
-
const query = gql`
|
|
115
|
-
mutation inventoryAdjustQuantities($input: InventoryAdjustQuantitiesInput!) {
|
|
116
|
-
inventoryAdjustQuantities(input: $input) {
|
|
117
|
-
userErrors {
|
|
118
|
-
field
|
|
119
|
-
message
|
|
120
|
-
}
|
|
121
|
-
inventoryAdjustmentGroup {
|
|
122
|
-
createdAt
|
|
123
|
-
reason
|
|
124
|
-
changes {
|
|
125
|
-
name
|
|
126
|
-
delta
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
`;
|
|
132
|
-
|
|
133
|
-
const result = await this.shopify.callApi(auth, async (sdk, session) =>
|
|
134
|
-
new sdk.clients.Graphql({ session }).request(query, {
|
|
135
|
-
input: {
|
|
136
|
-
reason: "correction",
|
|
137
|
-
name: "available",
|
|
138
|
-
changes: itemsWithQuantities.map(item => ({
|
|
139
|
-
delta: item.quantity,
|
|
140
|
-
inventoryItemId: `gid://shopify/InventoryItem/${item.id}`,
|
|
141
|
-
locationId: shopifyLocationId,
|
|
142
|
-
})),
|
|
143
|
-
},
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
if (result.errors?.message || result.data?.inventoryAdjustQuantities?.userErrors?.length) {
|
|
148
|
-
throw new GenieException(result.errors?.message ?? "Failed to adjust shopify location quantities", {
|
|
149
|
-
userErrors: result.data?.inventoryAdjustQuantities?.userErrors,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return result.data?.inventoryAdjustQuantities?.inventoryAdjustmentGroup;
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### 5. API and Interfaces
|
|
158
|
-
|
|
159
|
-
- **`ShopifyProductsService`**
|
|
160
|
-
- `getProductCategory(teamId: string, productId: number): Promise<string | null>`
|
|
161
|
-
Retrieves the category name of a single product via Shopify GraphQL.
|
|
162
|
-
|
|
163
|
-
- `getProductCategories(teamId: string, productIds: number[]): Promise<Record<string, string>>`
|
|
164
|
-
Retrieves categories for multiple products by chunking requests.
|
|
165
|
-
|
|
166
|
-
- `getProducts(teamId: string, args?: { ids?: number[]; query?: string })`
|
|
167
|
-
Retrieves products matching optional IDs or query string, paginated.
|
|
168
|
-
|
|
169
|
-
- `getInventoryItems(teamId: string, ids: number[]): Promise<InventoryItem[]>`
|
|
170
|
-
Retrieves inventory items in batches via REST with pagination.
|
|
171
|
-
|
|
172
|
-
- `adjustLocationInventoryQuantities(teamId: string, itemsWithQuantities: AdjustInventoryQuantityItem[], locationId: number)`
|
|
173
|
-
Adjusts inventory quantities at a Shopify location.
|
|
174
|
-
|
|
175
|
-
- And others: fetching collections, variants count, creating products and variants in bulk.
|
|
176
|
-
|
|
177
|
-
- **`InventoryService`**
|
|
178
|
-
- Core methods for filtering, sorting, search weighting, exporting inventory items.
|
|
179
|
-
- History syncing and retrieving historical inventory data.
|
|
180
|
-
- Methods for reports: stockout risk, asset values, dead stock, sales velocity.
|
|
181
|
-
|
|
182
|
-
- **Error Handling:**
|
|
183
|
-
All public methods throw `GenieException` on failures with contextual data about the operation and parameters.
|
|
184
|
-
|
|
185
|
-
### 6. Environment & Configuration
|
|
186
|
-
|
|
187
|
-
- No explicit environment variables are detailed here.
|
|
188
|
-
- The services depend on runtime configuration for Shopify API credentials supplied via `ShopifyApiService` and require PostgreSQL setup with the defined views.
|
|
189
|
-
|
|
190
|
-
### 7. Testing, Monitoring, and Deployment
|
|
191
|
-
|
|
192
|
-
- No explicit testing or deployment instructions are provided.
|
|
193
|
-
- Logging is integrated using NestJS Logger at the service level.
|
|
194
|
-
- Error handling uses `GenieException` for consistent exception wrapping.
|
|
195
|
-
|
|
196
|
-
### 8. Troubleshooting & Known Issues
|
|
197
|
-
|
|
198
|
-
- No documented known issues or troubleshooting procedures.
|
|
199
|
-
|
|
200
|
-
---
|
|
201
|
-
|
|
202
|
-
This concludes the internal Inventory API documentation, designed to provide comprehensive understanding for developers maintaining or extending the inventory-related backend services.
|
|
203
|
-
|
|
204
|
-
---
|
|
205
|
-
|
|
206
|
-
### References
|
|
207
|
-
- [ShopifyProductsService Source](/apps/api/src/shopify/services/shopify-products.service.ts)
|
|
208
|
-
- [InventoryService Source](/apps/api/src/pim/services/inventory.service.ts)
|
|
209
|
-
- Database Views Migration Samples:
|
|
210
|
-
- /apps/api/src/migrations/db/1716211523354-shipments-inventory.ts
|
|
211
|
-
- /apps/api/src/migrations/db/1701944032657-inventory-grading-values.ts
|
|
212
|
-
- /apps/api/src/migrations/db/1723014724470-sales-at-risk.ts
|
|
213
|
-
- And others in /apps/api/src/migrations/db/
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Product Management API'
|
|
3
|
-
description: 'Endpoints related to products, product variants, bundles, and supplier mappings.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## Product Management API
|
|
7
|
-
|
|
8
|
-
### 1. Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The Product Management API provides comprehensive functionality to manage products, product variants, bundles, collections, and supplier relationships within the Genie system. It enables syncing with Shopify, manipulation of product and variant metadata, managing supplier associations, and handling product bundles and collections.
|
|
11
|
-
|
|
12
|
-
This API is primarily used by the backend services and web clients to ensure seamless integration between Shopify data stores and Genie’s internal data model. It addresses challenges such as:
|
|
13
|
-
|
|
14
|
-
- Synchronizing product and inventory data from Shopify.
|
|
15
|
-
- Managing supplier mappings and variant tags.
|
|
16
|
-
- Handling bundles and collections relationships.
|
|
17
|
-
- Updating stock level settings and manual adjustments.
|
|
18
|
-
|
|
19
|
-
The system boundaries include interaction with Shopify services, internal repositories (Postgres via TypeORM), tracking services, and integrations with purchase order and workflow services.
|
|
20
|
-
|
|
21
|
-
### 2. Technical Overview
|
|
22
|
-
|
|
23
|
-
The Product Management API sits inside the `pim` (Product Information Management) domain. It integrates deeply with external Shopify services, internal sales order metrics, and team/user management for scoping data access.
|
|
24
|
-
|
|
25
|
-
Key backend services involved:
|
|
26
|
-
|
|
27
|
-
- **InsightsSyncService:** Syncs products, variants, collections, locations, and sales insights from Shopify.
|
|
28
|
-
- **ProductsService:** Exposes CRUD operations, bulk updates, supplier mappings, variant tagging, and bundle management.
|
|
29
|
-
- **IdeaProductsService:** Manages conceptual products before publishing to Shopify.
|
|
30
|
-
|
|
31
|
-
Dependencies and integrations:
|
|
32
|
-
|
|
33
|
-
- **ShopifyProductsService / ShopifyOrdersService:** Fetches product and order data from Shopify.
|
|
34
|
-
- **TeamsService:** For team-specific operations and access control.
|
|
35
|
-
- **InventorySalesMetricsService:** Updates sales and inventory metrics.
|
|
36
|
-
- **SalesOrdersService / PurchaseOrdersService:** For syncing sales data and purchase-related enhancements.
|
|
37
|
-
- **TrackingService:** Event tracking and analytics.
|
|
38
|
-
|
|
39
|
-
Technologies:
|
|
40
|
-
|
|
41
|
-
- Node.js with NestJS framework
|
|
42
|
-
- TypeORM for database interactions
|
|
43
|
-
- Various shared DTOs and validation via Zod
|
|
44
|
-
|
|
45
|
-
Design patterns include:
|
|
46
|
-
|
|
47
|
-
- Service-Oriented Architecture (SOA) with clearly defined domain services.
|
|
48
|
-
- Event-driven tracking and monitoring.
|
|
49
|
-
- Transactional database operations with upserts and batch processing.
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
### Mermaid Diagram: Component Interaction
|
|
54
|
-
|
|
55
|
-
```mermaid
|
|
56
|
-
flowchart TD
|
|
57
|
-
subgraph Frontend
|
|
58
|
-
UI["Web UI / API Clients"]:::frontend
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
subgraph Backend
|
|
62
|
-
subgraph "Product Management Domain"
|
|
63
|
-
PC["ProductsController"]:::service
|
|
64
|
-
PS["ProductsService"]:::service
|
|
65
|
-
IS["InsightsSyncService"]:::service
|
|
66
|
-
IPS["IdeaProductsService"]:::service
|
|
67
|
-
end
|
|
68
|
-
subgraph "Shopify Integration"
|
|
69
|
-
SPS["ShopifyProductsService"]:::service
|
|
70
|
-
SOS["ShopifyOrdersService"]:::service
|
|
71
|
-
SAS["ShopifyApiService"]:::service
|
|
72
|
-
end
|
|
73
|
-
subgraph "Inventory & Sales"
|
|
74
|
-
SS["SalesOrdersService"]:::service
|
|
75
|
-
ISM["InventorySalesMetricsService"]:::service
|
|
76
|
-
PPOS["PurchaseOrdersService"]:::service
|
|
77
|
-
end
|
|
78
|
-
subgraph "User Management"
|
|
79
|
-
TS["TeamsService"]:::service
|
|
80
|
-
end
|
|
81
|
-
subgraph "Tracking & Analytics"
|
|
82
|
-
TRS["TrackingService"]:::service
|
|
83
|
-
WFS["WorkflowService"]:::service
|
|
84
|
-
SLS["SlackService"]:::service
|
|
85
|
-
end
|
|
86
|
-
DB["Postgres DB"]:::database
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
UI -->|REST API calls| PC
|
|
90
|
-
PC -->|calls| PS
|
|
91
|
-
PC -->|calls| IS
|
|
92
|
-
PC -->|calls| IPS
|
|
93
|
-
|
|
94
|
-
IS -->|uses| SPS
|
|
95
|
-
IS -->|uses| SOS
|
|
96
|
-
IS -->|uses| SAS
|
|
97
|
-
IS -->|uses| TS
|
|
98
|
-
IS -->|updates| SS
|
|
99
|
-
IS -->|updates| ISM
|
|
100
|
-
|
|
101
|
-
PS -->|reads/writes| DB
|
|
102
|
-
IPS -->|reads/writes| DB
|
|
103
|
-
SS -->|reads/writes| DB
|
|
104
|
-
PPOS -->|reads/writes| DB
|
|
105
|
-
TRS -->|logs events| DB
|
|
106
|
-
WFS -->|workflow orchestration| DB
|
|
107
|
-
SLS -->|notifications| DB
|
|
108
|
-
|
|
109
|
-
classDef service fill:#1f78b4,stroke:#155d8a,color:#fff,font-weight:bold
|
|
110
|
-
classDef database fill:#33a02c,stroke:#1b6d17,color:#fff,font-weight:bold
|
|
111
|
-
classDef frontend fill:#fb9a99,stroke:#c6696b,color:#000,font-weight:bold
|
|
112
|
-
|
|
113
|
-
click PC "apps/api/src/pim/controllers/products.controller.ts"
|
|
114
|
-
click PS "apps/api/src/pim/services/products.service.ts"
|
|
115
|
-
click IS "apps/api/src/pim/services/insights-sync.service.ts"
|
|
116
|
-
click IPS "apps/api/src/pim/services/idea-products.service.ts"
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
### 3. Core Concepts and Responsibilities
|
|
122
|
-
|
|
123
|
-
- **Team Scoping:** All major APIs require a valid `teamId` context to operate. This scopes data to authorized entities.
|
|
124
|
-
- **Shopify Sync:** `InsightsSyncService` manages syncing from Shopify, including products, variants, collections, and inventory levels.
|
|
125
|
-
- **Manual Sync Control:** There is in-memory state tracking (`currentManualShopifyInsightsSyncingTeams`) to prevent concurrent manual sync requests per team.
|
|
126
|
-
- **Product Variants & Tags:** Variants are managed separately with tagging, supplier data, and stock levels.
|
|
127
|
-
- **Bundles:** Bundles are product variants of type `Bundle` that aggregate child components. Their relations can be updated via batch or individual operations.
|
|
128
|
-
- **Supplier Management:** Products and variants can have multiple suppliers mapped with primary designation and variant-level data such as unit cost and SKU.
|
|
129
|
-
- **Soft Deletes:** Products and variants missing from Shopify are soft deleted by setting `deletedAt` timestamp instead of hard delete.
|
|
130
|
-
- **Metrics Updates:** Sales and order metrics are updated asynchronously to maintain inventory insights.
|
|
131
|
-
|
|
132
|
-
**Ownership and Maintenance:**
|
|
133
|
-
|
|
134
|
-
- Maintained by the Product Management team.
|
|
135
|
-
- Logs via NestJS `Logger` for traceability.
|
|
136
|
-
- Exceptions wrapped in custom `GenieException` class.
|
|
137
|
-
|
|
138
|
-
**Non-Functional Requirements:**
|
|
139
|
-
|
|
140
|
-
- Scalability with batch processing and chunking (e.g., product upload chunks of 1000).
|
|
141
|
-
- Reliable sync by tracking with `DailySyncPerformanceTrackerService`.
|
|
142
|
-
- Conflict prevention for manual syncs.
|
|
143
|
-
- Security via team-based authorization (enforced at controller/service level).
|
|
144
|
-
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
### 4. Code Structure
|
|
148
|
-
|
|
149
|
-
- **Controllers:** Located under `apps/api/src/pim/controllers/`.
|
|
150
|
-
- `products.controller.ts` exposes HTTP endpoints for product CRUD, tagging, supplier management, bundles, collections.
|
|
151
|
-
- **Services:** Located under `apps/api/src/pim/services/`.
|
|
152
|
-
- `insights-sync.service.ts`: Handles Shopify synchronization and data import.
|
|
153
|
-
- `products.service.ts`: Core business logic for product querying, updates, and supplier relationships.
|
|
154
|
-
- `idea-products.service.ts`: Manages idea products workflow and publishing.
|
|
155
|
-
|
|
156
|
-
#### Key Service Methods from `InsightsSyncService`
|
|
157
|
-
```ts
|
|
158
|
-
public async syncDataForTeam({ teamId, sinceDays, trackingId, manual }) {
|
|
159
|
-
// Orchestrates syncing products, insights, and settings
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public async importShopifyProducts(teamId, products) {
|
|
163
|
-
// Transforms and batch imports Shopify products and variants
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private async markDeletedProductsAndVariants(teamId, shopifyProducts) {
|
|
167
|
-
// Marks missing products/variants as deleted
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private async syncLocations(teamId) {
|
|
171
|
-
// Syncs Shopify locations and inventory levels
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private async syncCollections(teamId) {
|
|
175
|
-
// Syncs Shopify collections and their associated products
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private async syncInsights({ teamId, sinceDays, trackingId }) {
|
|
179
|
-
// Syncs sales order data and updates sales/order metrics
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
#### Key Controller Endpoints in `ProductsController`
|
|
184
|
-
- `POST /products` - Fetch products with filtering, sorting, and pagination.
|
|
185
|
-
- `POST /products/sync-shopify` - Manually trigger Shopify sync for current user’s team.
|
|
186
|
-
- `GET /products/shopify-tags`, `/shopify-vendors`, `/shopify-categories` - Retrieve aggregated Shopify metadata.
|
|
187
|
-
- `POST /products/:productId/suppliers` - Set product suppliers.
|
|
188
|
-
- `POST /products/update-suppliers-for-variants` - Update suppliers across multiple variants.
|
|
189
|
-
- `PUT /products/:productId/variants/:variantId/landed-cost` - Update manual landed cost.
|
|
190
|
-
|
|
191
|
-
For extensive method and DTO details, refer to the source files noted above.
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
### 5. API and Interfaces
|
|
196
|
-
|
|
197
|
-
The main Product API exposes REST endpoints that:
|
|
198
|
-
|
|
199
|
-
- Allow fetching products with flexible filters.
|
|
200
|
-
- Enable tagging of variants.
|
|
201
|
-
- Permit management of product-supplier and variant-supplier mappings.
|
|
202
|
-
- Support bundle relations management.
|
|
203
|
-
- Provide manual sync entrypoints for Shopify data ingestion.
|
|
204
|
-
|
|
205
|
-
APIs rely on Zod schemas for input validation to ensure data integrity.
|
|
206
|
-
|
|
207
|
-
Failure modes mostly manifest as exceptions wrapped in `GenieException`, often with error contextual information such as `teamId` and entity IDs for traceability.
|
|
208
|
-
|
|
209
|
-
Authorization is enforced via user context containing `teamId`, ensuring all actions are scoped.
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
### 6. Environment & Configuration
|
|
214
|
-
|
|
215
|
-
The services depend on integration credentials for Shopify managed by `ShopifyApiService`.
|
|
216
|
-
|
|
217
|
-
No specific environment variables are described here.
|
|
218
|
-
|
|
219
|
-
Development setups require a running PostgreSQL database with entities defined under the `pim/entities/` directory.
|
|
220
|
-
|
|
221
|
-
---
|
|
222
|
-
|
|
223
|
-
### 7. Testing, Monitoring, and Deployment
|
|
224
|
-
|
|
225
|
-
While not explicitly covered in the provided context, logging is integral with NestJS `Logger`. Exception capturing uses the custom `captureException` utility, potentially tied to Sentry or alternative error-tracking.
|
|
226
|
-
|
|
227
|
-
Sync operations are tracked via `DailySyncPerformanceTrackerService` to monitor sync progress and performance.
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
### 8. Troubleshooting & Known Issues
|
|
232
|
-
|
|
233
|
-
- Manual Shopify syncs are guarded against concurrency per team. Attempting concurrent sync triggers a `ConflictException`.
|
|
234
|
-
- Soft deletes retain historical data; missing items in Shopify are soft deleted via timestamp.
|
|
235
|
-
- Batch operations process up to 1000 items at once to avoid DB overload.
|
|
236
|
-
|
|
237
|
-
No documented known bugs or operational runbooks are included.
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
### References
|
|
242
|
-
- [InsightsSyncService implementation](apps/api/src/pim/services/insights-sync.service.ts)
|
|
243
|
-
- [ProductsController implementation](apps/api/src/pim/controllers/products.controller.ts)
|
|
244
|
-
- [ProductsService implementation](apps/api/src/pim/services/products.service.ts)
|
|
245
|
-
- [IdeaProductsService implementation](apps/api/src/pim/services/idea-products.service.ts)
|
|
246
|
-
|
|
247
|
-
---
|
|
248
|
-
|
|
249
|
-
This document serves as a comprehensive technical reference for contributors and maintainers working on the Product Management API layer.
|