@clidey/dory 0.1.0 → 0.3.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 +9 -10
- package/src/mdx/fence.tsx +2 -1
- package/src/mdx/mermaid.tsx +39 -11
- 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,182 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'User Analytics & Tracking'
|
|
3
|
-
description: 'Details on user activity tracking using Google Analytics and tracking service abstractions.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## User Analytics & Tracking
|
|
7
|
-
|
|
8
|
-
### 1. Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The User Analytics & Tracking module is responsible for collecting, processing, and broadcasting user interaction events and system performance metrics throughout the Genie platform. It facilitates integrations with third-party analytics providers such as Google Analytics and Segment, and handles internal tracking of system sync performance and sales metrics. This module ensures comprehensive visibility into user behavior, system health, and operational workflows to support product improvement, monitoring, and reporting.
|
|
11
|
-
|
|
12
|
-
This component covers both frontend user tracking and backend event processing, acting as a critical layer bridging user interactions with analytical insights and operational telemetry.
|
|
13
|
-
|
|
14
|
-
### 2. Technical Overview
|
|
15
|
-
|
|
16
|
-
The system tracking architecture comprises two primary layers:
|
|
17
|
-
|
|
18
|
-
- **Frontend tracking:** Captures client-side user and web vital metrics and sends them to Google Analytics.
|
|
19
|
-
- **Backend tracking:** Implements event broadcasting and data sync tracking, integrating with third-party analytics platforms such as Segment and Hubspot.
|
|
20
|
-
|
|
21
|
-
#### Key components:
|
|
22
|
-
|
|
23
|
-
- **GoogleAnalyticsUserTracker (Frontend component):** Automatically sends authenticated user identity to Google Analytics.
|
|
24
|
-
- **TrackingService (Backend service):** Core event tracking service broadcasting events to configured channels.
|
|
25
|
-
- **SegmentService, HubspotChannel:** Specific channel integrations for analytics.
|
|
26
|
-
- **DailySyncPerformanceTrackerService:** Tracks and times performance of sync operations per team, aggregating metrics.
|
|
27
|
-
|
|
28
|
-
Mermaid diagram illustrating key interactions:
|
|
29
|
-
|
|
30
|
-
```mermaid
|
|
31
|
-
flowchart TD
|
|
32
|
-
subgraph Frontend
|
|
33
|
-
GAUserTracker["GoogleAnalyticsUserTracker"]:::frontend
|
|
34
|
-
GA["GoogleAnalytics (GA library)"]:::frontend
|
|
35
|
-
GAUserTracker -->|"set user_id"| GA
|
|
36
|
-
WebVitals["Next.js Web Vitals"]:::frontend -->|"sendGAEvent"| GA
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
subgraph Backend
|
|
40
|
-
TrackingService["TrackingService"]:::backend
|
|
41
|
-
SegmentChannel["SegmentChannel"]:::backend
|
|
42
|
-
HubspotChannel["HubspotChannel"]:::backend
|
|
43
|
-
SegmentService["SegmentService"]:::backend
|
|
44
|
-
SyncController["SyncController (Admin API) "]:::backend
|
|
45
|
-
DailyTracker["DailySyncPerformanceTrackerService"]:::backend
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
Frontend <--> |"User Interactions & Metrics"| Backend
|
|
49
|
-
TrackingService -->|"broadcastEvent"| SegmentChannel
|
|
50
|
-
TrackingService -->|"broadcastEvent"| HubspotChannel
|
|
51
|
-
SyncController -->|"sync operations"| DailyTracker
|
|
52
|
-
|
|
53
|
-
classDef frontend fill:#1976d2,stroke:#155fa0,color:#fff,stroke-width:1px
|
|
54
|
-
classDef backend fill:#4caf50,stroke:#357a38,color:#fff,stroke-width:1px
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### 3. Core Concepts and Responsibilities
|
|
59
|
-
|
|
60
|
-
- **User Identity in Google Analytics:** The `GoogleAnalyticsUserTracker` React component hooks into the authentication context and sets the current user ID for Google Analytics when the measurement ID environment variable is available.
|
|
61
|
-
|
|
62
|
-
- **Event Tracking Abstraction:** The backend `TrackingService` receives all events and validates them before broadcasting to multiple configured channels, implementing an extensible multi-channel event dispatch pattern.
|
|
63
|
-
|
|
64
|
-
- **Performance Tracking:** The `DailySyncPerformanceTrackerService` provides fine-grained timing of sync operations per team and global durations, enabling performance monitoring and alerting.
|
|
65
|
-
|
|
66
|
-
- **Third-party Integrations:** The system integrates with Segment for advanced event analytics and Hubspot for CRM/marketing tracking, encapsulated in dedicated services and channels.
|
|
67
|
-
|
|
68
|
-
- **System Sync and Sales Metrics Sync:** Administrative APIs allow triggering of sync operations across teams and various granularities (daily, weekly, full syncs), tracked and logged through the performance tracker.
|
|
69
|
-
|
|
70
|
-
### 4. Code Structure
|
|
71
|
-
|
|
72
|
-
- **Frontend Tracking**
|
|
73
|
-
- `apps/web/src/components/tracking/GoogleAnalyticsUserTracker.tsx` - Sends authenticated user_id to Google Analytics.
|
|
74
|
-
- `apps/web/src/pages/_app.tsx` - Includes `GoogleAnalyticsUserTracker` and configures GoogleAnalytics SDK with the measurement ID. Also sends Web Vitals metrics as GA events and reports them to Sentry.
|
|
75
|
-
- `apps/web/src/components/tracking/index.ts` - Exports tracking components.
|
|
76
|
-
|
|
77
|
-
- **Backend Tracking**
|
|
78
|
-
- `apps/api/src/tracking/services/tracking.service.ts` - Main service for validating and broadcasting tracking events.
|
|
79
|
-
- `apps/api/src/tracking/services/segment.service.ts` - Implements Segment integration for event tracking and user identification.
|
|
80
|
-
- `apps/api/src/tracking/tracking.module.ts` - NestJS module declaration wiring tracking components.
|
|
81
|
-
|
|
82
|
-
- **Sync and Performance Tracking**
|
|
83
|
-
- `apps/api/src/pim/services/insights-sync.service.ts` - Manages syncing inventory insights and sales data.
|
|
84
|
-
- `apps/api/src/pim/services/daily-sync-performance-tracker.service.ts` - Tracks performance of sync steps with start/stop duration tracking.
|
|
85
|
-
- `apps/api/src/admin/controllers/sync.controller.ts` - Exposes admin API endpoints to trigger syncs and updates, using the performance tracker.
|
|
86
|
-
|
|
87
|
-
### Example code snippet from `GoogleAnalyticsUserTracker.tsx`:
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
import { sendGAEvent } from "@next/third-parties/google";
|
|
91
|
-
import { useEffect } from "react";
|
|
92
|
-
import { useAuthContext } from "~/auth";
|
|
93
|
-
import env from "~/env";
|
|
94
|
-
|
|
95
|
-
export const GoogleAnalyticsUserTracker = () => {
|
|
96
|
-
const auth = useAuthContext();
|
|
97
|
-
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
if (env.NEXT_PUBLIC_GA_MEASUREMENT_ID) {
|
|
100
|
-
sendGAEvent("set", { user_id: auth?.user?.id ?? null });
|
|
101
|
-
}
|
|
102
|
-
}, [auth]);
|
|
103
|
-
|
|
104
|
-
return null;
|
|
105
|
-
};
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Example backend tracking method from `TrackingService`:
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
async trackEvent(event: EventType, context?: Partial<EventDTO["context"]>): Promise<void> {
|
|
112
|
-
try {
|
|
113
|
-
const user = context?.user ?? this.contextService.getUser();
|
|
114
|
-
|
|
115
|
-
const eventDto = new EventDTO(event, {
|
|
116
|
-
...context,
|
|
117
|
-
user: user ?? undefined,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if ((await validate(eventDto)).length > 0) {
|
|
121
|
-
throw new GenieException("Invalid event given", { event });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
this.channels.forEach((channel) => {
|
|
125
|
-
channel.broadcastEvent(eventDto);
|
|
126
|
-
});
|
|
127
|
-
} catch (error) {
|
|
128
|
-
captureException({ error, logger: this.logger });
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### 5. API and Interfaces
|
|
134
|
-
|
|
135
|
-
- **`TrackingService.trackEvent(event: EventType, context?: Partial<EventDTO["context"]>)`**
|
|
136
|
-
- Validates and broadcasts an event to all configured tracking channels.
|
|
137
|
-
- Uses the current user context if no user specified.
|
|
138
|
-
- Catches and reports exceptions internally.
|
|
139
|
-
|
|
140
|
-
- **SegmentService.sendIdentity(user)**
|
|
141
|
-
- Sends user identity information to Segment via the `identify` endpoint.
|
|
142
|
-
|
|
143
|
-
- **SyncController API Endpoints:**
|
|
144
|
-
- `/admin/sync-inventory-insights-for-all-teams` - Triggers full sync for all teams.
|
|
145
|
-
- `/admin/sync-inventory-insights-for-team` - Triggers sync for a specified team.
|
|
146
|
-
- Additional endpoints handle daily syncs, sales metric updates, and sales health checks.
|
|
147
|
-
|
|
148
|
-
### 6. Environment & Configuration
|
|
149
|
-
|
|
150
|
-
- **Environment Variables:**
|
|
151
|
-
- `NEXT_PUBLIC_GA_MEASUREMENT_ID`: Google Analytics Measurement ID for frontend tracking.
|
|
152
|
-
- `SEGMENT_WRITE_KEY`: Segment write key for backend event integration.
|
|
153
|
-
- Slack and other services have tokens configured in their respective env vars (e.g., Slack tokens).
|
|
154
|
-
|
|
155
|
-
These variables enable or disable integrations conditionally.
|
|
156
|
-
|
|
157
|
-
### 7. Testing, Monitoring, and Deployment
|
|
158
|
-
|
|
159
|
-
- **Testing**: While explicit tests are not detailed here, the module follows strict DTO validation (`class-validator`) ensuring data correctness before dispatch.
|
|
160
|
-
|
|
161
|
-
- **Monitoring and Error Reporting:**
|
|
162
|
-
- Errors in tracking are captured and reported via `captureException` to Sentry.
|
|
163
|
-
- Sync performance metrics are logged, aggregated, and emitted as Slack notifications via other integrated services (not detailed here).
|
|
164
|
-
|
|
165
|
-
- **Deployment**: The tracking features are integrated into the app lifecycle (`_app.tsx` for frontend) and exposed APIs for triggering sync jobs are available in the Admin API.
|
|
166
|
-
|
|
167
|
-
### 8. Troubleshooting & Known Issues
|
|
168
|
-
|
|
169
|
-
- The tracking system safely handles missing or invalid events through validation and exception capture, ensuring that failures in third-party services do not interrupt the main application flow.
|
|
170
|
-
|
|
171
|
-
- The frontend user tracking sends null user_id if unauthenticated, avoiding incorrect user attribution.
|
|
172
|
-
|
|
173
|
-
- Sync operations track durations carefully, and partial failures per team are logged and separated for analysis.
|
|
174
|
-
|
|
175
|
-
### References
|
|
176
|
-
|
|
177
|
-
- [GoogleAnalyticsUserTracker.tsx](apps/web/src/components/tracking/GoogleAnalyticsUserTracker.tsx)
|
|
178
|
-
- [TrackingService](apps/api/src/tracking/services/tracking.service.ts)
|
|
179
|
-
- [SegmentService](apps/api/src/tracking/services/segment.service.ts)
|
|
180
|
-
- [SyncController](apps/api/src/admin/controllers/sync.controller.ts)
|
|
181
|
-
- [DailySyncPerformanceTrackerService](apps/api/src/pim/services/daily-sync-performance-tracker.service.ts)
|
|
182
|
-
- [_app.tsx](apps/web/src/pages/_app.tsx)
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Shopify Connection & Setup'
|
|
3
|
-
description: 'How to set up and configure Shopify connections including manual and automated sync options.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Shopify Connection & Setup Service
|
|
7
|
-
|
|
8
|
-
## 1. Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The **ShopifyConnectService** is responsible for managing the lifecycle of Shopify store connections within the Genie platform. This includes initiating both automatic and manual OAuth connection flows, handling callbacks from Shopify, and setting up associated data structures such as teams, stores, users, and onboarding state.
|
|
11
|
-
|
|
12
|
-
This service acts as a key integration point between the Genie backend and Shopify's OAuth and API endpoints. It is essential for enabling Genie users to link their Shopify stores, provision required data entities, and track onboarding progress.
|
|
13
|
-
|
|
14
|
-
### Architectural Context
|
|
15
|
-
|
|
16
|
-
- Operates within the Genie API backend under the `setup` module.
|
|
17
|
-
- Collaborates closely with the `ShopifyApiService`, `ShopifyStoreService`, `UserManagement` services (Teams and User repositories), and onboarding and reporting subsystems.
|
|
18
|
-
- Controls multi-step connection flows with both automated and manual connection support.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
## 2. Technical Overview
|
|
22
|
-
|
|
23
|
-
### High-Level Flow
|
|
24
|
-
|
|
25
|
-
```mermaid
|
|
26
|
-
flowchart TD
|
|
27
|
-
subgraph Frontend
|
|
28
|
-
UI[Shopify Connect UI]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
subgraph Genie_Backend["Genie Backend"]
|
|
32
|
-
SCS["ShopifyConnectService"]
|
|
33
|
-
SAS["ShopifyApiService"]
|
|
34
|
-
SSS["ShopifyStoreService"]
|
|
35
|
-
TS["TeamsService"]
|
|
36
|
-
OR["OnboardingService & ReportsService"]
|
|
37
|
-
JWT["JWT Service"]
|
|
38
|
-
RepoUser["User Repository"]
|
|
39
|
-
RepoTeam["Team Repository"]
|
|
40
|
-
ReqRepo["ShopifyConnectRequest Repository"]
|
|
41
|
-
Tracking["TrackingService"]
|
|
42
|
-
SavedView["SavedViewService"]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
UI -->|Begin Connection| SCS
|
|
46
|
-
SCS -->|Begin OAuth| SAS
|
|
47
|
-
SAS -->|OAuth Redirect| UI
|
|
48
|
-
UI -->|OAuth Callback| SCS
|
|
49
|
-
SCS -->|Get/Setup Store & Team| SSS
|
|
50
|
-
SSS -->|Persist Team & Store| RepoTeam
|
|
51
|
-
SCS -->|Setup Admin & Business| TS
|
|
52
|
-
SCS -->|Initialize Onboarding & Reports| OR
|
|
53
|
-
SCS -->|Generate Token| JWT
|
|
54
|
-
SCS -->|Track Events| Tracking
|
|
55
|
-
SCS -->|Create Default Templates| SavedView
|
|
56
|
-
SCS -->|Update User Role & Details| RepoUser
|
|
57
|
-
ReqRepo -->|Handle Manual Requests| SCS
|
|
58
|
-
|
|
59
|
-
click SCS "apps/api/src/setup/services/shopify-connect.service.ts"
|
|
60
|
-
click SAS "apps/api/src/shopify/services/shopify-api.service.ts"
|
|
61
|
-
click SSS "apps/api/src/shopify/services/shopify-store.service.ts"
|
|
62
|
-
click TS "apps/api/src/user-management/services/teams.service.ts"
|
|
63
|
-
click OR "apps/api/src/setup/services/onboarding.service.ts"
|
|
64
|
-
click RepoUser "apps/api/src/user-management/entities/user.entity.ts"
|
|
65
|
-
click RepoTeam "apps/api/src/user-management/entities/team.entity.ts"
|
|
66
|
-
click ReqRepo "apps/api/src/setup/entities/shopify-connect-request.entity.ts"
|
|
67
|
-
click Tracking "apps/api/src/tracking/services/tracking.service.ts"
|
|
68
|
-
click SavedView "apps/api/src/pim/services/saved-view.service.ts"
|
|
69
|
-
|
|
70
|
-
classDef service fill:#f9f,stroke:#333,stroke-width:1px
|
|
71
|
-
class SCS,SAS,SSS,TS,OR,Tracking,SavedView service
|
|
72
|
-
|
|
73
|
-
classDef repository fill:#bbf,stroke:#333,stroke-width:1px
|
|
74
|
-
class RepoUser,RepoTeam,ReqRepo repository
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Key Technologies & Patterns
|
|
78
|
-
|
|
79
|
-
- **NestJS Framework:** The service is an injectable singleton leveraging NestJS's dependency injection.
|
|
80
|
-
- **TypeORM:** For database interactions managing entities like User, Team, Shopify stores, and manual connection requests.
|
|
81
|
-
- **JWT:** Used to sign session tokens post successful Shopify connect.
|
|
82
|
-
- **Shopify API Library:** Wraps Shopify OAuth and API interactions.
|
|
83
|
-
- **Event Tracking:** Tracks onboarding progress events.
|
|
84
|
-
- **Transactional Operations:** Ensures atomic creation/updating of Shopify Store and Team entities.
|
|
85
|
-
- **Manual vs Automatic Connection Flows:** Supports two modes of connection to cater to different UX models.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
## 3. Core Concepts and Responsibilities
|
|
89
|
-
|
|
90
|
-
### Connection Types
|
|
91
|
-
|
|
92
|
-
Defined in shared types (`ShopifyConnectionType`):
|
|
93
|
-
- `Setup`: Full setup connection with admin/business details capturing.
|
|
94
|
-
- `GrantPermissions`: Connection flow specifically for approving additional Shopify permissions (e.g., after new features rollout).
|
|
95
|
-
|
|
96
|
-
### Main Responsibilities
|
|
97
|
-
|
|
98
|
-
- **beginConnecting:** Starts the automatic OAuth flow for a Shopify domain.
|
|
99
|
-
- **beginManualConnection:** Starts OAuth flow based on a saved manual connection request.
|
|
100
|
-
- **finishConnecting:** Handles Shopify OAuth callback, establishes Shopify store and Genie team, assigns roles, initiates onboarding.
|
|
101
|
-
- **saveManualConnectionRequest:** Persists manual connection request data for later usage.
|
|
102
|
-
- **assignAdminAndBusinessDetailsToTeam:** Assigns the connecting user as team admin and updates team business name.
|
|
103
|
-
- **createDefaultTemplatesIfNeeded:** Adds default saved views/templates for new teams as part of setup.
|
|
104
|
-
|
|
105
|
-
### Ownership
|
|
106
|
-
|
|
107
|
-
- Maintained by the backend team responsible for Shopify integration.
|
|
108
|
-
- Logs and tracks exceptions via GenieException handling and Sentry integration.
|
|
109
|
-
|
|
110
|
-
### Non-Functional Requirements
|
|
111
|
-
|
|
112
|
-
- **Reliability:** Uses transactions to guarantee consistent creation of team and store.
|
|
113
|
-
- **Security:** Ensures proper JWT token generation and validates Shopify domains.
|
|
114
|
-
- **Scalability:** Supports multiple connection requests and re-authorization workflows.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
## 4. Code Structure
|
|
118
|
-
|
|
119
|
-
### Major Files
|
|
120
|
-
|
|
121
|
-
- `shopify-connect.service.ts`: Core service implementing connection logic.
|
|
122
|
-
- `shopify-store.service.ts`: Supports store domain sanitization and transactional setup.
|
|
123
|
-
- `shopify-connect.controller.ts`: Exposes REST endpoints for front-end interaction with OAuth flows.
|
|
124
|
-
|
|
125
|
-
### Key Methods Overview
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
// Starts automatic OAuth flow
|
|
129
|
-
beginConnecting({ shopDomain, callbackPath, req, res })
|
|
130
|
-
|
|
131
|
-
// Starts manual OAuth flow using saved request ID
|
|
132
|
-
async beginManualConnection({ connectionRequestId, callbackPath, req, res })
|
|
133
|
-
|
|
134
|
-
// Handles OAuth callback, sets up team/store, onboarding, and returns token
|
|
135
|
-
async finishConnecting({ req, res, manualConnectionRequestId? })
|
|
136
|
-
|
|
137
|
-
// Saves manual connection request from UI input
|
|
138
|
-
async saveManualConnectionRequest(userId, data: ManualConnectShopifyRequestDto)
|
|
139
|
-
|
|
140
|
-
// Assigns admin role and business details to team
|
|
141
|
-
private async assignAdminAndBusinessDetailsToTeam({ teamId, conenctRequest })
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Example: Initiating OAuth Flow (Automatic)
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
beginConnecting({ shopDomain, callbackPath, req, res }) {
|
|
148
|
-
this.trackingService.trackEvent({
|
|
149
|
-
name: EVENTS.Onboarding,
|
|
150
|
-
properties: {
|
|
151
|
-
onboarding_progress: "Not Started",
|
|
152
|
-
onboarding_connection_type: "Automatic",
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
return this.shopifyApiService.getAuthApi().begin({
|
|
157
|
-
shop: this.shopifyStoreService.sanitizeShopDomainOrThrow(shopDomain),
|
|
158
|
-
callbackPath,
|
|
159
|
-
isOnline: false,
|
|
160
|
-
rawRequest: req,
|
|
161
|
-
rawResponse: res,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
## 5. API and Interfaces
|
|
168
|
-
|
|
169
|
-
The service itself is consumed primarily by the NestJS controller `ShopifyConnectController` which exposes the following endpoints:
|
|
170
|
-
|
|
171
|
-
| Endpoint | HTTP Method | Description |
|
|
172
|
-
|-------------------------------|-------------|------------------------------------------------|
|
|
173
|
-
| `/shopify/connect/begin` | GET | Begins automatic OAuth flow with shop domain |
|
|
174
|
-
| `/shopify/connect/manual` | POST | Saves manual connect request and returns ID |
|
|
175
|
-
| `/shopify/connect/manual/begin`| GET | Begins manual OAuth flow using request ID |
|
|
176
|
-
| `/shopify/connect/callback` | GET | Handles OAuth callback and finalizes connection|
|
|
177
|
-
|
|
178
|
-
### ManualConnectShopifyRequestDto
|
|
179
|
-
|
|
180
|
-
Defines input for manual connect:
|
|
181
|
-
- `shopifyUrl`: Shopify domain/url string.
|
|
182
|
-
- `type`: Connection type (`SETUP` or `GRANT_PERMISSIONS`).
|
|
183
|
-
- For `SETUP` type, additional fields: `firstName`, `surname`, `businessName`.
|
|
184
|
-
|
|
185
|
-
### Expected Returns
|
|
186
|
-
|
|
187
|
-
- `finishConnecting` returns an install session token (JWT) unless it was a manual connection flow.
|
|
188
|
-
|
|
189
|
-
### Error Handling
|
|
190
|
-
|
|
191
|
-
- Invalid Shopify URL detected during manual connect throws `GenieException` with code `ErrorCode.InvalidShopifyUrl`.
|
|
192
|
-
- Controller maps this to 400 BadRequest with error code `ApiErrorCode.InvalidShopifyUrl`.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
## 6. Environment & Configuration
|
|
196
|
-
|
|
197
|
-
This service relies on core platform config for:
|
|
198
|
-
- `APP_URL`: Used for forming callback and redirect URLs.
|
|
199
|
-
- Shopify API credentials and tokens are managed through `ShopifyApiService`.
|
|
200
|
-
- Cookie setup for manual connect request tracking (30 minutes expiration).
|
|
201
|
-
|
|
202
|
-
No additional explicit environment variables or secrets are defined directly in this service.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
## 7. Testing, Monitoring, and Deployment
|
|
206
|
-
|
|
207
|
-
No explicit test information is included in the provided context.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
## 8. Troubleshooting & Known Issues
|
|
211
|
-
|
|
212
|
-
- Manual connection requests must be valid with correct Shopify URLs; invalid URLs raise errors.
|
|
213
|
-
- The service tracks and logs exceptions via `GenieException` and `captureException`.
|
|
214
|
-
- Manual connection requests are persisted to prevent unauthorized or invalid OAuth flow starts.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
## 9. References
|
|
218
|
-
|
|
219
|
-
- See the service code: [apps/api/src/setup/services/shopify-connect.service.ts](apps/api/src/setup/services/shopify-connect.service.ts)
|
|
220
|
-
- Controller usage: [apps/api/src/setup/controllers/shopify-connect.controller.ts](apps/api/src/setup/controllers/shopify-connect.controller.ts)
|
|
221
|
-
- Store setup logic: [apps/api/src/shopify/services/shopify-store.service.ts](apps/api/src/shopify/services/shopify-store.service.ts)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
---
|
|
225
|
-
|
|
226
|
-
This documentation covers the internal workings and integration points of the Shopify connection and setup service within Genie. It is crucial for maintaining and extending Shopify integration capabilities.
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Shopify Webhooks'
|
|
3
|
-
description: 'Webhooks handling for inventory, compliance, and shopify events and how the system processes these.'
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
## Shopify Webhooks
|
|
7
|
-
|
|
8
|
-
### Purpose and Scope
|
|
9
|
-
|
|
10
|
-
The **Shopify Webhooks** integration in the Genie app is responsible for subscribing to, receiving, storing, and processing webhook events generated by Shopify stores connected to the platform. This component enables the system to stay synchronized with store data changes such as Products, Locations, Inventory Levels, Collections, Orders, and Shop metadata updates.
|
|
11
|
-
|
|
12
|
-
It bridges Shopify's asynchronous event system with Genie’s internal data models, ensuring real-time or near-real-time reflections of Shopify changes in Genie’s system. The Shopify Webhooks service owns the lifecycle of webhook registration per team (client) and manages persistent storage and processing of incoming webhook events.
|
|
13
|
-
|
|
14
|
-
**System boundaries:**
|
|
15
|
-
- Receives webhook HTTP callbacks from Shopify (via a public API endpoint).
|
|
16
|
-
- Stores raw and processed events in a dedicated Postgres table.
|
|
17
|
-
- Processes and orchestrates updates to Genie internal entities like Product, Variant, Location, Collection, Sales Order, and Settings.
|
|
18
|
-
- Registers and unregisters subscriptions for Shopify webhooks via Shopify's API.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### Technical Overview
|
|
22
|
-
|
|
23
|
-
This component fits within the Genie integration layer for Shopify:
|
|
24
|
-
- The **WebhooksController** exposes a public HTTP POST endpoint `/shopify/webhooks` to receive Shopify webhook payloads, secured by `ShopifyWebhooksGuard` verification.
|
|
25
|
-
- The **ShopifyWebhooksService** handles storage, registration, deregistration, and fetching logic for webhooks with Shopify.
|
|
26
|
-
- The **ShopifyWebhooksConsumer** asynchronously processes webhook events from a Redis-backed queue (BullMQ), delegating business logic to the **WebhooksInsightsSyncService**.
|
|
27
|
-
- Sync service manages domain-specific sync flows: Products, Variants, Locations, Inventory, Collections, Orders, Shop settings.
|
|
28
|
-
|
|
29
|
-
[Mermaid architecture diagram omitted here; see separate Mermaid.js output]
|
|
30
|
-
|
|
31
|
-
This component depends on:
|
|
32
|
-
- ShopifyApiService: For authenticated Shopify API calls.
|
|
33
|
-
- TeamsService: To manage active/inactive team states and billing plan checks.
|
|
34
|
-
- InsightsSyncService: For importing and syncing Shopify data.
|
|
35
|
-
- TypeORM repositories for persistence.
|
|
36
|
-
- BullMQ queue for asynchronous event handling.
|
|
37
|
-
|
|
38
|
-
Key technologies:
|
|
39
|
-
- NestJS for service and controller abstractions.
|
|
40
|
-
- TypeORM for database entity management.
|
|
41
|
-
- BullMQ for queued, concurrent processing.
|
|
42
|
-
- Zod for schema validation of webhook payloads.
|
|
43
|
-
- Shopify SDK (`@shopify/shopify-api`) for API and webhook registrations.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### Core Concepts and Responsibilities
|
|
47
|
-
|
|
48
|
-
- **Webhook Event:** Represents a single Shopify event with payload, topic, timestamps, and status.
|
|
49
|
-
- **Team:** Represents a customer or client; webhooks are registered per team.
|
|
50
|
-
- **Webhook Topics:** Shopify event types such as ProductsCreate, LocationsUpdate, InventoryLevelsUpdate, OrdersCreate, ShopUpdate, etc.
|
|
51
|
-
- **Event Status:** Tracks processing states - PENDING, PROCESSED, SKIPPED, FAILED.
|
|
52
|
-
|
|
53
|
-
Responsibility boundaries:
|
|
54
|
-
- Register/unregister webhooks dynamically based on active team status and plan type.
|
|
55
|
-
- Store raw webhook events reliably with input sanitization.
|
|
56
|
-
- Process webhooks in order, skipping obsolete or duplicate events.
|
|
57
|
-
- Mark events as processed or failed to manage retry logic.
|
|
58
|
-
- Coordinate syncing of Shopify entities to Genie internal tables.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### Code Structure
|
|
62
|
-
|
|
63
|
-
| File/Folder | Description |
|
|
64
|
-
|-------------|-------------|
|
|
65
|
-
| [apps/api/src/shopify/controllers/webhooks.controller.ts](apps/api/src/shopify/controllers/webhooks.controller.ts) | REST controller endpoint receiving raw webhook POST requests from Shopify and forwarding to service. |
|
|
66
|
-
| [apps/api/src/shopify/services/shopify-webhooks.service.ts](apps/api/src/shopify/services/shopify-webhooks.service.ts) | Core service for Shopify webhook registering, unregistering, event persistence, and queueing processing tasks. |
|
|
67
|
-
| [apps/api/src/pim/services/webhooks-insights-sync.service.ts](apps/api/src/pim/services/webhooks-insights-sync.service.ts) | Business logic service to interpret and sync webhook events to internal domain (products, orders, collections, etc). |
|
|
68
|
-
| [apps/api/src/shopify/shopify-webhook-event.ts](apps/api/src/shopify/shopify-webhook-event.ts) | Class representing a typed and validated Shopify webhook event instance with status setters. |
|
|
69
|
-
| [apps/api/src/shopify/schemas.ts](apps/api/src/shopify/schemas.ts) | Zod schemas for validating the structure of Shopify webhook payloads by topic.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
#### Example: Receiving and Storing a Webhook Event
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
// In WebhooksController
|
|
76
|
-
@Post('webhooks')
|
|
77
|
-
async processShopifyEventForSync(
|
|
78
|
-
@Request() { webhookContext },
|
|
79
|
-
@Body() body: any
|
|
80
|
-
) {
|
|
81
|
-
await this.shopifyWebhooksService.storeEvent(webhookContext, body);
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
// In ShopifyWebhooksService
|
|
87
|
-
async storeEvent(context, body) {
|
|
88
|
-
// Sanitize and validate payload
|
|
89
|
-
// Resolve team by store domain
|
|
90
|
-
// Insert event record with PENDING status
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
### API and Interfaces
|
|
96
|
-
|
|
97
|
-
- **Webhook Reception Endpoint:** `/shopify/webhooks` (POST)
|
|
98
|
-
- Protected by `ShopifyWebhooksGuard` to verify Shopify request authenticity.
|
|
99
|
-
- Accepts any webhook event payload, mapped to the internal team by domain.
|
|
100
|
-
|
|
101
|
-
- **ShopifyWebhooksService** key methods:
|
|
102
|
-
- `storeEvent(context, body)`: Persist a webhook event.
|
|
103
|
-
- `registerWebhooksForTeam(teamId, topics)`: Registers webhook subscriptions on Shopify for specified topics.
|
|
104
|
-
- `unregisterWebhooksForTeam(teamId)`: Deletes existing webhook subscriptions from Shopify for a team.
|
|
105
|
-
- `markEventsAsProcessed(ids)`, `markEventsAsFailed(ids)`: Update statuses in DB.
|
|
106
|
-
- `getEventsByTopics(events, topics)`: Filter events by topic.
|
|
107
|
-
|
|
108
|
-
- **Event Status Workflow:**
|
|
109
|
-
- NEW events start with status `PENDING`.
|
|
110
|
-
- Successfully processed events are marked as `PROCESSED`.
|
|
111
|
-
- Duplicate or obsolete older events are marked as `SKIPPED`.
|
|
112
|
-
- Errors mark events as `FAILED` for retry.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
### Environment & Configuration
|
|
116
|
-
|
|
117
|
-
- **Configuartion keys used:**
|
|
118
|
-
- `API_URL`: Base URL for webhook callback URL registration.
|
|
119
|
-
- `SHOPIFY_APP_CLIENT_ID` and `SHOPIFY_APP_CLIENT_SECRET`: Shopify app credentials.
|
|
120
|
-
- Relevant env/config management handled globally.
|
|
121
|
-
|
|
122
|
-
- Webhook callback endpoint hardcoded as `/shopify/webhooks` relative to `API_URL`.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
### Testing, Monitoring, and Deployment
|
|
126
|
-
|
|
127
|
-
- Webhook events are queued on receipt and processed asynchronously for scalability.
|
|
128
|
-
- Processing errors are captured and logged via Sentry integration.
|
|
129
|
-
- Batch processing and retry logic ensure robustness.
|
|
130
|
-
- Logging throughout the WebhooksService and InsightsSyncService supports operational debugging.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### Troubleshooting & Known Issues
|
|
134
|
-
|
|
135
|
-
- Webhook registration failures for a team are logged with detailed error messages.
|
|
136
|
-
- The system includes automatic retry for failed webhook registrations.
|
|
137
|
-
- Event processing failures are marked `FAILED` and retried later.
|
|
138
|
-
- Duplicate or older webhook events are identified and skipped.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
## Mermaid Diagram: Shopify Webhooks Architecture
|
|
144
|
-
|
|
145
|
-
```mermaid
|
|
146
|
-
flowchart TD
|
|
147
|
-
subgraph "Shopify System"
|
|
148
|
-
ShopifyWebhookAPI["Shopify Webhook API"]:::external
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
subgraph "Genie API Backend"
|
|
152
|
-
direction TB
|
|
153
|
-
WebhooksController["WebhooksController /shopify/webhooks"]:::controller
|
|
154
|
-
ShopifyWebhooksService["ShopifyWebhooksService"]:::service
|
|
155
|
-
ShopifyWebhooksQueue["BullMQ Queue"]:::queue
|
|
156
|
-
ShopifyWebhooksConsumer["ShopifyWebhooksConsumer"]:::worker
|
|
157
|
-
WebhooksInsightsSyncService["WebhooksInsightsSyncService"]:::service
|
|
158
|
-
ProductRepo["Product Repository":::db]
|
|
159
|
-
VariantRepo["ProductVariant Repository":::db]
|
|
160
|
-
LocationRepo["Location Repository":::db]
|
|
161
|
-
CollectionRepo["Collection Repository":::db]
|
|
162
|
-
SalesOrderRepo["SalesOrder Repository":::db]
|
|
163
|
-
SalesOrderItemRepo["SalesOrderItem Repository":::db]
|
|
164
|
-
SettingsService["SettingsService"]:::service
|
|
165
|
-
TeamsService["TeamsService"]:::service
|
|
166
|
-
ShopifyApiService["ShopifyApiService"]:::service
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
ShopifyWebhookAPI -->|"HTTP Post Webhook Calls"| WebhooksController
|
|
170
|
-
WebhooksController -->|"storeEvent()"| ShopifyWebhooksService
|
|
171
|
-
ShopifyWebhooksService -->|"Insert Event DB"| DB["ShopifyWebhookEventEntity Table"]:::db
|
|
172
|
-
ShopifyWebhooksService -->|"Add jobs to Queue"| ShopifyWebhooksQueue
|
|
173
|
-
ShopifyWebhooksConsumer -->|"Fetch Event"| DB
|
|
174
|
-
ShopifyWebhooksConsumer -->|"Process Event"| WebhooksInsightsSyncService
|
|
175
|
-
|
|
176
|
-
WebhooksInsightsSyncService --> ProductRepo
|
|
177
|
-
WebhooksInsightsSyncService --> VariantRepo
|
|
178
|
-
WebhooksInsightsSyncService --> LocationRepo
|
|
179
|
-
WebhooksInsightsSyncService --> CollectionRepo
|
|
180
|
-
WebhooksInsightsSyncService --> SalesOrderRepo
|
|
181
|
-
WebhooksInsightsSyncService --> SalesOrderItemRepo
|
|
182
|
-
WebhooksInsightsSyncService --> SettingsService
|
|
183
|
-
|
|
184
|
-
ShopifyWebhooksService --> ShopifyApiService
|
|
185
|
-
ShopifyWebhooksService --> TeamsService
|
|
186
|
-
|
|
187
|
-
classDef external fill:#D6EAF8,stroke:#2E86C1,color:#154360,font-weight:bold;
|
|
188
|
-
classDef controller fill:#D5F5E3,stroke:#27AE60,color:#145A32,font-weight:bold;
|
|
189
|
-
classDef service fill:#FCF3CF,stroke:#F1C40F,color:#7D6608,font-weight:bold;
|
|
190
|
-
classDef queue fill:#FADBD8,stroke:#E74C3C,color:#78281F,font-weight:bold;
|
|
191
|
-
classDef worker fill:#F5EEF8,stroke:#8E44AD,color:#4A235A,font-weight:bold;
|
|
192
|
-
classDef db fill:#D4E6F1,stroke:#2980B9,color:#1B4F72,font-weight:bold;
|
|
193
|
-
|
|
194
|
-
click WebhooksController "apps/api/src/shopify/controllers/webhooks.controller.ts"
|
|
195
|
-
click ShopifyWebhooksService "apps/api/src/shopify/services/shopify-webhooks.service.ts"
|
|
196
|
-
click ShopifyWebhooksConsumer "apps/api/src/shopify/services/shopify-webhooks.consumer.ts"
|
|
197
|
-
click WebhooksInsightsSyncService "apps/api/src/pim/services/webhooks-insights-sync.service.ts"
|
|
198
|
-
click ProductRepo "apps/api/src/pim/entities/product.entity.ts"
|
|
199
|
-
click VariantRepo "apps/api/src/pim/entities/product-variant.entity.ts"
|
|
200
|
-
click LocationRepo "apps/api/src/pim/entities/location.entity.ts"
|
|
201
|
-
click CollectionRepo "apps/api/src/pim/entities/collection.entity.ts"
|
|
202
|
-
click SalesOrderRepo "apps/api/src/sales-order/entities/sales-order.entity.ts"
|
|
203
|
-
click SalesOrderItemRepo "apps/api/src/sales-order/entities/sales-order-item.entity.ts"
|
|
204
|
-
click SettingsService "apps/api/src/user-management/services/settings.service.ts"
|
|
205
|
-
click TeamsService "apps/api/src/user-management/services/teams.service.ts"
|
|
206
|
-
click ShopifyApiService "apps/api/src/shopify/services/shopify-api.service.ts"
|
|
207
|
-
```
|