File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import parseCookie from 'cookie'
21import { prop } from 'ramda'
32
43import { PRODUCT_HEADER } from '../constants'
54import { inflightUrlWithQuery , JanusClient } from '../HttpClient'
5+ import { extractSessionCookie } from './Session'
66
77export interface SegmentData {
88 campaigns ?: any
@@ -19,7 +19,6 @@ export interface SegmentData {
1919 [ key : string ] : any
2020}
2121
22- const SEGMENT_COOKIE = 'vtex_segment'
2322const SEGMENT_MAX_AGE_S = 60 * 60 // 60 minutes - segment is actually immutable
2423const ALLOWED_QUERY_PREFIXES = [ 'utm' , 'cultureInfo' , 'supportedLocales' ]
2524
@@ -71,15 +70,11 @@ export class Segment extends JanusClient {
7170 public getOrCreateSegment = async ( query ?: Record < string , string > , token ?: string ) => {
7271 const {
7372 data : segmentData ,
74- headers : {
75- 'set-cookie' : [ setCookies ] ,
76- } ,
73+ headers,
7774 } = await this . rawSegment ( token , query )
78- const parsedCookie = parseCookie . parse ( setCookies )
79- const segmentToken = prop ( SEGMENT_COOKIE , parsedCookie )
8075 return {
8176 segmentData,
82- segmentToken,
77+ segmentToken : extractSessionCookie ( headers ) || token ,
8378 }
8479 }
8580
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ export class Session extends JanusClient {
5151 }
5252}
5353
54- function extractSessionCookie ( headers : Record < string , string > ) {
54+ export function extractSessionCookie ( headers : Record < string , string > ) {
5555 for ( const setCookie of headers [ 'set-cookie' ] || [ ] ) {
5656 const parsedCookie = parseCookie . parse ( setCookie )
5757 const sessionCookie = parsedCookie [ SESSION_COOKIE ]
You can’t perform that action at this time.
0 commit comments