Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions node/clients/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

private getCommonHeaders = () => {
const { orderFormId, ownerId, segmentToken, sessionToken } = this
const { orderFormId, ownerId, segmentToken, sessionToken, rcSessionIdv7, rcMacIdv7 } = this

Check failure on line 33 in node/clients/checkout.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·orderFormId,·ownerId,·segmentToken,·sessionToken,·rcSessionIdv7,·rcMacIdv7·}·=·this⏎······` with `⏎······orderFormId,⏎······ownerId,⏎······segmentToken,⏎······sessionToken,⏎······rcSessionIdv7,⏎······rcMacIdv7,⏎····}·=·this`
.context as CustomIOContext

const checkoutCookie = orderFormId ? checkoutCookieFormat(orderFormId) : ''
Expand All @@ -43,8 +43,11 @@
? `vtex_session=${sessionToken};`
: ''

const rcSessionCookie = rcSessionIdv7 ? `VtexRCSessionIdv7=${rcSessionIdv7};` : ''

Check failure on line 46 in node/clients/checkout.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·?·`VtexRCSessionIdv7=${rcSessionIdv7};`` with `⏎······?·`VtexRCSessionIdv7=${rcSessionIdv7};`⏎·····`
const rcMacCookie = rcMacIdv7 ? `VtexRCMacIdv7=${rcMacIdv7};` : ''

return {
Cookie: `${checkoutCookie}${ownershipCookie}${segmentTokenCookie}${sessionTokenCookie}`,
Cookie: `${checkoutCookie}${ownershipCookie}${segmentTokenCookie}${sessionTokenCookie}${rcSessionCookie}${rcMacCookie}`,
}
}

Expand Down
8 changes: 4 additions & 4 deletions node/directives/withOwnerId.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defaultFieldResolver, GraphQLField } from 'graphql'
import { SchemaDirectiveVisitor } from 'graphql-tools'

import { getOwnerIdFromCookie } from '../utils'
import { getOwnerIdFromCookie, getRcSessionIdFromCookie, getRcMacIdFromCookie } from '../utils'

Check failure on line 4 in node/directives/withOwnerId.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·getOwnerIdFromCookie,·getRcSessionIdFromCookie,·getRcMacIdFromCookie·` with `⏎··getOwnerIdFromCookie,⏎··getRcSessionIdFromCookie,⏎··getRcMacIdFromCookie,⏎`

export class WithOwnerId extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field

field.resolve = async (root: any, args: any, ctx: Context, info: any) => {
const checkoutOwnerId = getOwnerIdFromCookie(ctx.cookies)

ctx.vtex.ownerId = checkoutOwnerId
ctx.vtex.ownerId = getOwnerIdFromCookie(ctx.cookies)
ctx.vtex.rcSessionIdv7 = getRcSessionIdFromCookie(ctx.cookies)
ctx.vtex.rcMacIdv7 = getRcMacIdFromCookie(ctx.cookies)

return resolve(root, args, ctx, info)
}
Expand Down
2 changes: 2 additions & 0 deletions node/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ declare global {
segment?: SegmentData
orderFormId?: string
ownerId?: string
rcSessionIdv7?: string
rcMacIdv7?: string
}

interface StoreGraphQLDataSources {
Expand Down
12 changes: 12 additions & 0 deletions node/utils/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const parseCookie = (cookie: string): ParsedCookie => {
const CHECKOUT_COOKIE = 'checkout.vtex.com'
const ASPXAUTH_COOKIE = '.ASPXAUTH'
const OWNERSHIP_COOKIE = 'CheckoutOrderFormOwnership'
const RC_SESSION_COOKIE = 'VtexRCSessionIdv7'
const RC_MAC_COOKIE = 'VtexRCMacIdv7'

const checkoutCookieFormat = (orderFormId: string) =>
`${CHECKOUT_COOKIE}=__ofid=${orderFormId};`
Expand All @@ -53,11 +55,21 @@ export function getOwnerIdFromCookie(cookies: Context['cookies']) {
return cookies.get(OWNERSHIP_COOKIE)
}

export function getRcSessionIdFromCookie(cookies: Context['cookies']) {
return cookies.get(RC_SESSION_COOKIE)
}

export function getRcMacIdFromCookie(cookies: Context['cookies']) {
return cookies.get(RC_MAC_COOKIE)
}

export {
isUserLoggedIn,
CHECKOUT_COOKIE,
ASPXAUTH_COOKIE,
OWNERSHIP_COOKIE,
RC_SESSION_COOKIE,
RC_MAC_COOKIE,
checkoutCookieFormat,
getOrderFormIdFromCookie,
parseCookie,
Expand Down
Loading