@akinon/next 2.0.104 → 2.0.105-beta.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/CHANGELOG.md +3 -3
- package/api/auth.ts +20 -97
- package/data/client/user.ts +1 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 2.0.
|
|
3
|
+
## 2.0.105-beta.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- cbbbfd757: ZERO-4376: Bootstrap beta cycle (next-main pre-release motor)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## 2.0.104
|
|
10
10
|
|
|
11
11
|
## 2.0.103
|
|
12
12
|
|
package/api/auth.ts
CHANGED
|
@@ -225,31 +225,12 @@ const getDefaultAuthConfig = () => {
|
|
|
225
225
|
}
|
|
226
226
|
);
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
const body = (await request.json()) as {
|
|
229
229
|
key: string;
|
|
230
230
|
non_field_errors: string[];
|
|
231
231
|
redirect_url: string;
|
|
232
232
|
};
|
|
233
233
|
|
|
234
|
-
try {
|
|
235
|
-
body = await request.json();
|
|
236
|
-
} catch {
|
|
237
|
-
// Backend returned a non-JSON body (e.g. an HTML error page on
|
|
238
|
-
// a 500/502) — surface a clean auth error instead of letting
|
|
239
|
-
// the SyntaxError bubble up as an opaque "Configuration" error
|
|
240
|
-
// (ZERO-4866).
|
|
241
|
-
logger.warn(
|
|
242
|
-
`Login/Register response was not valid JSON (status ${request.status})`,
|
|
243
|
-
{ userIp }
|
|
244
|
-
);
|
|
245
|
-
throwAuthError([
|
|
246
|
-
{
|
|
247
|
-
type: 'non_field_errors',
|
|
248
|
-
data: ['Something went wrong. Please try again later.']
|
|
249
|
-
}
|
|
250
|
-
]);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
234
|
return { request, body };
|
|
254
235
|
};
|
|
255
236
|
|
|
@@ -293,32 +274,17 @@ const getDefaultAuthConfig = () => {
|
|
|
293
274
|
|
|
294
275
|
let sessionId = '';
|
|
295
276
|
let rotatedCsrfToken = '';
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
for (const cookieHeader of setCookieHeaders) {
|
|
307
|
-
if (!sessionId) {
|
|
308
|
-
const sessionMatch = cookieHeader?.match(/osessionid=\w+/)?.[0];
|
|
309
|
-
if (sessionMatch) {
|
|
310
|
-
sessionId = sessionMatch.replace('osessionid=', '');
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (!rotatedCsrfToken) {
|
|
314
|
-
const csrfMatch = cookieHeader?.match(/csrftoken=[^;,\s]+/)?.[0];
|
|
315
|
-
if (csrfMatch) {
|
|
316
|
-
rotatedCsrfToken = csrfMatch.replace('csrftoken=', '');
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
277
|
+
const setCookieHeader = apiRequest.headers.get('set-cookie');
|
|
278
|
+
if (setCookieHeader) {
|
|
279
|
+
sessionId =
|
|
280
|
+
setCookieHeader
|
|
281
|
+
.match(/osessionid=\w+/)?.[0]
|
|
282
|
+
.replace(/osessionid=/, '') || '';
|
|
283
|
+
rotatedCsrfToken =
|
|
284
|
+
setCookieHeader
|
|
285
|
+
.match(/csrftoken=[^;,\s]+/)?.[0]
|
|
286
|
+
.replace(/csrftoken=/, '') || '';
|
|
320
287
|
|
|
321
|
-
if (sessionId) {
|
|
322
288
|
logger.debug(`Login/Register session id: ${sessionId}`);
|
|
323
289
|
} else {
|
|
324
290
|
logger.warn('No set-cookie header found in response');
|
|
@@ -375,14 +341,8 @@ const getDefaultAuthConfig = () => {
|
|
|
375
341
|
}
|
|
376
342
|
}
|
|
377
343
|
|
|
378
|
-
// Register/OTP responses don't rotate the session cookie — the
|
|
379
|
-
// backend upgrades the shopper's existing anonymous osessionid in
|
|
380
|
-
// place instead of issuing a new one, so no Set-Cookie is present
|
|
381
|
-
// here. Falling back to the pre-request session id keeps this
|
|
382
|
-
// working for those flows (login always rotates it, so sessionId
|
|
383
|
-
// still wins there) (ZERO-4866).
|
|
384
344
|
const currentUser = await getCurrentUser(
|
|
385
|
-
sessionId
|
|
345
|
+
sessionId,
|
|
386
346
|
cookieStore.get('pz-currency')?.value ?? ''
|
|
387
347
|
);
|
|
388
348
|
return currentUser;
|
|
@@ -571,31 +531,12 @@ const defaultNextAuthOptionsV4 = (req: any, res: any) => {
|
|
|
571
531
|
}
|
|
572
532
|
);
|
|
573
533
|
|
|
574
|
-
|
|
534
|
+
const body = (await request.json()) as {
|
|
575
535
|
key: string;
|
|
576
536
|
non_field_errors: string[];
|
|
577
537
|
redirect_url: string;
|
|
578
538
|
};
|
|
579
539
|
|
|
580
|
-
try {
|
|
581
|
-
body = await request.json();
|
|
582
|
-
} catch {
|
|
583
|
-
// Backend returned a non-JSON body (e.g. an HTML error page on
|
|
584
|
-
// a 500/502) — surface a clean auth error instead of letting
|
|
585
|
-
// the SyntaxError bubble up as an opaque "Configuration" error
|
|
586
|
-
// (ZERO-4866).
|
|
587
|
-
logger.warn(
|
|
588
|
-
`Login/Register response was not valid JSON (status ${request.status})`,
|
|
589
|
-
{ userIp }
|
|
590
|
-
);
|
|
591
|
-
throwAuthError([
|
|
592
|
-
{
|
|
593
|
-
type: 'non_field_errors',
|
|
594
|
-
data: ['Something went wrong. Please try again later.']
|
|
595
|
-
}
|
|
596
|
-
]);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
540
|
return { request, body };
|
|
600
541
|
};
|
|
601
542
|
|
|
@@ -638,25 +579,13 @@ const defaultNextAuthOptionsV4 = (req: any, res: any) => {
|
|
|
638
579
|
logger.debug(`Login/Register response: ${JSON.stringify(response)}`);
|
|
639
580
|
|
|
640
581
|
let sessionId = '';
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
typeof apiRequest.headers.getSetCookie === 'function'
|
|
648
|
-
? apiRequest.headers.getSetCookie()
|
|
649
|
-
: [apiRequest.headers.get('set-cookie')].filter(Boolean);
|
|
650
|
-
|
|
651
|
-
for (const cookieHeader of setCookieHeaders) {
|
|
652
|
-
const match = cookieHeader?.match(/osessionid=\w+/)?.[0];
|
|
653
|
-
if (match) {
|
|
654
|
-
sessionId = match.replace('osessionid=', '');
|
|
655
|
-
break;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
582
|
+
const setCookieHeader = apiRequest.headers.get('set-cookie');
|
|
583
|
+
if (setCookieHeader) {
|
|
584
|
+
sessionId =
|
|
585
|
+
setCookieHeader
|
|
586
|
+
.match(/osessionid=\w+/)?.[0]
|
|
587
|
+
.replace(/osessionid=/, '') || '';
|
|
658
588
|
|
|
659
|
-
if (sessionId) {
|
|
660
589
|
logger.debug(`Login/Register session id: ${sessionId}`);
|
|
661
590
|
} else {
|
|
662
591
|
logger.warn('No set-cookie header found in response');
|
|
@@ -696,14 +625,8 @@ const defaultNextAuthOptionsV4 = (req: any, res: any) => {
|
|
|
696
625
|
}
|
|
697
626
|
}
|
|
698
627
|
|
|
699
|
-
// Register/OTP responses don't rotate the session cookie — the
|
|
700
|
-
// backend upgrades the shopper's existing anonymous osessionid in
|
|
701
|
-
// place instead of issuing a new one, so no Set-Cookie is present
|
|
702
|
-
// here. Falling back to the pre-request session id keeps this
|
|
703
|
-
// working for those flows (login always rotates it, so sessionId
|
|
704
|
-
// still wins there) (ZERO-4866).
|
|
705
628
|
const currentUser = await getCurrentUser(
|
|
706
|
-
sessionId
|
|
629
|
+
sessionId,
|
|
707
630
|
req.cookies['pz-currency'] ?? ''
|
|
708
631
|
);
|
|
709
632
|
return currentUser;
|
package/data/client/user.ts
CHANGED
|
@@ -22,12 +22,7 @@ const userApi = api.injectEndpoints({
|
|
|
22
22
|
getCaptcha: build.query<GetCaptchaResponse, void>({
|
|
23
23
|
query: () => buildClientRequestUrl(user.captcha),
|
|
24
24
|
transformResponse: (response: { html: string }) => {
|
|
25
|
-
|
|
26
|
-
// reCAPTCHA site key configured (data-sitekey="") — an empty
|
|
27
|
-
// siteKey is handled by the caller, whereas a thrown error here
|
|
28
|
-
// isn't (ZERO-4866).
|
|
29
|
-
const siteKey =
|
|
30
|
-
response.html.match(/data-sitekey="([^"]+)"/i)?.[1] || '';
|
|
25
|
+
const siteKey = response.html.match(/data-sitekey="([^"]+)"/i)[1];
|
|
31
26
|
|
|
32
27
|
const csrfTokenMatch = response.html.match(
|
|
33
28
|
/name=['|"]csrfmiddlewaretoken['|"] value=['|"][^'"]+/gi
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/next",
|
|
3
3
|
"description": "Core package for Project Zero Next",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.105-beta.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"set-cookie-parser": "2.6.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@akinon/eslint-plugin-projectzero": "2.0.
|
|
39
|
+
"@akinon/eslint-plugin-projectzero": "2.0.105-beta.0",
|
|
40
40
|
"@babel/core": "7.26.10",
|
|
41
41
|
"@babel/preset-env": "7.26.9",
|
|
42
42
|
"@babel/preset-typescript": "7.27.0",
|