vdimsa commited on
Commit
1affa63
·
verified ·
1 Parent(s): fec2265

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +270 -19
  3. prompts.txt +4 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Api Test
3
- emoji: 👀
4
- colorFrom: yellow
5
- colorTo: red
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: api-test
3
+ emoji: 🐳
4
+ colorFrom: pink
5
+ colorTo: yellow
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,270 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Deraah Product API Tester</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .fade-in {
11
+ animation: fadeIn 0.3s ease-in-out;
12
+ }
13
+
14
+ @keyframes fadeIn {
15
+ from { opacity: 0; transform: translateY(10px); }
16
+ to { opacity: 1; transform: translateY(0); }
17
+ }
18
+
19
+ .product-card {
20
+ transition: all 0.3s ease;
21
+ }
22
+
23
+ .product-card:hover {
24
+ transform: translateY(-5px);
25
+ box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
26
+ }
27
+
28
+ .input-focus {
29
+ transition: all 0.3s ease;
30
+ }
31
+
32
+ .input-focus:focus {
33
+ border-color: #8b5cf6;
34
+ box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
35
+ }
36
+ </style>
37
+ </head>
38
+ <body class="bg-gray-50 min-h-screen">
39
+ <div class="container mx-auto px-4 py-12">
40
+ <div class="max-w-3xl mx-auto">
41
+ <!-- Header -->
42
+ <div class="text-center mb-10">
43
+ <h1 class="text-4xl font-bold text-purple-800 mb-2">Deraah Product API Tester</h1>
44
+ <p class="text-lg text-gray-600">Enter a SKU to fetch live product information</p>
45
+ </div>
46
+
47
+ <!-- Search Form -->
48
+ <div class="bg-white rounded-xl shadow-md p-6 mb-8">
49
+ <form id="productForm" class="space-y-4">
50
+ <div>
51
+ <label for="sku" class="block text-sm font-medium text-gray-700 mb-1">Product SKU</label>
52
+ <div class="relative">
53
+ <input
54
+ type="text"
55
+ id="sku"
56
+ name="sku"
57
+ placeholder="e.g. 10411131442000-8050"
58
+ class="w-full px-4 py-3 rounded-lg border border-gray-300 input-focus focus:outline-none"
59
+ required
60
+ >
61
+ <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none hidden" id="loadingSpinner">
62
+ <i class="fas fa-spinner fa-spin text-purple-600"></i>
63
+ </div>
64
+ </div>
65
+ <p class="mt-1 text-sm text-gray-500">Enter a valid product SKU</p>
66
+ </div>
67
+
68
+ <button
69
+ type="submit"
70
+ class="w-full bg-purple-600 hover:bg-purple-700 text-white font-medium py-3 px-4 rounded-lg transition duration-300 flex items-center justify-center"
71
+ >
72
+ <i class="fas fa-search mr-2"></i> Fetch Product
73
+ </button>
74
+ </form>
75
+ </div>
76
+
77
+ <!-- Error Message -->
78
+ <div id="errorAlert" class="hidden bg-red-50 border-l-4 border-red-500 p-4 mb-8 rounded-lg">
79
+ <div class="flex">
80
+ <div class="flex-shrink-0">
81
+ <i class="fas fa-exclamation-circle text-red-500"></i>
82
+ </div>
83
+ <div class="ml-3">
84
+ <p class="text-sm text-red-700" id="errorMessage">Product not found. Please check the SKU and try again.</p>
85
+ </div>
86
+ </div>
87
+ </div>
88
+
89
+ <!-- Authentication Error -->
90
+ <div id="authErrorAlert" class="hidden bg-yellow-50 border-l-4 border-yellow-500 p-4 mb-8 rounded-lg">
91
+ <div class="flex">
92
+ <div class="flex-shrink-0">
93
+ <i class="fas fa-exclamation-triangle text-yellow-500"></i>
94
+ </div>
95
+ <div class="ml-3">
96
+ <p class="text-sm text-yellow-700" id="authErrorMessage">Authentication required. Please contact support.</p>
97
+ </div>
98
+ </div>
99
+ </div>
100
+
101
+ <!-- Product Card -->
102
+ <div id="productContainer" class="hidden">
103
+ <div class="product-card bg-white rounded-xl shadow-md overflow-hidden fade-in">
104
+ <div class="md:flex">
105
+ <div class="md:flex-shrink-0 md:w-1/3">
106
+ <img id="productImage" class="h-48 w-full object-cover md:h-full" src="" alt="Product image">
107
+ </div>
108
+ <div class="p-8 md:w-2/3">
109
+ <div class="flex justify-between items-start">
110
+ <div>
111
+ <h2 id="productName" class="text-2xl font-bold text-gray-800 mb-2"></h2>
112
+ <span id="availabilityBadge" class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium hidden">
113
+ <span class="w-2 h-2 mr-2 rounded-full bg-green-500"></span>
114
+ Available
115
+ </span>
116
+ </div>
117
+ <div id="productPrice" class="text-xl font-semibold text-purple-700"></div>
118
+ </div>
119
+ <p id="productDescription" class="mt-4 text-gray-600"></p>
120
+
121
+ <div class="mt-6">
122
+ <div class="flex items-center">
123
+ <span class="text-gray-500 mr-2">SKU:</span>
124
+ <span id="productSku" class="font-medium text-gray-700"></span>
125
+ </div>
126
+ </div>
127
+ </div>
128
+ </div>
129
+ </div>
130
+ </div>
131
+ </div>
132
+ </div>
133
+
134
+ <script>
135
+ document.addEventListener('DOMContentLoaded', function() {
136
+ const form = document.getElementById('productForm');
137
+ const errorAlert = document.getElementById('errorAlert');
138
+ const authErrorAlert = document.getElementById('authErrorAlert');
139
+ const productContainer = document.getElementById('productContainer');
140
+ const loadingSpinner = document.getElementById('loadingSpinner');
141
+
142
+ form.addEventListener('submit', async function(e) {
143
+ e.preventDefault();
144
+
145
+ const sku = document.getElementById('sku').value.trim();
146
+
147
+ if (!sku) {
148
+ showError('Please enter a SKU');
149
+ return;
150
+ }
151
+
152
+ // Show loading spinner
153
+ loadingSpinner.classList.remove('hidden');
154
+ // Hide previous results and errors
155
+ errorAlert.classList.add('hidden');
156
+ authErrorAlert.classList.add('hidden');
157
+ productContainer.classList.add('hidden');
158
+
159
+ try {
160
+ // Call our backend API route
161
+ const response = await fetch(`/api/products`, {
162
+ method: 'POST',
163
+ headers: {
164
+ 'Content-Type': 'application/json',
165
+ 'Accept': 'application/json'
166
+ },
167
+ body: JSON.stringify({ sku: sku })
168
+ });
169
+
170
+ // Check response status first
171
+ if (response.status === 401 || response.status === 403) {
172
+ throw new Error('AUTH_REQUIRED');
173
+ }
174
+
175
+ // Check if response is JSON
176
+ const contentType = response.headers.get('content-type');
177
+ if (!contentType || !contentType.includes('application/json')) {
178
+ const text = await response.text();
179
+ if (text.includes('<html') || text.includes('<!DOCTYPE html')) {
180
+ throw new Error('AUTH_REQUIRED');
181
+ }
182
+ throw new Error('Invalid response format from server');
183
+ }
184
+
185
+ const productData = await response.json();
186
+
187
+ if (!response.ok || productData.error) {
188
+ throw new Error(productData.message || 'Failed to fetch product');
189
+ }
190
+
191
+ if (!productData || Object.keys(productData).length === 0) {
192
+ throw new Error('Product not found');
193
+ }
194
+
195
+ // Display product data
196
+ displayProduct(productData);
197
+ } catch (error) {
198
+ console.error('Fetch error:', error);
199
+ if (error.message === 'AUTH_REQUIRED') {
200
+ showAuthError('Authentication required. Please contact support.');
201
+ } else {
202
+ showError(error.message || 'An error occurred while fetching product data. Please try again.');
203
+ }
204
+ } finally {
205
+ loadingSpinner.classList.add('hidden');
206
+ }
207
+ });
208
+
209
+ function showError(message) {
210
+ document.getElementById('errorMessage').textContent = message;
211
+ errorAlert.classList.remove('hidden');
212
+ productContainer.classList.add('hidden');
213
+ authErrorAlert.classList.add('hidden');
214
+ }
215
+
216
+ function showAuthError(message) {
217
+ document.getElementById('authErrorMessage').textContent = message;
218
+ authErrorAlert.classList.remove('hidden');
219
+ productContainer.classList.add('hidden');
220
+ errorAlert.classList.add('hidden');
221
+ }
222
+
223
+ function displayProduct(product) {
224
+ // Set product details
225
+ document.getElementById('productName').textContent = product.name || 'No name available';
226
+ document.getElementById('productDescription').textContent = product.shortDescription || product.description || 'No description available';
227
+
228
+ // Format price with currency
229
+ if (product.price && product.currency) {
230
+ const formattedPrice = new Intl.NumberFormat(undefined, {
231
+ style: 'currency',
232
+ currency: product.currency
233
+ }).format(product.price);
234
+ document.getElementById('productPrice').textContent = formattedPrice;
235
+ } else if (product.price) {
236
+ document.getElementById('productPrice').textContent = `$${product.price.toFixed(2)}`;
237
+ } else {
238
+ document.getElementById('productPrice').textContent = 'Price not available';
239
+ }
240
+
241
+ document.getElementById('productSku').textContent = product.sku || product.id || '';
242
+
243
+ // Set product image
244
+ const productImage = document.getElementById('productImage');
245
+ if (product.images && product.images.length > 0) {
246
+ productImage.src = product.images[0];
247
+ productImage.alt = product.name || 'Product image';
248
+ } else if (product.image) {
249
+ productImage.src = product.image;
250
+ productImage.alt = product.name || 'Product image';
251
+ } else {
252
+ productImage.src = 'https://via.placeholder.com/400x300?text=No+Image+Available';
253
+ productImage.alt = 'No image available';
254
+ }
255
+
256
+ // Set availability
257
+ const availabilityBadge = document.getElementById('availabilityBadge');
258
+ if (product.available || product.inStock) {
259
+ availabilityBadge.classList.remove('hidden');
260
+ } else {
261
+ availabilityBadge.classList.add('hidden');
262
+ }
263
+
264
+ // Show product container
265
+ productContainer.classList.remove('hidden');
266
+ }
267
+ });
268
+ </script>
269
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=vdimsa/api-test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
270
+ </html>
prompts.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ Build a responsive single-page web app called "Deraah Product API Tester" that allows users to enter a SKU and fetch product details from Deraah’s live API. The app should include a backend route /api/product that accepts a sku query parameter, validates that it's not empty, and sends a GET request to https://www.deraahstore.com/on/demandware.store/Sites-deraah_SA-Site/ar_SA/Vdimsa-ProductDetails?SKU={sku}. If the sku is missing, return HTTP 400 with { success: false, message: "Missing SKU" }, and if the API response has "success": false, return HTTP 404 with the error message. The frontend should feature a centered layout with a title “Deraah Product API Tester”, a subtitle “Enter a SKU to fetch live product information”, a labeled input field for the SKU, and a “Fetch Product” button. Upon submission, the app should call /api/product?sku={enteredSKU}, show a loading spinner, and display a product card if successful—showing the product name, short description, price with currency, availability badge (if available: true), and the first product image. If there’s an error, show a red alert box with the message “Product not found. Please check the SKU and try again.” The design should be responsive and mobile-friendly, using clean UI components such as cards, inputs, buttons, badges, spinners, and alerts, with a white background, blue or purple buttons, and red error messaging. Use shadows, spacing, and transitions for a smooth, professional UX. Use test SKU 10411131442000-8050 for validation.
2
+ i need to grab the real data not test
3
+ call the api through backend route insted of frontend The API is returning an HTML error page (e.g., a redirect, permission block, or login page). Your frontend is trying to .json() parse this HTML — resulting in the invalid token error. fix it
4
+ getting this error Received HTML response - possible authentication or permission issue. fix it please and insure its working 100%