@wix/astro 2.22.0 → 2.23.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.
@@ -0,0 +1,26 @@
1
+ // src/utils/saveSessionTokensToCookie.ts
2
+ import { WIX_CLIENT_ID } from "astro:env/client";
3
+
4
+ // src/utils/sessionCookie.ts
5
+ var SESSION_COOKIE_NAME = "wixSession";
6
+ var SESSION_COOKIE_OPTIONS = {
7
+ path: "/",
8
+ secure: true,
9
+ ...import.meta.env.DEV && {
10
+ maxAge: 10800,
11
+ sameSite: "none"
12
+ }
13
+ };
14
+
15
+ // src/utils/saveSessionTokensToCookie.ts
16
+ function saveSessionTokensToCookie(context, tokens) {
17
+ context.cookies.set(
18
+ SESSION_COOKIE_NAME,
19
+ { clientId: WIX_CLIENT_ID, tokens },
20
+ SESSION_COOKIE_OPTIONS
21
+ );
22
+ }
23
+
24
+ export {
25
+ saveSessionTokensToCookie
26
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  saveSessionTokensToCookie
3
- } from "../chunk-HPW4ZAEJ.js";
3
+ } from "../chunk-DZHZMKUF.js";
4
4
  import {
5
5
  contextualClient,
6
6
  elevatedContextualClient
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  saveSessionTokensToCookie
3
- } from "../chunk-HPW4ZAEJ.js";
3
+ } from "../chunk-DZHZMKUF.js";
4
4
  import {
5
5
  object,
6
6
  string
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  saveSessionTokensToCookie
3
- } from "../chunk-HPW4ZAEJ.js";
3
+ } from "../chunk-DZHZMKUF.js";
4
4
  import {
5
5
  returnToQueryParamName
6
6
  } from "../chunk-24J7STEA.js";
@@ -3,17 +3,48 @@ import { resolveContext } from "@wix/sdk-runtime/context";
3
3
 
4
4
  // src/runtime/client/utils.ts
5
5
  import { headlessSite } from "@wix/headless-site";
6
- import { createClient } from "@wix/sdk";
7
- import { SiteSessionAuth } from "@wix/sdk/auth/site-session";
6
+ import { createClient, EMPTY_TOKENS, OAuthStrategy } from "@wix/sdk";
7
+
8
+ // src/utils/sessionCookie.ts
9
+ var SESSION_COOKIE_NAME = "wixSession";
10
+ var SESSION_COOKIE_OPTIONS = {
11
+ path: "/",
12
+ secure: true,
13
+ ...import.meta.env.DEV && {
14
+ maxAge: 10800,
15
+ sameSite: "none"
16
+ }
17
+ };
18
+
19
+ // src/runtime/client/utils.ts
8
20
  function getSessionClient(options) {
21
+ const cookieStorage = {
22
+ getTokens: () => getCookieAsJson(SESSION_COOKIE_NAME)?.tokens ?? EMPTY_TOKENS,
23
+ setTokens: (tokens) => {
24
+ document.cookie = buildSessionCookieString(options.clientId, tokens);
25
+ }
26
+ };
9
27
  return createClient({
10
- auth: SiteSessionAuth({
11
- tokens: getCookieAsJson("wixSession")?.tokens,
28
+ auth: OAuthStrategy({
29
+ tokenStorage: cookieStorage,
12
30
  ...options
13
31
  }),
14
32
  host: headlessSite.host({})
15
33
  });
16
34
  }
35
+ function buildSessionCookieString(clientId, tokens) {
36
+ const cookieValue = encodeURIComponent(
37
+ JSON.stringify({ clientId, tokens })
38
+ );
39
+ let cookie = `${SESSION_COOKIE_NAME}=${cookieValue}; path=${SESSION_COOKIE_OPTIONS.path}; ${SESSION_COOKIE_OPTIONS.secure ? "secure;" : ""}`;
40
+ if (SESSION_COOKIE_OPTIONS.sameSite) {
41
+ cookie += ` samesite=${SESSION_COOKIE_OPTIONS.sameSite};`;
42
+ }
43
+ if (SESSION_COOKIE_OPTIONS.maxAge != null) {
44
+ cookie += ` max-age=${SESSION_COOKIE_OPTIONS.maxAge}`;
45
+ }
46
+ return cookie;
47
+ }
17
48
  function getCookieAsJson(name) {
18
49
  const cookies = document.cookie.split("; ");
19
50
  const cookie = cookies.find((row) => row.startsWith(`${name}=`));
@@ -35,6 +66,9 @@ function isCookieValue(value) {
35
66
  if (value == null || typeof value !== "object") {
36
67
  return false;
37
68
  }
69
+ if (!("clientId" in value) || typeof value.clientId !== "string") {
70
+ return false;
71
+ }
38
72
  if (!("tokens" in value)) {
39
73
  return false;
40
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/astro",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "dependencies": {
5
5
  "@wix/auth-management": "^1.0.71",
6
6
  "@wix/dashboard": "^1.3.40",
@@ -9,10 +9,10 @@
9
9
  "@wix/headless-node": "^1.28.0",
10
10
  "@wix/headless-site": "^1.28.0",
11
11
  "@wix/headless-site-assets": "^1.0.9",
12
- "@wix/sdk": "^1.20.0",
12
+ "@wix/sdk": "^1.21.2",
13
13
  "@wix/sdk-runtime": "^1.0.0",
14
- "@wix/sdk-types": "^1.17.0",
15
- "@wix/site": "^1.37.0"
14
+ "@wix/sdk-types": "^1.17.1",
15
+ "@wix/site": "^1.39.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@wix/astro-auth": "0.0.0",
@@ -72,5 +72,5 @@
72
72
  ]
73
73
  }
74
74
  },
75
- "falconPackageHash": "b3edababb18b3ee139ee50bc046d92810bf0a5e065efbf7927c36758"
75
+ "falconPackageHash": "ca13cc4226c2bea6883412b853befce37e7d41124eaa0a3bb369b47b"
76
76
  }
@@ -1,23 +0,0 @@
1
- // src/utils/saveSessionTokensToCookie.ts
2
- import { WIX_CLIENT_ID } from "astro:env/client";
3
- function saveSessionTokensToCookie(context, tokens) {
4
- const cookieOptions = {
5
- path: "/",
6
- secure: true
7
- };
8
- if (import.meta.env.DEV) {
9
- cookieOptions.sameSite = "none";
10
- cookieOptions.maxAge = 10800;
11
- }
12
- context.cookies.set("wixSession", sessionCookieJson(tokens), cookieOptions);
13
- }
14
- function sessionCookieJson(tokens) {
15
- return {
16
- clientId: WIX_CLIENT_ID,
17
- tokens
18
- };
19
- }
20
-
21
- export {
22
- saveSessionTokensToCookie
23
- };