@wix/astro 1.0.26 → 1.0.27
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/build-browser-runtime/setup.js +69 -1
- package/build-runtime/chunk-B6RICTPP.js +94 -0
- package/build-runtime/context/elevated.js +8 -1
- package/build-runtime/context/nonElevated.js +5 -1
- package/build-runtime/middleware/auth.js +1 -0
- package/package.json +5 -2
- package/src/client-context/utils.ts +2 -0
- package/src/context/elevated.ts +2 -0
- package/src/context/hostProxy.ts +38 -0
- package/src/context/nonElevated.ts +2 -0
- package/src/middleware/auth.ts +1 -0
- package/src/utils/authAsyncLocalStorage.ts +1 -0
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
// src/client-context/setup.ts
|
|
2
2
|
import { wixContext } from "@wix/sdk-context";
|
|
3
3
|
|
|
4
|
+
// ../../node_modules/@wix/headless-site/dist/esm/headers/common-config-header.js
|
|
5
|
+
var COMMON_CONFIG_HEADER_NAME = "commonConfig";
|
|
6
|
+
var IGNORE_KEYS = /* @__PURE__ */ new Set(["consentPolicy", "consentPolicyHeader"]);
|
|
7
|
+
var MAP_KEYS = /* @__PURE__ */ new Map([["bsi", "BSI"]]);
|
|
8
|
+
var getCommonConfigValues = () => {
|
|
9
|
+
const {
|
|
10
|
+
commonConfig
|
|
11
|
+
} = globalThis;
|
|
12
|
+
if (!commonConfig) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const entries = Object.entries(commonConfig).reduce((res, _ref) => {
|
|
16
|
+
let [key, value] = _ref;
|
|
17
|
+
if (typeof value !== "undefined" && // This can happen if the value was explicitly set to undefined
|
|
18
|
+
typeof value !== "function" && !IGNORE_KEYS.has(key)) {
|
|
19
|
+
res.push([MAP_KEYS.get(key) ?? key, value]);
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
}, []);
|
|
23
|
+
return entries.length > 0 ? Object.fromEntries(entries) : null;
|
|
24
|
+
};
|
|
25
|
+
var getCommonConfigHeader = () => {
|
|
26
|
+
const commonConfigValues = getCommonConfigValues();
|
|
27
|
+
const value = commonConfigValues ? JSON.stringify(commonConfigValues) : "";
|
|
28
|
+
return {
|
|
29
|
+
[COMMON_CONFIG_HEADER_NAME]: encodeURIComponent(value)
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// ../../node_modules/@wix/headless-site/dist/esm/headers/index.js
|
|
34
|
+
var getPassThroughHeaders = () => {
|
|
35
|
+
const headers = [getCommonConfigHeader()];
|
|
36
|
+
return headers.reduce((res, header) => {
|
|
37
|
+
const entries = Object.entries(header).filter((_ref) => {
|
|
38
|
+
let [_, value] = _ref;
|
|
39
|
+
return !!value;
|
|
40
|
+
});
|
|
41
|
+
res = {
|
|
42
|
+
...res,
|
|
43
|
+
...Object.fromEntries(entries)
|
|
44
|
+
};
|
|
45
|
+
return res;
|
|
46
|
+
}, {});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ../../node_modules/@wix/headless-site/dist/esm/host-module.js
|
|
50
|
+
var createHostModule = () => {
|
|
51
|
+
return {
|
|
52
|
+
__type: "host",
|
|
53
|
+
create: () => {
|
|
54
|
+
return {};
|
|
55
|
+
},
|
|
56
|
+
host: () => {
|
|
57
|
+
return {
|
|
58
|
+
essentials: {
|
|
59
|
+
get passThroughHeaders() {
|
|
60
|
+
return getPassThroughHeaders();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// ../../node_modules/@wix/headless-site/dist/esm/index.js
|
|
69
|
+
var headlessSite = createHostModule();
|
|
70
|
+
|
|
4
71
|
// src/client-context/utils.ts
|
|
5
72
|
import { createClient } from "@wix/sdk";
|
|
6
73
|
import { SiteSessionAuth } from "@wix/sdk/auth/site-session";
|
|
@@ -9,7 +76,8 @@ function getSessionClient(options) {
|
|
|
9
76
|
auth: SiteSessionAuth({
|
|
10
77
|
tokens: getCookieAsJson("wixSession")?.tokens,
|
|
11
78
|
...options
|
|
12
|
-
})
|
|
79
|
+
}),
|
|
80
|
+
host: headlessSite.host()
|
|
13
81
|
});
|
|
14
82
|
}
|
|
15
83
|
function getCookieAsJson(name) {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authAsyncLocalStorage
|
|
3
|
+
} from "./chunk-NVTQFGTR.js";
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/@wix/headless-node/dist/esm/headers/common-config-header.js
|
|
6
|
+
var COMMON_CONFIG_HEADER_NAME = "commonConfig";
|
|
7
|
+
var BSI_COOKIE_NAME = "bSession";
|
|
8
|
+
var getCommonConfigHeader = (req) => {
|
|
9
|
+
let value = req.headers.get(COMMON_CONFIG_HEADER_NAME);
|
|
10
|
+
if (!value) {
|
|
11
|
+
const cookies = req.headers.get("cookie");
|
|
12
|
+
const bsiCookie = cookies == null ? void 0 : cookies.split(";").find((keyValue) => keyValue.trim().startsWith(`${BSI_COOKIE_NAME}=`));
|
|
13
|
+
value = bsiCookie ? encodeURIComponent(JSON.stringify({
|
|
14
|
+
BSI: bsiCookie.split("=")[1]
|
|
15
|
+
})) : "";
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
[COMMON_CONFIG_HEADER_NAME]: value
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/@wix/headless-node/dist/esm/headers/index.js
|
|
23
|
+
var getPassThroughHeaders = (req) => {
|
|
24
|
+
if (!req) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
const headers = [getCommonConfigHeader(req)];
|
|
28
|
+
return headers.reduce((res, header) => {
|
|
29
|
+
const entries = Object.entries(header).filter((_ref) => {
|
|
30
|
+
let [_, value] = _ref;
|
|
31
|
+
return !!value;
|
|
32
|
+
});
|
|
33
|
+
res = {
|
|
34
|
+
...res,
|
|
35
|
+
...Object.fromEntries(entries)
|
|
36
|
+
};
|
|
37
|
+
return res;
|
|
38
|
+
}, {});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// ../../node_modules/@wix/headless-node/dist/esm/host-module.js
|
|
42
|
+
var createHostModule = () => {
|
|
43
|
+
return {
|
|
44
|
+
__type: "host",
|
|
45
|
+
create: () => {
|
|
46
|
+
return {};
|
|
47
|
+
},
|
|
48
|
+
host: function(_temp) {
|
|
49
|
+
let {
|
|
50
|
+
req
|
|
51
|
+
} = _temp === void 0 ? {} : _temp;
|
|
52
|
+
const passThroughHeaders = getPassThroughHeaders(req);
|
|
53
|
+
return {
|
|
54
|
+
essentials: {
|
|
55
|
+
passThroughHeaders
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// ../../node_modules/@wix/headless-node/dist/esm/index.js
|
|
63
|
+
var headlessNode = createHostModule();
|
|
64
|
+
|
|
65
|
+
// src/context/hostProxy.ts
|
|
66
|
+
var createHostWithCurrentRequest = () => {
|
|
67
|
+
const store = authAsyncLocalStorage.getStore();
|
|
68
|
+
return headlessNode.host({ req: store?.request });
|
|
69
|
+
};
|
|
70
|
+
var createHostProxy = () => {
|
|
71
|
+
return new Proxy(
|
|
72
|
+
{},
|
|
73
|
+
{
|
|
74
|
+
get(target, prop) {
|
|
75
|
+
const host = createHostWithCurrentRequest();
|
|
76
|
+
const value = host[prop];
|
|
77
|
+
if (typeof value !== "function") {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
return function(...args) {
|
|
81
|
+
const anotherHost = createHostWithCurrentRequest();
|
|
82
|
+
return anotherHost[prop].apply(
|
|
83
|
+
anotherHost,
|
|
84
|
+
args
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
createHostProxy
|
|
94
|
+
};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHostProxy
|
|
3
|
+
} from "../chunk-B6RICTPP.js";
|
|
4
|
+
import "../chunk-NVTQFGTR.js";
|
|
5
|
+
import "../chunk-MLKGABMK.js";
|
|
6
|
+
|
|
1
7
|
// src/context/elevated.ts
|
|
2
8
|
import { AppStrategy, createClient } from "@wix/sdk";
|
|
3
9
|
import { WIX_CLIENT_ID } from "astro:env/client";
|
|
@@ -12,6 +18,7 @@ var elevatedContextClient = createClient({
|
|
|
12
18
|
appSecret: WIX_CLIENT_SECRET,
|
|
13
19
|
instanceId: WIX_CLIENT_INSTANCE_ID,
|
|
14
20
|
publicKey: WIX_CLIENT_PUBLIC_KEY
|
|
15
|
-
})
|
|
21
|
+
}),
|
|
22
|
+
host: createHostProxy()
|
|
16
23
|
});
|
|
17
24
|
elevatedContextClient.enableContext("global", { elevated: true });
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHostProxy
|
|
3
|
+
} from "../chunk-B6RICTPP.js";
|
|
1
4
|
import {
|
|
2
5
|
authAsyncLocalStorage
|
|
3
6
|
} from "../chunk-NVTQFGTR.js";
|
|
@@ -28,6 +31,7 @@ var authProxy = new Proxy(
|
|
|
28
31
|
}
|
|
29
32
|
);
|
|
30
33
|
var contextClient = createClient({
|
|
31
|
-
auth: authProxy
|
|
34
|
+
auth: authProxy,
|
|
35
|
+
host: createHostProxy()
|
|
32
36
|
});
|
|
33
37
|
contextClient.enableContext("global");
|
|
@@ -51,6 +51,7 @@ var onRequest = async (context, next) => {
|
|
|
51
51
|
const existingTokens = getExistingTokens(context);
|
|
52
52
|
const usedTokens = existingTokens ?? await generateVisitorTokens();
|
|
53
53
|
const store = {
|
|
54
|
+
request: context.request,
|
|
54
55
|
sessionTokens: usedTokens
|
|
55
56
|
};
|
|
56
57
|
const response = await authAsyncLocalStorage.run(store, async () => {
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/astro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@wix/dashboard": "^1.3.35",
|
|
6
6
|
"@wix/essentials": "^0.1.23",
|
|
7
|
+
"@wix/headless-node": "^1.4.0",
|
|
8
|
+
"@wix/headless-site": "^1.0.0",
|
|
7
9
|
"@wix/headless-site-assets": "^1.0.2",
|
|
8
10
|
"@wix/sdk": "^1.15.23",
|
|
9
11
|
"@wix/sdk-context": "^0.0.1",
|
|
12
|
+
"@wix/sdk-types": "^1.13.32",
|
|
10
13
|
"astro": "^5.10.1",
|
|
11
14
|
"chalk": "^5.4.1",
|
|
12
15
|
"chokidar": "^3.6.0",
|
|
@@ -46,5 +49,5 @@
|
|
|
46
49
|
"artifactId": "wix-astro"
|
|
47
50
|
}
|
|
48
51
|
},
|
|
49
|
-
"falconPackageHash": "
|
|
52
|
+
"falconPackageHash": "d63557661fd785b25ed8a39da82d8812517f4690bfd1c928ef0454ae"
|
|
50
53
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Tokens, WixClient } from '@wix/sdk';
|
|
2
|
+
import { headlessSite } from '@wix/headless-site';
|
|
2
3
|
import { createClient } from '@wix/sdk';
|
|
3
4
|
import { SiteSessionAuth } from '@wix/sdk/auth/site-session';
|
|
4
5
|
|
|
@@ -8,6 +9,7 @@ export function getSessionClient(options: { clientId: string }): WixClient {
|
|
|
8
9
|
tokens: getCookieAsJson('wixSession')?.tokens,
|
|
9
10
|
...options,
|
|
10
11
|
}),
|
|
12
|
+
host: headlessSite.host(),
|
|
11
13
|
});
|
|
12
14
|
}
|
|
13
15
|
|
package/src/context/elevated.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
WIX_CLIENT_PUBLIC_KEY,
|
|
6
6
|
WIX_CLIENT_SECRET,
|
|
7
7
|
} from 'astro:env/server';
|
|
8
|
+
import { createHostProxy } from './hostProxy.js';
|
|
8
9
|
|
|
9
10
|
const elevatedContextClient = createClient({
|
|
10
11
|
auth: AppStrategy({
|
|
@@ -13,6 +14,7 @@ const elevatedContextClient = createClient({
|
|
|
13
14
|
instanceId: WIX_CLIENT_INSTANCE_ID,
|
|
14
15
|
publicKey: WIX_CLIENT_PUBLIC_KEY,
|
|
15
16
|
}),
|
|
17
|
+
host: createHostProxy(),
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
elevatedContextClient.enableContext('global', { elevated: true });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Host } from '@wix/sdk-types';
|
|
2
|
+
import { headlessNode } from '@wix/headless-node';
|
|
3
|
+
import { authAsyncLocalStorage } from '../utils/authAsyncLocalStorage.js';
|
|
4
|
+
|
|
5
|
+
const createHostWithCurrentRequest = () => {
|
|
6
|
+
const store = authAsyncLocalStorage.getStore();
|
|
7
|
+
|
|
8
|
+
return headlessNode.host({ req: store?.request });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const createHostProxy = (): Host => {
|
|
12
|
+
return new Proxy<Host>(
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
get(target, prop: keyof Host) {
|
|
16
|
+
// host might be created before async local storage was set
|
|
17
|
+
const host = createHostWithCurrentRequest();
|
|
18
|
+
const value = host[prop];
|
|
19
|
+
|
|
20
|
+
if (typeof value !== 'function') {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// for functions, create the host again when the function runs,
|
|
25
|
+
// so that the middleware has a chance to set the async local storage
|
|
26
|
+
// before we access the current request
|
|
27
|
+
return function (...args: unknown[]) {
|
|
28
|
+
const anotherHost = createHostWithCurrentRequest();
|
|
29
|
+
|
|
30
|
+
return (anotherHost[prop] as (...args: unknown[]) => unknown).apply(
|
|
31
|
+
anotherHost,
|
|
32
|
+
args
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -2,6 +2,7 @@ import type { IOAuthStrategy } from '@wix/sdk';
|
|
|
2
2
|
import { createClient, OAuthStrategy } from '@wix/sdk';
|
|
3
3
|
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
4
4
|
import { authAsyncLocalStorage } from '../utils/authAsyncLocalStorage.js';
|
|
5
|
+
import { createHostProxy } from './hostProxy.js';
|
|
5
6
|
|
|
6
7
|
const authProxy = new Proxy(
|
|
7
8
|
{},
|
|
@@ -35,6 +36,7 @@ const authProxy = new Proxy(
|
|
|
35
36
|
|
|
36
37
|
const contextClient = createClient({
|
|
37
38
|
auth: authProxy,
|
|
39
|
+
host: createHostProxy(),
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
contextClient.enableContext('global');
|
package/src/middleware/auth.ts
CHANGED