@decocms/apps 0.28.1 → 0.29.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/package.json +1 -1
- package/vtex/loaders/legacy.ts +11 -0
- package/vtex/utils/vtexId.ts +38 -0
package/package.json
CHANGED
package/vtex/loaders/legacy.ts
CHANGED
|
@@ -622,3 +622,14 @@ export async function legacySuggestions(
|
|
|
622
622
|
|
|
623
623
|
return { searches, products };
|
|
624
624
|
}
|
|
625
|
+
|
|
626
|
+
// ---------------------------------------------------------------------------
|
|
627
|
+
// Short aliases — sites use invoke.vtex.loaders.legacy.productDetailsPage()
|
|
628
|
+
// ---------------------------------------------------------------------------
|
|
629
|
+
|
|
630
|
+
export {
|
|
631
|
+
legacyProductDetailsPage as productDetailsPage,
|
|
632
|
+
legacyProductList as productList,
|
|
633
|
+
legacyProductListingPage as productListingPage,
|
|
634
|
+
legacySuggestions as suggestions,
|
|
635
|
+
};
|
package/vtex/utils/vtexId.ts
CHANGED
|
@@ -97,4 +97,42 @@ export function buildAuthCookieHeader(authCookie: string, account: string): stri
|
|
|
97
97
|
return `${VTEX_AUTH_COOKIE}=${authCookie}; ${VTEX_AUTH_COOKIE}_${account}=${authCookie}`;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
export interface CookiePayload {
|
|
101
|
+
sub?: string;
|
|
102
|
+
account?: string;
|
|
103
|
+
audience?: string;
|
|
104
|
+
sess?: string;
|
|
105
|
+
exp?: number;
|
|
106
|
+
userId?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Parse VTEX auth cookies from request headers.
|
|
111
|
+
*
|
|
112
|
+
* Returns the serialized cookie string (for forwarding) and the decoded
|
|
113
|
+
* JWT payload. Compatible with the legacy deco-cx/apps parseCookie API.
|
|
114
|
+
*/
|
|
115
|
+
export function parseCookie(
|
|
116
|
+
headers: Headers,
|
|
117
|
+
account: string,
|
|
118
|
+
): { cookie: string; payload: CookiePayload | undefined } {
|
|
119
|
+
const cookieHeader = headers.get("cookie") ?? "";
|
|
120
|
+
|
|
121
|
+
const base = extractVtexAuthCookie(cookieHeader);
|
|
122
|
+
const suffixedRe = new RegExp(`(?:^|;\\s*)${VTEX_AUTH_COOKIE}_${account}=([^;]+)`);
|
|
123
|
+
const suffixedMatch = cookieHeader.match(suffixedRe);
|
|
124
|
+
const suffixed = suffixedMatch?.[1] ?? null;
|
|
125
|
+
|
|
126
|
+
const token = base ?? suffixed;
|
|
127
|
+
const payload = token
|
|
128
|
+
? ((decodeJwtPayload(token) as CookiePayload | null) ?? undefined)
|
|
129
|
+
: undefined;
|
|
130
|
+
|
|
131
|
+
const parts: string[] = [];
|
|
132
|
+
if (base) parts.push(`${VTEX_AUTH_COOKIE}=${base}`);
|
|
133
|
+
if (suffixed) parts.push(`${VTEX_AUTH_COOKIE}_${account}=${suffixed}`);
|
|
134
|
+
|
|
135
|
+
return { cookie: parts.join("; "), payload };
|
|
136
|
+
}
|
|
137
|
+
|
|
100
138
|
export { VTEX_AUTH_COOKIE };
|