diff --git a/vtex/actions/session/createSession.ts b/vtex/actions/session/createSession.ts new file mode 100644 index 000000000..ae3aa3825 --- /dev/null +++ b/vtex/actions/session/createSession.ts @@ -0,0 +1,38 @@ +import type { AppContext } from "../../mod.ts"; +import { proxySetCookie } from "../../utils/cookies.ts"; +import type { CreateEditSessionResponse } from "../../utils/openapi/vcs.openapi.gen.ts"; + +interface Props { + publicProperties: Record; +} + +async function action( + props: Props, + req: Request, + ctx: AppContext, +): Promise { + const { vcs } = ctx; + + try { + const response = await vcs["POST /api/sessions"]({}, { + body: { + public: { + ...props.publicProperties, + }, + }, + }); + + if (!response.ok) { + throw new Error(`Failed to create session: ${response.status}`); + } + + proxySetCookie(response.headers, ctx.response.headers, req.url); + + return await response.json(); + } catch (error) { + console.error("Error creating VTEX session:", error); + return null; + } +} + +export default action; diff --git a/vtex/actions/session/deleteSession.ts b/vtex/actions/session/deleteSession.ts new file mode 100644 index 000000000..edc677a82 --- /dev/null +++ b/vtex/actions/session/deleteSession.ts @@ -0,0 +1,39 @@ +import { AppContext } from "../../mod.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +export interface DeleteSession { + logOutFromSession: string; +} + +const mutation = `mutation LogOutFromSession($sessionId: ID) { + logOutFromSession(sessionId: $sessionId) @context(provider: "vtex.store-graphql@2.x") +}`; + +interface Props { + sessionId: string; +} + +async function action( + { sessionId }: Props, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + try { + return await io.query({ + query: mutation, + variables: { sessionId }, + }, { headers: { cookie } }); + } catch (error) { + console.error(error); + return null; + } +} + +export default action; diff --git a/vtex/actions/session/editSession.ts b/vtex/actions/session/editSession.ts new file mode 100644 index 000000000..100266a7e --- /dev/null +++ b/vtex/actions/session/editSession.ts @@ -0,0 +1,41 @@ +import type { AppContext } from "../../mod.ts"; +import { proxySetCookie } from "../../utils/cookies.ts"; +import type { CreateEditSessionResponse } from "../../utils/openapi/vcs.openapi.gen.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +interface Props { + publicProperties: Record; +} + +async function action( + props: Props, + req: Request, + ctx: AppContext, +): Promise { + const { vcs } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + try { + const response = await vcs["PATCH /api/sessions"]({}, { + body: { + public: { + ...props.publicProperties, + }, + }, + headers: { cookie }, + }); + + if (!response.ok) { + throw new Error(`Failed to edit session: ${response.status}`); + } + + proxySetCookie(response.headers, ctx.response.headers, req.url); + + return await response.json(); + } catch (error) { + console.error("Error editing VTEX session:", error); + return null; + } +} + +export default action; diff --git a/vtex/loaders/session/getSession.ts b/vtex/loaders/session/getSession.ts new file mode 100644 index 000000000..f3c0917f6 --- /dev/null +++ b/vtex/loaders/session/getSession.ts @@ -0,0 +1,42 @@ +import type { AppContext } from "../../mod.ts"; +import type { GetSessionResponse } from "../../utils/openapi/vcs.openapi.gen.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +interface Props { + /** + * Items are the keys of the values you wish to get. They follow the format namespace1.key1,namespace2.key2. + * + * If you wish to recover the data sent on Create new session, it should be public.{key}, replacing {key} with the name of the custom property you created. Following the example request presented in Create new session, it would be public.variable1,public.variable2. + * + * If you want to retrieve all keys from Session Manager, you can use the wildcard operator (*) as a value for this query parameter. + */ + items: string[]; +} + +async function loader( + props: Props, + req: Request, + ctx: AppContext, +): Promise { + const { vcs } = ctx; + const { cookie } = parseCookie(req.headers, ctx.account); + + try { + const response = await vcs["GET /api/sessions"]({ + items: props.items.join(","), + }, { + headers: { cookie }, + }); + + if (!response.ok) { + throw new Error(`Failed to get session: ${response.status}`); + } + + return await response.json(); + } catch (error) { + console.error("Error getting VTEX session:", error); + return null; + } +} + +export default loader; diff --git a/vtex/loaders/session/getUserSessions.ts b/vtex/loaders/session/getUserSessions.ts new file mode 100644 index 000000000..9c58fbf2a --- /dev/null +++ b/vtex/loaders/session/getUserSessions.ts @@ -0,0 +1,51 @@ +import type { AppContext } from "../../mod.ts"; +import type { LoginSessionsInfo } from "../../utils/types.ts"; +import { parseCookie } from "../../utils/vtexId.ts"; + +const query = `query getUserSessions { + loginSessionsInfo { + currentLoginSessionId + loginSessions { + id + cacheId + deviceType + city + lastAccess + browser + os + ip + fullAddress + firstAccess + } + } +}`; + +async function loader( + _props: unknown, + req: Request, + ctx: AppContext, +): Promise { + const { io } = ctx; + const { cookie, payload } = parseCookie(req.headers, ctx.account); + + if (!payload?.sub || !payload?.userId) { + return null; + } + + try { + const data = await io.query< + { loginSessionsInfo: LoginSessionsInfo }, + null + >( + { query }, + { headers: { cookie } }, + ); + + return data.loginSessionsInfo; + } catch (e) { + console.error(e); + return null; + } +} + +export default loader; diff --git a/vtex/manifest.gen.ts b/vtex/manifest.gen.ts index 921f1446c..b0f7ca0f1 100644 --- a/vtex/manifest.gen.ts +++ b/vtex/manifest.gen.ts @@ -24,9 +24,12 @@ import * as $$$$$$$$$18 from "./actions/masterdata/updateDocument.ts"; import * as $$$$$$$$$19 from "./actions/newsletter/subscribe.ts"; import * as $$$$$$$$$20 from "./actions/notifyme.ts"; import * as $$$$$$$$$21 from "./actions/review/submit.ts"; -import * as $$$$$$$$$22 from "./actions/trigger.ts"; -import * as $$$$$$$$$23 from "./actions/wishlist/addItem.ts"; -import * as $$$$$$$$$24 from "./actions/wishlist/removeItem.ts"; +import * as $$$$$$$$$22 from "./actions/session/createSession.ts"; +import * as $$$$$$$$$23 from "./actions/session/deleteSession.ts"; +import * as $$$$$$$$$24 from "./actions/session/editSession.ts"; +import * as $$$$$$$$$25 from "./actions/trigger.ts"; +import * as $$$$$$$$$26 from "./actions/wishlist/addItem.ts"; +import * as $$$$$$$$$27 from "./actions/wishlist/removeItem.ts"; import * as $$$$0 from "./handlers/sitemap.ts"; import * as $$$0 from "./loaders/cart.ts"; import * as $$$1 from "./loaders/categories/tree.ts"; @@ -64,10 +67,12 @@ import * as $$$32 from "./loaders/product/extensions/suggestions.ts"; import * as $$$33 from "./loaders/product/wishlist.ts"; import * as $$$34 from "./loaders/promotion/getPromotionById.ts"; import * as $$$35 from "./loaders/proxy.ts"; -import * as $$$36 from "./loaders/user.ts"; -import * as $$$37 from "./loaders/wishlist.ts"; -import * as $$$38 from "./loaders/workflow/product.ts"; -import * as $$$39 from "./loaders/workflow/products.ts"; +import * as $$$36 from "./loaders/session/getSession.ts"; +import * as $$$37 from "./loaders/session/getUserSessions.ts"; +import * as $$$38 from "./loaders/user.ts"; +import * as $$$39 from "./loaders/wishlist.ts"; +import * as $$$40 from "./loaders/workflow/product.ts"; +import * as $$$41 from "./loaders/workflow/products.ts"; import * as $$$$$$0 from "./sections/Analytics/Vtex.tsx"; import * as $$$$$$$$$$0 from "./workflows/events.ts"; import * as $$$$$$$$$$1 from "./workflows/product/index.ts"; @@ -110,10 +115,12 @@ const manifest = { "vtex/loaders/product/wishlist.ts": $$$33, "vtex/loaders/promotion/getPromotionById.ts": $$$34, "vtex/loaders/proxy.ts": $$$35, - "vtex/loaders/user.ts": $$$36, - "vtex/loaders/wishlist.ts": $$$37, - "vtex/loaders/workflow/product.ts": $$$38, - "vtex/loaders/workflow/products.ts": $$$39, + "vtex/loaders/session/getSession.ts": $$$36, + "vtex/loaders/session/getUserSessions.ts": $$$37, + "vtex/loaders/user.ts": $$$38, + "vtex/loaders/wishlist.ts": $$$39, + "vtex/loaders/workflow/product.ts": $$$40, + "vtex/loaders/workflow/products.ts": $$$41, }, "handlers": { "vtex/handlers/sitemap.ts": $$$$0, @@ -144,9 +151,12 @@ const manifest = { "vtex/actions/newsletter/subscribe.ts": $$$$$$$$$19, "vtex/actions/notifyme.ts": $$$$$$$$$20, "vtex/actions/review/submit.ts": $$$$$$$$$21, - "vtex/actions/trigger.ts": $$$$$$$$$22, - "vtex/actions/wishlist/addItem.ts": $$$$$$$$$23, - "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$24, + "vtex/actions/session/createSession.ts": $$$$$$$$$22, + "vtex/actions/session/deleteSession.ts": $$$$$$$$$23, + "vtex/actions/session/editSession.ts": $$$$$$$$$24, + "vtex/actions/trigger.ts": $$$$$$$$$25, + "vtex/actions/wishlist/addItem.ts": $$$$$$$$$26, + "vtex/actions/wishlist/removeItem.ts": $$$$$$$$$27, }, "workflows": { "vtex/workflows/events.ts": $$$$$$$$$$0, diff --git a/vtex/utils/openapi/vcs.openapi.gen.ts b/vtex/utils/openapi/vcs.openapi.gen.ts index c870b409d..8820361b3 100644 --- a/vtex/utils/openapi/vcs.openapi.gen.ts +++ b/vtex/utils/openapi/vcs.openapi.gen.ts @@ -19538,6 +19538,60 @@ per_page: string } response: Userorderslist } +/** + * Retrieves information from a previously created sesssion. + * + * >⚠️ The Session Manager API uses the `vtex_session` and `vtex_segment` cookies to store the data required to identify the user and the session. These cookies are stored in the user's browser when the session is created and sent automatically in every request to that domain. You will have to reproduce that by sending these cookies as headers to Session Manager API in order for it to work outside of a browser environment. + * + * ## Permissions + * + * This endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3). + */ +"GET /api/sessions": { +searchParams: { +/** + * Items are the keys of the values you wish to get. They follow the format `namespace1.key1,namespace2.key2`. + * + * If you wish to recover the data sent on [Create new session](https://developers.vtex.com/docs/api-reference/session-manager-api#post-/api/sessions), it should be `public.{key}`, replacing `{key}` with the name of the custom property you created. Following the example request presented in [Create new session](https://developers.vtex.com/docs/api-reference/session-manager-api#post-/api/sessions), it would be `public.variable1,public.variable2`. + * + * If you want to retrieve all keys from Session Manager, you can use the wildcard operator (`*`) as a value for this query parameter. + */ +items: string +} +response: GetSessionResponse +} +/** + * Creates a new session and returns a session token and a segment token. Also stores `vtex_session` and `vtex_segment` cookies, with the same values returned in the response. + * + * All parameters in the body that are not within the public namespace will be ignored. Query string items will automatically be added to the public namespace. + * + * >⚠️ The Session Manager API uses the `vtex_session` and `vtex_segment` cookies to store the data required to identify the user and the session. These cookies are stored in the user's browser when the session is created and sent automatically in every request to that domain. You will have to reproduce that by sending these cookies as headers in other requests to Session Manager API in order for it to work outside of a browser environment. + * + * ## Permissions + * + * This endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3). + */ +"POST /api/sessions": { +body: CreateEditSessionRequest +response: CreateEditSessionResponse +} +/** + * Edits information from a previously created sesssion. + * + * This endpoint works the same way as the [Create new session](https://developers.vtex.com/docs/api-reference/session-manager-api#post-/api/sessions) endpoint, but when the request is sent with a `vtex_session` and the `vtex_segment` cookies in the header, it retrieves the session first and then applies the changes instead of generating a new one. + * + * Only keys inside the `public` namespace in the request body are considered, and query parameters are automatically added to the public namespace. + * + * >⚠️ The Session Manager API uses the `vtex_session` and `vtex_segment` cookies to store the data required to identify the user and the session. These cookies are stored in the user's browser when the session is created and sent automatically in every request to that domain. You will have to reproduce that by sending these cookies as headers to Session Manager API in order for it to work outside of a browser environment. + * + * ## Permissions + * + * This endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3). + */ +"PATCH /api/sessions": { +body: CreateEditSessionRequest +response: CreateEditSessionResponse +} } /** * Pickup point information. @@ -21977,3 +22031,165 @@ Facets: { } } +/** + * Session information. + */ +export interface GetSessionResponse { +/** + * Session ID. + */ +id?: string +/** + * Object with namespaces, each containing a set of information about the session. + */ +namespaces?: { +/** + * Account information related to the session. + */ +account?: { +/** + * VTEX account ID. + */ +id?: { +/** + * Value of the VTEX account ID. + */ +value?: string +/** + * Determines whether or not the connection should be kept alive. + */ +keepAlive?: boolean +} +/** + * VTEX account name. + */ +accountName?: { +/** + * Value of the VTEX account name. + */ +value?: string +} +} +/** + * Store information related to the session. + */ +store?: { +/** + * [Trade policy](https://help.vtex.com/en/tutorial/how-trade-policies-work--6Xef8PZiFm40kg2STrMkMV) ID. + */ +channel?: { +/** + * Value of the [Trade policy](https://help.vtex.com/en/tutorial/how-trade-policies-work--6Xef8PZiFm40kg2STrMkMV) ID. + */ +value?: string +} +/** + * Country code. + */ +countryCode?: { +/** + * Value of the country code. + */ +value?: string +} +/** + * Locale that provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. Read [this documentation](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-7.0#culture-names-and-identifiers) for more details. + */ +cultureInfo?: { +/** + * Value of the `cultureInfo` property. + */ +value?: string +} +/** + * Currency code. + */ +currencyCode?: { +/** + * Value of the currency code. + */ +value?: string +} +/** + * Currency symbol. + */ +currencySymbol?: { +/** + * Value of the currency symbol. + */ +value?: string +} +/** + * Defines whether or not the channel is private. + */ +channelPrivacy?: { +/** + * Value containing the channel's privacy option. + */ +value?: string +} +} +/** + * Public and editable information related to the session. + */ +public?: { +/** + * Custom property. + */ +[k: string]: { +/** + * Value of the custom property. + */ +value?: string +} +} +/** + * Checkout information related to the session. + */ +checkout?: { +/** + * ID of the session's region. + */ +regionId?: { +/** + * Value of the Region ID. + */ +value?: string +} +} +} +} +/** + * Session information. + */ +export interface CreateEditSessionRequest { +public: Public +} +/** + * Public information. + */ +export interface Public { +/** + * Custom property. + */ +additionalProperties?: { +/** + * Value of the custom property. + */ +value?: string +} +[k: string]: any +} +/** + * Object containing session token and segment token. + */ +export interface CreateEditSessionResponse { +/** + * Token that identifies the user's individual session. + */ +sessionToken?: string +/** + * Token that identifies the user's segment, shared with other users with similar navigation parameters. + */ +segmentToken?: string +} diff --git a/vtex/utils/openapi/vcs.openapi.json b/vtex/utils/openapi/vcs.openapi.json index e8a08bafa..255e5104d 100644 --- a/vtex/utils/openapi/vcs.openapi.json +++ b/vtex/utils/openapi/vcs.openapi.json @@ -39045,6 +39045,206 @@ } } } + }, + "/api/sessions":{ + "post":{ + "tags":[ + "Session" + ], + "summary":"Create new session", + "description":"Creates a new session and returns a session token and a segment token. Also stores `vtex_session` and `vtex_segment` cookies, with the same values returned in the response.\n\r\n\rAll parameters in the body that are not within the public namespace will be ignored. Query string items will automatically be added to the public namespace.\n\r\n\r>⚠️ The Session Manager API uses the `vtex_session` and `vtex_segment` cookies to store the data required to identify the user and the session. These cookies are stored in the user's browser when the session is created and sent automatically in every request to that domain. You will have to reproduce that by sending these cookies as headers in other requests to Session Manager API in order for it to work outside of a browser environment.\r\n\r\n## Permissions\r\n\r\nThis endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3).", + "operationId":"Createnewsession", + "parameters":[ + + ], + "requestBody":{ + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/CreateEditSessionRequest" + }, + "example":{ + "public":{ + "variable1":{ + "value":"value1" + }, + "variable2":{ + "value":"value2" + } + } + } + } + }, + "required":true + }, + "responses":{ + "201":{ + "description":"Created", + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/CreateEditSessionResponse" + }, + "example":{ + "sessionToken":"eyJhbGciOiJFUzI1NiIsImtpZCI6IjM5MEI4MTM1RDUzQ0MwMUY0RjA4N0YwMzA2RjhDODMzNzBDMjY4M0UiLCJ0eXAiOiJqd3QifQ.eyJhY2NvdW50LmlkIjoiYThiMjdmYjQtNjUxNi00Y2MwLTgyYjYtYTVmMmIwMTFlNmUyIiwiaWQiOiIyNmQyY2I2Yy0yMTNlLTQ5MzYtOWUyYS0xZDFlMjk5ZWMzM2IiLCJ2ZXJzaW9uIjoyLCJzdWIiOiJzZXNzaW9uIiwiYWNjb3VudCI6InNlc3Npb24iLCJleHAiOjE2OTM1Nzg5NzYsImlhdCI6MTY5Mjg4Nzc3NiwiaXNzIjoidG9rZW4tZW1pdHRlciIsImp0aSI6IjhiYWU2NzdmLWE0NTAtNGI0OC05YTBkLTViMzAwYjNiY2NkOCJ9.Ak1bn2xEA1A5dVN4qR6RI8vnZpSpLXyVxFCthMoVjmWn0HlP5BqMHEMYApDj8TPPhyxT0hGT0vkmvMQa2Mprrw", + "segmentToken":"eyJjYW1wYWlnbnMiOm51bGwsImNoYW5uZWwiOiIxIiwicHJpY2VUYWJsZXMiOm51bGwsInJlZ2lvbklkIjpudWxsLCJ1dG1fY2FtcGFpZ24iOm51bGwsInV0bV9zb3VyY2UiOm51bGwsInV0bWlfY2FtcGFpZ24iOm51bGwsImN1cnJlbmN5Q29kZSI6IkJSTCIsImN1cnJlbmN5U3ltYm9sIjoiUiQiLCJjb3VudHJ5Q29kZSI6IkJSQSIsImN1bHR1cmVJbmZvIjoiZW4tVVMiLCJjaGFubmVsUHJpdmFjeSI6InB1YmxpYyJ9" + } + } + } + } + }, + "deprecated":false + }, + "get":{ + "tags":[ + "Session" + ], + "summary":"Get session", + "description":"Retrieves information from a previously created sesssion.\n\r\n\r>⚠️ The Session Manager API uses the `vtex_session` and `vtex_segment` cookies to store the data required to identify the user and the session. These cookies are stored in the user's browser when the session is created and sent automatically in every request to that domain. You will have to reproduce that by sending these cookies as headers to Session Manager API in order for it to work outside of a browser environment.\r\n\r\n## Permissions\r\n\r\nThis endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3).", + "operationId":"GetSession", + "parameters":[ + { + "name":"items", + "in":"query", + "description":"Items are the keys of the values you wish to get. They follow the format `namespace1.key1,namespace2.key2`.\n\r\n\rIf you wish to recover the data sent on [Create new session](https://developers.vtex.com/docs/api-reference/session-manager-api#post-/api/sessions), it should be `public.{key}`, replacing `{key}` with the name of the custom property you created. Following the example request presented in [Create new session](https://developers.vtex.com/docs/api-reference/session-manager-api#post-/api/sessions), it would be `public.variable1,public.variable2`.\n\r\n\rIf you want to retrieve all keys from Session Manager, you can use the wildcard operator (`*`) as a value for this query parameter.", + "required":true, + "style":"form", + "explode":true, + "schema":{ + "type":"string", + "example":"*" + } + } + ], + "responses":{ + "200":{ + "description":"OK", + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/GetSessionResponse" + }, + "example":{ + "id":"26d2cb6c-213e-4936-9e2a-1d1e299ec33b", + "namespaces":{ + "account":{ + "id":{ + "value":"a8b27fb4-6516-4cc0-82b6-a5f2b011e6e2", + "keepAlive":true + }, + "accountName":{ + "value":"apiexamples" + } + }, + "store":{ + "channel":{ + "value":"1" + }, + "countryCode":{ + "value":"BRA" + }, + "cultureInfo":{ + "value":"en-US" + }, + "currencyCode":{ + "value":"BRL" + }, + "currencySymbol":{ + "value":"R$" + }, + "channelPrivacy":{ + "value":"public" + } + }, + "public":{ + "variable1":{ + "value":"value1" + }, + "variable2":{ + "value":"value2" + } + }, + "checkout":{ + "regionId":{ + "value":"v2.1BB18CE648B5111D0933734ED83EC783" + } + } + } + } + } + } + } + }, + "security":[ + { + "vtex_session":[ + + ], + "vtex_segment":[ + + ] + } + ], + "deprecated":false + }, + "patch":{ + "tags":[ + "Session" + ], + "summary":"Edit session", + "description":"Edits information from a previously created sesssion.\n\r\n\rThis endpoint works the same way as the [Create new session](https://developers.vtex.com/docs/api-reference/session-manager-api#post-/api/sessions) endpoint, but when the request is sent with a `vtex_session` and the `vtex_segment` cookies in the header, it retrieves the session first and then applies the changes instead of generating a new one.\n\r\n\rOnly keys inside the `public` namespace in the request body are considered, and query parameters are automatically added to the public namespace.\n\r\n\r>⚠️ The Session Manager API uses the `vtex_session` and `vtex_segment` cookies to store the data required to identify the user and the session. These cookies are stored in the user's browser when the session is created and sent automatically in every request to that domain. You will have to reproduce that by sending these cookies as headers to Session Manager API in order for it to work outside of a browser environment.\r\n\r\n## Permissions\r\n\r\nThis endpoint does not require [authentication](https://developers.vtex.com/docs/guides/authentication) or [permissions](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3).", + "operationId":"Editsession", + "parameters":[ + + ], + "requestBody":{ + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/CreateEditSessionRequest" + }, + "example":{ + "public":{ + "variable2":{ + "value":"value2_patched" + }, + "variable3":{ + "value":"value3" + } + } + } + } + }, + "required":true + }, + "responses":{ + "200":{ + "description":"OK", + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/CreateEditSessionResponse" + }, + "example":{ + "sessionToken":"eyJhbGciOiJFUzI1NiIsImtpZCI6IjM5MEI4MTM1RDUzQ0MwMUY0RjA4N0YwMzA2RjhDODMzNzBDMjY4M0UiLCJ0eXAiOiJqd3QifQ.eyJhY2NvdW50LmlkIjoiYThiMjdmYjQtNjUxNi00Y2MwLTgyYjYtYTVmMmIwMTFlNmUyIiwiaWQiOiIyNmQyY2I2Yy0yMTNlLTQ5MzYtOWUyYS0xZDFlMjk5ZWMzM2IiLCJ2ZXJzaW9uIjoyLCJzdWIiOiJzZXNzaW9uIiwiYWNjb3VudCI6InNlc3Npb24iLCJleHAiOjE2OTM1Nzg5NzYsImlhdCI6MTY5Mjg4Nzc3NiwiaXNzIjoidG9rZW4tZW1pdHRlciIsImp0aSI6IjhiYWU2NzdmLWE0NTAtNGI0OC05YTBkLTViMzAwYjNiY2NkOCJ9.Ak1bn2xEA1A5dVN4qR6RI8vnZpSpLXyVxFCthMoVjmWn0HlP5BqMHEMYApDj8TPPhyxT0hGT0vkmvMQa2Mprrw", + "segmentToken":"eyJjYW1wYWlnbnMiOm51bGwsImNoYW5uZWwiOiIxIiwicHJpY2VUYWJsZXMiOm51bGwsInJlZ2lvbklkIjpudWxsLCJ1dG1fY2FtcGFpZ24iOm51bGwsInV0bV9zb3VyY2UiOm51bGwsInV0bWlfY2FtcGFpZ24iOm51bGwsImN1cnJlbmN5Q29kZSI6IkJSTCIsImN1cnJlbmN5U3ltYm9sIjoiUiQiLCJjb3VudHJ5Q29kZSI6IkJSQSIsImN1bHR1cmVJbmZvIjoiZW4tVVMiLCJjaGFubmVsUHJpdmFjeSI6InB1YmxpYyJ9" + } + } + } + } + }, + "security":[ + { + "vtex_session":[ + + ], + "vtex_segment":[ + + ] + } + ], + "deprecated":false + } } }, "components": { @@ -39128,6 +39328,209 @@ } }, "schemas": { + "CreateEditSessionRequest":{ + "title":"CreateEditSessionRequest", + "required":[ + "public" + ], + "type":"object", + "description":"Session information.", + "properties":{ + "public":{ + "title":"Public", + "type":"object", + "description":"Public information.", + "additionalProperties":true, + "properties":{ + "additionalProperties":{ + "type":"object", + "description":"Custom property.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the custom property.", + "example":"value3" + } + } + } + }, + "example":{ + "variable2":{ + "value":"value2" + }, + "variable3":{ + "value":"value3" + } + } + } + }, + "example":{ + "public":{ + "variable2":{ + "value":"value2" + }, + "variable3":{ + "value":"value3" + } + } + } + }, + "CreateEditSessionResponse":{ + "type":"object", + "description":"Object containing session token and segment token.", + "properties":{ + "sessionToken":{ + "type":"string", + "description":"Token that identifies the user's individual session." + }, + "segmentToken":{ + "type":"string", + "description":"Token that identifies the user's segment, shared with other users with similar navigation parameters." + } + } + }, + "GetSessionResponse":{ + "type":"object", + "description":"Session information.", + "properties":{ + "id":{ + "type":"string", + "description":"Session ID." + }, + "namespaces":{ + "type":"object", + "description":"Object with namespaces, each containing a set of information about the session.", + "properties":{ + "account":{ + "type":"object", + "description":"Account information related to the session.", + "properties":{ + "id":{ + "type":"object", + "description":"VTEX account ID.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the VTEX account ID." + }, + "keepAlive":{ + "type":"boolean", + "description":"Determines whether or not the connection should be kept alive." + } + } + }, + "accountName":{ + "type":"object", + "description":"VTEX account name.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the VTEX account name." + } + } + } + } + }, + "store":{ + "type":"object", + "description":"Store information related to the session.", + "properties":{ + "channel":{ + "type":"object", + "description":"[Trade policy](https://help.vtex.com/en/tutorial/how-trade-policies-work--6Xef8PZiFm40kg2STrMkMV) ID.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the [Trade policy](https://help.vtex.com/en/tutorial/how-trade-policies-work--6Xef8PZiFm40kg2STrMkMV) ID." + } + } + }, + "countryCode":{ + "type":"object", + "description":"Country code.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the country code." + } + } + }, + "cultureInfo":{ + "type":"object", + "description":"Locale that provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. Read [this documentation](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-7.0#culture-names-and-identifiers) for more details.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the `cultureInfo` property." + } + } + }, + "currencyCode":{ + "type":"object", + "description":"Currency code.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the currency code." + } + } + }, + "currencySymbol":{ + "type":"object", + "description":"Currency symbol.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the currency symbol." + } + } + }, + "channelPrivacy":{ + "type":"object", + "description":"Defines whether or not the channel is private.", + "properties":{ + "value":{ + "type":"string", + "description":"Value containing the channel's privacy option." + } + } + } + } + }, + "public":{ + "type":"object", + "description":"Public and editable information related to the session.", + "additionalProperties":{ + "type":"object", + "description":"Custom property.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the custom property." + } + } + } + }, + "checkout":{ + "type":"object", + "description":"Checkout information related to the session.", + "properties":{ + "regionId":{ + "type":"object", + "description":"ID of the session's region.", + "properties":{ + "value":{ + "type":"string", + "description":"Value of the Region ID." + } + } + } + } + } + } + } + } + }, "PickupPoint": { "type": "object", "description": "Pickup point information.", diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index c87b84357..78c141d3e 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -1523,3 +1523,64 @@ export interface AdvancedLoaderConfig { } export type Maybe = T | null | undefined; + +export enum DeviceType { + Mobile = "MOBILE", + Tablet = "TABLET", + Desktop = "DESKTOP", +} + +export interface LoginSession { + id: string; + cacheId: string; + deviceType: DeviceType; + city?: Maybe; + lastAccess: string; + browser?: Maybe; + os?: Maybe; + ip?: Maybe; + fullAddress?: Maybe; + firstAccess: string; +} + +export interface LoginSessionsInfo { + currentLoginSessionId?: Maybe; + loginSessions?: Maybe; +} + +export interface Session { + id: string; + namespaces?: { + profile: SessionProfile; + impersonate: SessionImpersonate; + authentication: Record; + public: SessionPublic; + }; +} + +export interface SessionProfile { + id?: { value: string }; + email?: { value: string }; + firstName?: { value: string }; + lastName?: { value: string }; + phone?: { value: string }; + isAuthenticated?: { value: string }; + priceTables?: { value: string }; +} + +export interface SessionImpersonate { + storeUserEmail?: { value: string }; + storeUserId?: { value: string }; +} + +export interface SessionPublic { + orderFormId?: { value: string }; + utm_source?: { value: string }; + utm_medium?: { value: string }; + utm_campaign?: { value: string }; + utm_term?: { value: string }; + utm_content?: { value: string }; + utmi_cp?: { value: string }; + utmi_pc?: { value: string }; + utmi_p?: { value: string }; +}