-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatadump.txt
More file actions
226 lines (196 loc) · 10 KB
/
Copy pathdatadump.txt
File metadata and controls
226 lines (196 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
================================================================================
DATA DUMP METHOD — SupleCost Product Import Pipeline
================================================================================
Date: 2026-06-30
Product: MuscleBlaze Biozyme Iso-Zero (Low Carb Ice Cream Chocolate, 500g)
Source: https://www.muscleblaze.com/sv/muscleblaze-biozyme-iso-zero/SP-45405
Target: Supabase (czdvxcuuylfgdltttnnt.supabase.co)
Website: https://varunsonline.com
================================================================================
OVERVIEW
--------
Extract product data from a product page using the built-in browser, then
insert/upsert all 50 fields directly into Supabase via the service role key.
NOTE: cost_per_serving is AUTO-CALCULATED as: best_price / total_servings
This happens at 3 layers: DB trigger, API reshape, and import script.
See: scripts/migration-cost-per-serving.sql
================================================================================
TOOLS USED
================================================================================
1. openwork-browser_navigate_page — Navigate to product URL
2. openwork-browser_take_snapshot — Read visible text (a11y tree)
3. openwork-browser_evaluate_script — Execute JS in page context
4. openwork-browser_click — Click tabs to reveal hidden content
5. write — Create the import script
6. bash (npx tsx) — Run the import script
================================================================================
STEP-BY-STEP PROCESS
================================================================================
STEP 1: NAVIGATE
-----------------
Open the product page in the built-in browser.
STEP 2: EXTRACT PAGE TEXT
--------------------------
Take an a11y snapshot and extract visible text (product name, price, flavor,
description, rating, etc.).
STEP 3: EXTRACT STRUCTURED DATA (JavaScript)
----------------------------------------------
Inject JavaScript via evaluate_script to extract:
a) window.__NEXT_DATA__ — Next.js serialized JSON containing:
- Product name, brand, category, pricing (MRP, offer price, discount)
- All image URLs with multiple resolutions
- Variant/attribute details (flavors, weights, SKU IDs)
- Manufacturer details, country of origin, FSSAI code
- UPC/EAN codes (pv_upc, pr_Upc)
- Ratings, review counts
- Goals/concerns
- Food type (vegetarian/vegan)
- Shelf life
- Vendor information
- Available variants with per-variant pricing
b) document.querySelectorAll() — DOM traversal for:
- <meta> tags (OG description, meta description)
- Tab content sections (Description, Key Benefits, Nutritional Info)
c) Tab interaction — Click on each tab section (Key Benefits, Nutritional
Information) to reveal hidden content and capture it via snapshot.
STEP 4: MAP TO 50-FIELD SCHEMA
--------------------------------
Map extracted data to database columns:
# Field DB Column Table
-- ----------------------- ------------------- ----------------
1 Name name products
2 Brand brand_id products (FK→brands)
3 Category category_id products (FK→categories)
4 Slug slug products
5 Description description products
6 Short Description short_description products
7 Image URLs images[] products
8 Availability is_active products
9 Net Weight net_weight products
10 Serving Size serving_size products
11 Total Servings total_servings products
12 Cost Per Serving cost_per_serving products
13 Protein Per Serving protein_per_serving products
14 Creatine Per Serving creatine_per_serving products
15 Carbs Per Serving carbs_per_serving products
16 Fats Per Serving fats_per_serving products
17 Calories Per Serving calories_per_serving products
18 Flavor flavor[] products
19 Key Ingredients key_ingredients[] products
20 Benefits benefits[] products
21 Full Ingredients List full_ingredients_list products
22 Structured Ingredients ingredients (JSONB) products
23 Nutrition Facts nutrition (JSONB) products
24 Usage Instructions usage_instructions products
25 Warnings warnings products
26 Best Time To Use best_time_to_use products
27 Manufacturing Standard manufacturing_standard products
28 Country Of Origin country_of_origin products
29 UPC / EAN upc_ean products
30 Goals goals[] products
31 Certifications certifications[] products
32 Is Vegetarian is_vegetarian products
33 Is Vegan is_vegan products
34 Lab Tested lab_tested products
35 Lab Test Details lab_test_details products
36 Brand Logo URL (via brands.logo_url) brands
37 Value Score value_score products
38 Meta Title meta_title products
39 Meta Description meta_description products
40 Best Price best_price products (denormalized)
41 Original Price original_price products (denormalized)
42 Discount Percentage discount_percentage products (denormalized)
43 Retailer ID retailer_id product_prices
44 Retailer Current Price current_price product_prices
45 Retailer Original Price original_price product_prices
46 Retailer Discount % discount_percentage product_prices
47 In Stock in_stock product_prices
48 Buy URL url product_prices
49 Is Main Link is_main_link product_prices
50 Extended Nutrition (stored in nutrition products
JSONB or as image URL)
STEP 5: WRITE IMPORT SCRIPT
----------------------------
Create a TypeScript file (scripts/import-<product-slug>.ts) that:
1. Loads environment variables via dotenv
2. Connects to Supabase using the service role key (supabaseAdmin)
3. Ensures related records exist (brand, category, retailer)
4. Upserts the product row
5. Inserts product price per retailer
6. Creates affiliate link record
7. Links filter options (goals → product_filter_values)
STEP 6: EXECUTE SCRIPT
-----------------------
Run: npx tsx scripts/import-<product-slug>.ts
This inserts data directly into the same Supabase instance that powers
varunsonline.com (via the GET /api/supplements endpoint).
STEP 7: VERIFY
---------------
Re-query the database to confirm all fields were saved correctly.
================================================================================
DATABASE TABLES POPULATED
================================================================================
Table Purpose
------------------- -------------------------------------------
brands Product brand (MuscleBlaze)
categories Product category (Isolate Protein)
retailers Seller/store (MuscleBlaze Official)
products Core product data (all 50 fields)
product_prices Price per retailer
affiliate_links Trackable outbound URL
product_filter_values Link products to filter options (goals)
================================================================================
IMPORTANT NOTES
================================================================================
- The supabaseAdmin client uses SUPABASE_SERVICE_ROLE_KEY (bypasses RLS).
- The product must have is_active = true to appear on the public website.
- The products page queries /api/supplements which always filters
is_active = true.
- The DEALS section on the homepage requires discount_percentage > 20%.
- The SUPPLECOST RECOMMENDED section requires brand_id = 'supplecost-products'.
- The product is immediately visible after upsert — no redeploy needed since
the Vercel frontend reads from the same Supabase instance at runtime.
================================================================================
PRODUCT 2: MuscleBlaze Biozyme Whey PR
================================================================================
Source Page:
https://www.muscleblaze.com/sv/muscleblaze-biozyme-whey-pr/SP-122029?navKey=VRNT-249465
Script: scripts/import-muscleblaze-biozyme-whey-pr.ts
Product ID: muscleblaze-biozyme-whey-pr
Slug: muscleblaze-biozyme-whey-pr
Category: whey-protein
Flavor: Molten Chocolate Cake
Weight: 1 kg (2.2 lb)
Serving: 45 g
Servings: 22
Protein: 30 g
Calories: 171
Best Price: ₹3,949
MRP: ₹3,999
Discount: 1%
UPC: 8906165785375
Key Differentiator:
Whey Concentrate with Creatine Monohydrate (CreAMP) & AstraGin®.
Unlike Biozyme Performance Whey (25g protein, no creatine) and
Biozyme Iso-Zero (27g isolate, no creatine), this PR variant
delivers 30g protein + 3g creatine per serving.
Cost Per Serving:
₹3,949 / 22 servings = ₹179.50
Extraction:
- Navigate to product URL
- Extract __NEXT_DATA__ via evaluate_script
- Key fields under pageProps.data.results:
- nm → product name
- offer_pr → best price
- mrp → original price
- discount → discount %
- pr_img.o_link → main image
- pv_upc → UPC/EAN
- hasAttributes → serving size, servings count, protein %
- urlFragment → product URL slug
- nut_info_grp → nutritional highlights
- Additional images from thumbnail img elements
Verification:
https://varunsonline.com/products/muscleblaze-biozyme-whey-pr
→ All fields display correctly including COST/SERVING = ₹179.5
================================================================================