@vtex/faststore-plugin-buyer-portal 1.1.72-experimental.4 → 1.1.72-experimental.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.1.72-experimental.4",
3
+ "version": "1.1.72-experimental.5",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * User Details Page with integrated debug functionality
3
+ */
4
+
1
5
  import {
2
6
  getOrgUnitBasicDataService,
3
7
  getOrgUnitByUserIdService,
@@ -57,8 +61,43 @@ export async function loader(
57
61
  );
58
62
  }
59
63
 
64
+ function createErrorResponse(errorMessage: string, errorDetails?: any) {
65
+ return {
66
+ data: { user: null, orgUnit: { id: "", name: "" } },
67
+ context: {
68
+ clientContext: {
69
+ cookie: "",
70
+ vtexIdclientAutCookie: "",
71
+ customerId: "",
72
+ userId: "",
73
+ },
74
+ currentOrgUnit: null,
75
+ currentUser: null,
76
+ },
77
+ debug: {
78
+ logs,
79
+ error: {
80
+ message: errorMessage,
81
+ details: errorDetails,
82
+ timestamp: new Date().toISOString(),
83
+ },
84
+ },
85
+ };
86
+ }
87
+
60
88
  addLog("info", "START", "Starting user-details loader");
61
89
 
90
+ // Proteção extra contra dados malformados
91
+ if (!data) {
92
+ addLog("error", "VALIDATION", "LoaderData is undefined");
93
+ return createErrorResponse("LoaderData is undefined - request malformed");
94
+ }
95
+
96
+ if (!data.query) {
97
+ addLog("error", "VALIDATION", "Query parameters missing");
98
+ return createErrorResponse("Query parameters missing from request");
99
+ }
100
+
62
101
  try {
63
102
  addLog("info", "REQUEST", "Request info", {
64
103
  cookies: Object.keys(data.req?.cookies || {}),
@@ -80,7 +119,10 @@ export async function loader(
80
119
  userId,
81
120
  orgUnitId,
82
121
  });
83
- throw new Error("Missing required query parameters: userId or orgUnitId");
122
+ return createErrorResponse(
123
+ "Missing required query parameters: userId or orgUnitId",
124
+ { providedUserId: userId, providedOrgUnitId: orgUnitId }
125
+ );
84
126
  }
85
127
 
86
128
  addLog("info", "VALIDATION", "Query params validated ✅", {
@@ -96,22 +138,8 @@ export async function loader(
96
138
  });
97
139
 
98
140
  if (!user) {
99
- addLog("warn", "USER_SERVICE", "User not found - redirecting");
100
- data.res?.writeHead(302, { Location: "/buyer-portal" });
101
- data.res?.end();
102
-
103
- return {
104
- data: { user: null, orgUnit: { id: "", name: "" } },
105
- context: {
106
- clientContext: { cookie, ...clientContext },
107
- currentOrgUnit: null,
108
- currentUser: null,
109
- },
110
- debug: {
111
- logs,
112
- error: { message: "User not found", userId, orgUnitId },
113
- },
114
- };
141
+ addLog("warn", "USER_SERVICE", "User not found");
142
+ return createErrorResponse("User not found", { userId, orgUnitId });
115
143
  }
116
144
 
117
145
  addLog("info", "ORG_UNIT_BASIC", "Fetching current org unit...");
@@ -161,118 +189,72 @@ export async function loader(
161
189
 
162
190
  return result;
163
191
  } catch (error) {
192
+ const errorMessage =
193
+ error instanceof Error ? error.message : "Unknown error occurred";
194
+ const errorDetails =
195
+ error instanceof Error
196
+ ? {
197
+ name: error.name,
198
+ stack: error.stack,
199
+ }
200
+ : { rawError: error };
201
+
164
202
  addLog("error", "FATAL_ERROR", "Loader failed with error", {
165
- error: error instanceof Error ? error.message : "Unknown error",
166
- stack: error instanceof Error ? error.stack : undefined,
203
+ message: errorMessage,
204
+ details: errorDetails,
167
205
  });
168
206
 
169
- // Return error page instead of throwing
170
- return {
171
- data: { user: null, orgUnit: { id: "", name: "" } },
172
- context: {
173
- clientContext: {
174
- cookie: "",
175
- vtexIdclientAutCookie: "",
176
- customerId: "",
177
- userId: "",
178
- },
179
- currentOrgUnit: null,
180
- currentUser: null,
181
- },
182
- debug: {
183
- logs,
184
- error:
185
- error instanceof Error
186
- ? {
187
- message: error.message,
188
- name: error.name,
189
- stack: error.stack,
190
- }
191
- : { message: "Unknown error", error },
192
- },
193
- };
207
+ // Always return a valid response, never throw
208
+ return createErrorResponse(errorMessage, errorDetails);
194
209
  }
195
210
  }
196
211
 
197
- const UserDetailsPage = ({ data, context, debug }: UserDetailsPageData) => {
198
- // Se tiver debug info (erros), mostrar página de debug
199
- if (debug) {
212
+ const UserDetailsPage = (props?: UserDetailsPageData) => {
213
+ // Se props estiver undefined
214
+ if (!props) {
200
215
  return (
201
- <div
202
- style={{
203
- maxWidth: "900px",
204
- margin: "0 auto",
205
- padding: "20px",
206
- fontFamily: "system-ui, sans-serif",
207
- }}
208
- >
216
+ <div style={{ padding: "40px", textAlign: "center" }}>
217
+ <h1>🚨 Erro de Carregamento</h1>
218
+ <p>Não foi possível carregar os dados da página.</p>
219
+ <p>Tente recarregar a página ou verificar sua conexão.</p>
220
+ </div>
221
+ );
222
+ }
223
+
224
+ const { data, context, debug } = props;
225
+
226
+ // Se tiver debug info (erros), mostrar página simples de debug
227
+ if (debug?.error) {
228
+ return (
229
+ <div style={{ maxWidth: "800px", margin: "0 auto", padding: "20px" }}>
209
230
  <div
210
231
  style={{
211
232
  background: "#fff3cd",
212
- border: "1px solid #ffc107",
213
- borderRadius: "8px",
214
233
  padding: "20px",
215
234
  marginBottom: "20px",
235
+ borderRadius: "8px",
216
236
  }}
217
237
  >
218
- <h1 style={{ color: "#856404", margin: "0 0 10px 0" }}>
219
- 🚨 Erro na Página User Details
220
- </h1>
221
- <p style={{ color: "#856404", margin: 0 }}>
222
- Ocorreu um erro ao carregar a página. Veja os detalhes abaixo:
223
- </p>
238
+ <h1>🚨 Erro na Página User Details</h1>
239
+ <p>Ocorreu um erro ao carregar a página.</p>
224
240
  </div>
225
241
 
226
- {/* Logs em tempo real */}
227
- <div style={{ marginBottom: "30px" }}>
228
- <h2
229
- style={{
230
- color: "#333",
231
- borderBottom: "2px solid #007bff",
232
- paddingBottom: "10px",
233
- }}
234
- >
235
- 📝 Logs de Execução
236
- </h2>
242
+ <div style={{ marginBottom: "20px" }}>
243
+ <h2>📝 Logs de Execução</h2>
237
244
  <div
238
245
  style={{
239
246
  background: "#1e1e1e",
240
- color: "#ffffff",
247
+ color: "#fff",
241
248
  padding: "20px",
242
249
  borderRadius: "8px",
243
- fontFamily: "Monaco, Consolas, monospace",
244
- fontSize: "13px",
245
- maxHeight: "500px",
250
+ fontFamily: "monospace",
251
+ fontSize: "12px",
252
+ maxHeight: "400px",
246
253
  overflowY: "auto",
247
- border: "1px solid #333",
248
254
  }}
249
255
  >
250
- {debug.logs.map((log, index) => (
251
- <div
252
- key={index}
253
- style={{
254
- marginBottom: "12px",
255
- borderLeft: `4px solid ${
256
- log.level === "error"
257
- ? "#ff4444"
258
- : log.level === "warn"
259
- ? "#ff9800"
260
- : "#4caf50"
261
- }`,
262
- paddingLeft: "15px",
263
- paddingBottom: "8px",
264
- }}
265
- >
266
- <div
267
- style={{
268
- color: "#888",
269
- fontSize: "11px",
270
- marginBottom: "4px",
271
- }}
272
- >
273
- {new Date(log.timestamp).toLocaleTimeString("pt-BR")} -{" "}
274
- {log.step}
275
- </div>
256
+ {debug.logs?.map((log, index) => (
257
+ <div key={index} style={{ marginBottom: "10px" }}>
276
258
  <div
277
259
  style={{
278
260
  color:
@@ -281,24 +263,13 @@ const UserDetailsPage = ({ data, context, debug }: UserDetailsPageData) => {
281
263
  : log.level === "warn"
282
264
  ? "#ffa726"
283
265
  : "#81c784",
284
- fontWeight: "bold",
285
- marginBottom: log.data ? "8px" : 0,
286
266
  }}
287
267
  >
288
- [{log.level.toUpperCase()}] {log.message}
268
+ [{log.level.toUpperCase()}] {log.step}: {log.message}
289
269
  </div>
290
270
  {log.data && (
291
271
  <pre
292
- style={{
293
- fontSize: "11px",
294
- color: "#ccc",
295
- background: "#2d2d2d",
296
- padding: "8px",
297
- borderRadius: "4px",
298
- margin: 0,
299
- whiteSpace: "pre-wrap",
300
- overflow: "auto",
301
- }}
272
+ style={{ fontSize: "10px", color: "#ccc", margin: "5px 0" }}
302
273
  >
303
274
  {JSON.stringify(log.data, null, 2)}
304
275
  </pre>
@@ -308,27 +279,16 @@ const UserDetailsPage = ({ data, context, debug }: UserDetailsPageData) => {
308
279
  </div>
309
280
  </div>
310
281
 
311
- {/* Detalhes do erro */}
312
282
  {debug.error && (
313
- <div style={{ marginBottom: "30px" }}>
314
- <h2
315
- style={{
316
- color: "#dc3545",
317
- borderBottom: "2px solid #dc3545",
318
- paddingBottom: "10px",
319
- }}
320
- >
321
- ❌ Detalhes do Erro
322
- </h2>
283
+ <div style={{ marginBottom: "20px" }}>
284
+ <h2>❌ Detalhes do Erro</h2>
323
285
  <pre
324
286
  style={{
325
287
  background: "#f8d7da",
326
- color: "#721c24",
327
- padding: "20px",
288
+ padding: "15px",
328
289
  borderRadius: "8px",
329
- border: "1px solid #f5c6cb",
290
+ fontSize: "12px",
330
291
  overflow: "auto",
331
- fontSize: "13px",
332
292
  }}
333
293
  >
334
294
  {JSON.stringify(debug.error, null, 2)}
@@ -336,47 +296,30 @@ const UserDetailsPage = ({ data, context, debug }: UserDetailsPageData) => {
336
296
  </div>
337
297
  )}
338
298
 
339
- {/* Próximos passos */}
340
299
  <div
341
300
  style={{
342
301
  background: "#d1ecf1",
343
- border: "1px solid #bee5eb",
302
+ padding: "15px",
344
303
  borderRadius: "8px",
345
- padding: "20px",
346
304
  }}
347
305
  >
348
- <h3 style={{ color: "#0c5460", margin: "0 0 15px 0" }}>
349
- 🔧 Como resolver:
350
- </h3>
351
- <ol style={{ color: "#0c5460", paddingLeft: "20px" }}>
306
+ <h3>🔧 Como resolver:</h3>
307
+ <ol>
352
308
  <li>Verifique se você está logado na VTEX</li>
353
309
  <li>Confirme se os IDs da URL estão corretos</li>
354
310
  <li>Tente fazer logout e login novamente</li>
355
- <li>Se o erro persistir, entre em contato com o suporte</li>
311
+ <li>Abra o console do browser (F12) para ver logs adicionais</li>
356
312
  </ol>
357
-
358
- <div
359
- style={{
360
- marginTop: "15px",
361
- padding: "10px",
362
- background: "#b8daff",
363
- borderRadius: "4px",
364
- }}
365
- >
366
- <strong>💡 Dica:</strong> Abra o console do browser (F12) para ver
367
- logs adicionais
368
- </div>
369
313
  </div>
370
314
 
371
315
  <script
372
316
  dangerouslySetInnerHTML={{
373
317
  __html: `
374
- // Log debug info to browser console
375
- console.group('🔍 USER DETAILS DEBUG INFO');
376
- console.log('Error Details:', ${JSON.stringify(debug.error)});
377
- console.log('Execution Logs:', ${JSON.stringify(debug.logs)});
378
- console.groupEnd();
379
- `,
318
+ console.group('🔍 USER DETAILS DEBUG INFO');
319
+ console.log('Error Details:', ${JSON.stringify(debug.error)});
320
+ console.log('Execution Logs:', ${JSON.stringify(debug.logs)});
321
+ console.groupEnd();
322
+ `,
380
323
  }}
381
324
  />
382
325
  </div>