keystone-design-bootstrap 1.0.101 → 1.0.102

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": "keystone-design-bootstrap",
3
- "version": "1.0.101",
3
+ "version": "1.0.102",
4
4
  "description": "Keystone Design Bootstrap - Sections, Elements, and Theme System for customer websites",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -47,6 +47,10 @@ function apiHeaders(request?: Request): Record<string, string> {
47
47
  };
48
48
  }
49
49
 
50
+ function responseData(json: Record<string, unknown>): Record<string, unknown> {
51
+ return (json.data as Record<string, unknown>) || json;
52
+ }
53
+
50
54
  // POST /api/consumer/initiate
51
55
  // Looks up an existing user by email or phone, creating a Contact if needed.
52
56
  // Returns { exists, firstName, hasPassword }.
@@ -68,8 +72,8 @@ async function handleInitiate(request: Request, NR: NextResponseLike): Promise<R
68
72
  if (res.status === 404) return NR.json({ exists: false });
69
73
  if (!res.ok) return NR.json({ exists: null });
70
74
 
71
- const json = await res.json().catch(() => ({}));
72
- const data = json.data as Record<string, unknown> | undefined;
75
+ const json = await res.json().catch(() => ({})) as Record<string, unknown>;
76
+ const data = responseData(json);
73
77
  return NR.json({
74
78
  exists: true,
75
79
  firstName: data?.first_name ?? undefined,
@@ -172,20 +176,21 @@ async function handleSendCode(request: Request, NR: NextResponseLike): Promise<R
172
176
  body: JSON.stringify({ phone }),
173
177
  });
174
178
 
175
- const json = await res.json().catch(() => ({}));
179
+ const json = await res.json().catch(() => ({})) as Record<string, unknown>;
180
+ const data = responseData(json);
176
181
  if (!res.ok) {
177
182
  return NR.json(
178
183
  {
179
- error: json.error || 'Failed to send verification code. Please try again.',
180
- code: json.code,
181
- retry_in_seconds: json.retry_in_seconds,
184
+ error: (json as Record<string, unknown>).error || 'Failed to send verification code. Please try again.',
185
+ code: (json as Record<string, unknown>).code,
186
+ retry_in_seconds: (json as Record<string, unknown>).retry_in_seconds,
182
187
  },
183
188
  { status: res.status }
184
189
  );
185
190
  }
186
191
 
187
192
  return NR.json({
188
- resend_available_at: json.data?.resend_available_at ?? null,
193
+ resend_available_at: data?.resend_available_at ?? null,
189
194
  });
190
195
  }
191
196
 
@@ -202,19 +207,23 @@ async function handleVerifyCode(request: Request, NR: NextResponseLike): Promise
202
207
  body: JSON.stringify({ phone, code }),
203
208
  });
204
209
 
205
- const json = await res.json().catch(() => ({}));
210
+ const json = await res.json().catch(() => ({})) as Record<string, unknown>;
211
+ const data = responseData(json);
206
212
  if (!res.ok) {
207
213
  return NR.json(
208
- { error: json.error || 'Verification failed. Please try again.', code: json.code },
214
+ {
215
+ error: (json as Record<string, unknown>).error || 'Verification failed. Please try again.',
216
+ code: (json as Record<string, unknown>).code,
217
+ },
209
218
  { status: res.status }
210
219
  );
211
220
  }
212
221
 
213
222
  return NR.json({
214
- verification_token: json.data?.verification_token,
215
- first_name: json.data?.first_name ?? '',
216
- last_name: json.data?.last_name ?? '',
217
- email: json.data?.email ?? '',
223
+ verification_token: data?.verification_token,
224
+ first_name: data?.first_name ?? '',
225
+ last_name: data?.last_name ?? '',
226
+ email: data?.email ?? '',
218
227
  });
219
228
  }
220
229
 
@@ -242,17 +251,21 @@ async function handlePasswordlessAuth(request: Request, NR: NextResponseLike): P
242
251
  }),
243
252
  });
244
253
 
245
- const json = await res.json().catch(() => ({}));
254
+ const json = await res.json().catch(() => ({})) as Record<string, unknown>;
255
+ const data = responseData(json);
246
256
  if (!res.ok) {
247
- return NR.json({ error: json.error || 'Authentication failed. Please try again.' }, { status: res.status });
257
+ return NR.json(
258
+ { error: (json as Record<string, unknown>).error || 'Authentication failed. Please try again.' },
259
+ { status: res.status }
260
+ );
248
261
  }
249
262
 
250
- const token = json.data?.token;
263
+ const token = data?.token;
251
264
  if (!token) return NR.json({ error: 'No token received.' }, { status: 500 });
252
265
 
253
266
  // Surface the server-side Lead event_id so the browser can fire a single deduped
254
267
  // Lead (fbq track with { eventID }) that Meta matches against the CAPI Lead event.
255
- const response = NR.json({ eventId: json.data?.event_id ?? undefined });
268
+ const response = NR.json({ eventId: data?.event_id ?? undefined });
256
269
  response.cookies.set(CONSUMER_TOKEN_COOKIE, token, {
257
270
  httpOnly: true,
258
271
  secure: process.env.NODE_ENV === 'production',