@wix/astro 1.0.34 → 1.0.36
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/index.d.ts +9 -0
- package/build/index.js +17176 -0
- package/build/index.js.map +1 -0
- package/build-browser-runtime/setup.d.ts +5 -0
- package/build-browser-runtime/setup.js +993 -0
- package/build-runtime/chunk-EK7YZVWJ.js +353 -0
- package/build-runtime/chunk-HPW4ZAEJ.js +23 -0
- package/build-runtime/chunk-JODQ44LE.js +1079 -0
- package/build-runtime/chunk-NKFV7KCT.js +831 -0
- package/build-runtime/chunk-NVTQFGTR.js +7 -0
- package/build-runtime/chunk-PSHIUVP2.js +131 -0
- package/build-runtime/chunk-Q3KPY4P2.js +3104 -0
- package/build-runtime/chunk-QRPWKJ4C.js +41 -0
- package/build-runtime/chunk-UZPSWWI5.js +13 -0
- package/build-runtime/chunk-W73LN534.js +24 -0
- package/build-runtime/chunk-YX6EVX5Q.js +11 -0
- package/build-runtime/context/elevated.d.ts +2 -0
- package/build-runtime/context/elevated.js +25 -0
- package/build-runtime/context/nonElevated.d.ts +2 -0
- package/build-runtime/context/nonElevated.js +38 -0
- package/build-runtime/context/setupServicePlugin.d.ts +5 -0
- package/build-runtime/context/setupServicePlugin.js +16 -0
- package/build-runtime/context/setupWebhook.d.ts +5 -0
- package/build-runtime/context/setupWebhook.js +16 -0
- package/build-runtime/middleware/auth.d.ts +5 -0
- package/build-runtime/middleware/auth.js +74 -0
- package/build-runtime/middleware/html-embeds.d.ts +5 -0
- package/build-runtime/middleware/html-embeds.js +166 -0
- package/build-runtime/routes/auth/callback.d.ts +5 -0
- package/build-runtime/routes/auth/callback.js +52 -0
- package/build-runtime/routes/auth/login.d.ts +5 -0
- package/build-runtime/routes/auth/login.js +45 -0
- package/build-runtime/routes/auth/logout-callback.d.ts +5 -0
- package/build-runtime/routes/auth/logout-callback.js +23 -0
- package/build-runtime/routes/auth/logout.d.ts +5 -0
- package/build-runtime/routes/auth/logout.js +32 -0
- package/build-runtime/routes/paylink/checkout.d.ts +5 -0
- package/build-runtime/routes/paylink/checkout.js +35 -0
- package/build-runtime/routes/paylink/paylink.d.ts +5 -0
- package/build-runtime/routes/paylink/paylink.js +34 -0
- package/build-runtime/routes/robots/robots.d.ts +5 -0
- package/build-runtime/routes/robots/robots.js +44 -0
- package/build-runtime/routes/servicePluginsDevRoute.d.ts +5 -0
- package/build-runtime/routes/servicePluginsDevRoute.js +13 -0
- package/build-runtime/routes/webhooksDevRoute.d.ts +5 -0
- package/build-runtime/routes/webhooksDevRoute.js +13 -0
- package/build-runtime/routes/wix-apis/api.d.ts +5 -0
- package/build-runtime/routes/wix-apis/api.js +34 -0
- package/package.json +6 -7
- package/src/client-context/utils.ts +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
__esm,
|
|
37
|
+
__commonJS,
|
|
38
|
+
__export,
|
|
39
|
+
__toESM,
|
|
40
|
+
__toCommonJS
|
|
41
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var oAuthStateCookieName = "oAuthState";
|
|
3
|
+
var returnToQueryParamName = "returnTo";
|
|
4
|
+
|
|
5
|
+
// src/utils/contextualAuth.ts
|
|
6
|
+
import { auth as originalAuth } from "@wix/essentials";
|
|
7
|
+
var auth = originalAuth.getContextualAuth();
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
oAuthStateCookieName,
|
|
11
|
+
returnToQueryParamName,
|
|
12
|
+
auth
|
|
13
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/context/utils.ts
|
|
2
|
+
import { AppStrategy, createClient } from "@wix/sdk";
|
|
3
|
+
import { WIX_CLIENT_ID } from "astro:env/client";
|
|
4
|
+
import { WIX_CLIENT_PUBLIC_KEY, WIX_CLIENT_SECRET } from "astro:env/server";
|
|
5
|
+
async function setupClient(fn) {
|
|
6
|
+
const client = createClient({
|
|
7
|
+
auth: AppStrategy({
|
|
8
|
+
appId: WIX_CLIENT_ID,
|
|
9
|
+
appSecret: WIX_CLIENT_SECRET,
|
|
10
|
+
publicKey: WIX_CLIENT_PUBLIC_KEY
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
const olderClient = globalThis.__wix_context__.client;
|
|
14
|
+
client.enableContext("global");
|
|
15
|
+
await fn();
|
|
16
|
+
if (olderClient) {
|
|
17
|
+
olderClient.enableContext("global");
|
|
18
|
+
}
|
|
19
|
+
return client;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
setupClient
|
|
24
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/utils/normalizeWixRedirectUrl.ts
|
|
2
|
+
function normalizeWixRedirectUrl({
|
|
3
|
+
wixRedirectUrl
|
|
4
|
+
}) {
|
|
5
|
+
const normalizedWixRedirectUrl = wixRedirectUrl.endsWith("/") ? wixRedirectUrl : `${wixRedirectUrl}/`;
|
|
6
|
+
return normalizedWixRedirectUrl;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
normalizeWixRedirectUrl
|
|
11
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHostProxy
|
|
3
|
+
} from "../chunk-NKFV7KCT.js";
|
|
4
|
+
import "../chunk-NVTQFGTR.js";
|
|
5
|
+
import "../chunk-PSHIUVP2.js";
|
|
6
|
+
import "../chunk-QRPWKJ4C.js";
|
|
7
|
+
|
|
8
|
+
// src/context/elevated.ts
|
|
9
|
+
import { AppStrategy, createClient } from "@wix/sdk";
|
|
10
|
+
import { WIX_CLIENT_ID } from "astro:env/client";
|
|
11
|
+
import {
|
|
12
|
+
WIX_CLIENT_INSTANCE_ID,
|
|
13
|
+
WIX_CLIENT_PUBLIC_KEY,
|
|
14
|
+
WIX_CLIENT_SECRET
|
|
15
|
+
} from "astro:env/server";
|
|
16
|
+
var elevatedContextClient = createClient({
|
|
17
|
+
auth: AppStrategy({
|
|
18
|
+
appId: WIX_CLIENT_ID,
|
|
19
|
+
appSecret: WIX_CLIENT_SECRET,
|
|
20
|
+
instanceId: WIX_CLIENT_INSTANCE_ID,
|
|
21
|
+
publicKey: WIX_CLIENT_PUBLIC_KEY
|
|
22
|
+
}),
|
|
23
|
+
host: createHostProxy()
|
|
24
|
+
});
|
|
25
|
+
elevatedContextClient.enableContext("global", { elevated: true });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHostProxy
|
|
3
|
+
} from "../chunk-NKFV7KCT.js";
|
|
4
|
+
import {
|
|
5
|
+
authAsyncLocalStorage
|
|
6
|
+
} from "../chunk-NVTQFGTR.js";
|
|
7
|
+
import "../chunk-PSHIUVP2.js";
|
|
8
|
+
import "../chunk-QRPWKJ4C.js";
|
|
9
|
+
|
|
10
|
+
// src/context/nonElevated.ts
|
|
11
|
+
import { createClient, OAuthStrategy } from "@wix/sdk";
|
|
12
|
+
import { WIX_CLIENT_ID } from "astro:env/client";
|
|
13
|
+
var authProxy = new Proxy(
|
|
14
|
+
{},
|
|
15
|
+
{
|
|
16
|
+
get(target, prop) {
|
|
17
|
+
const auth = OAuthStrategy({
|
|
18
|
+
clientId: WIX_CLIENT_ID
|
|
19
|
+
});
|
|
20
|
+
const value = auth[prop];
|
|
21
|
+
if (typeof value !== "function") {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return function(...args) {
|
|
25
|
+
const store = authAsyncLocalStorage.getStore();
|
|
26
|
+
if (store?.sessionTokens) {
|
|
27
|
+
auth.setTokens(store.sessionTokens);
|
|
28
|
+
}
|
|
29
|
+
return value.apply(auth, args);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
var contextClient = createClient({
|
|
35
|
+
auth: authProxy,
|
|
36
|
+
host: createHostProxy()
|
|
37
|
+
});
|
|
38
|
+
contextClient.enableContext("global");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setupClient
|
|
3
|
+
} from "../chunk-W73LN534.js";
|
|
4
|
+
import "../chunk-QRPWKJ4C.js";
|
|
5
|
+
|
|
6
|
+
// src/context/setupServicePlugin.ts
|
|
7
|
+
async function setupServicePlugin(fn) {
|
|
8
|
+
const client = await setupClient(fn);
|
|
9
|
+
return async function(context) {
|
|
10
|
+
await client.servicePlugins.processRequest(context.request);
|
|
11
|
+
return new Response("OK");
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
setupServicePlugin
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setupClient
|
|
3
|
+
} from "../chunk-W73LN534.js";
|
|
4
|
+
import "../chunk-QRPWKJ4C.js";
|
|
5
|
+
|
|
6
|
+
// src/context/setupWebhook.ts
|
|
7
|
+
async function setupWebhook(fn) {
|
|
8
|
+
const client = await setupClient(fn);
|
|
9
|
+
return async function(context) {
|
|
10
|
+
await client.webhooks.processRequest(context.request);
|
|
11
|
+
return new Response("OK");
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
setupWebhook
|
|
16
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
saveSessionTokensToCookie
|
|
3
|
+
} from "../chunk-HPW4ZAEJ.js";
|
|
4
|
+
import {
|
|
5
|
+
authAsyncLocalStorage
|
|
6
|
+
} from "../chunk-NVTQFGTR.js";
|
|
7
|
+
import "../chunk-QRPWKJ4C.js";
|
|
8
|
+
|
|
9
|
+
// src/utils/generateVisitorTokens.ts
|
|
10
|
+
import { OAuthStrategy } from "@wix/sdk";
|
|
11
|
+
import { WIX_CLIENT_ID } from "astro:env/client";
|
|
12
|
+
var auth = OAuthStrategy({
|
|
13
|
+
clientId: WIX_CLIENT_ID
|
|
14
|
+
});
|
|
15
|
+
async function generateVisitorTokens() {
|
|
16
|
+
return auth.generateVisitorTokens();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/utils/getSessionTokensFromCookie.ts
|
|
20
|
+
import { TokenRole } from "@wix/sdk";
|
|
21
|
+
import { z } from "astro/zod";
|
|
22
|
+
import { WIX_CLIENT_ID as WIX_CLIENT_ID2 } from "astro:env/client";
|
|
23
|
+
var tokensSchema = z.object({
|
|
24
|
+
clientId: z.string(),
|
|
25
|
+
tokens: z.object({
|
|
26
|
+
accessToken: z.object({
|
|
27
|
+
expiresAt: z.number(),
|
|
28
|
+
value: z.string()
|
|
29
|
+
}),
|
|
30
|
+
refreshToken: z.object({
|
|
31
|
+
role: z.nativeEnum(TokenRole),
|
|
32
|
+
value: z.string()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
function getSessionTokensFromCookie(context) {
|
|
37
|
+
if (!context.isPrerendered) {
|
|
38
|
+
const rawCookie = context.cookies.get("wixSession")?.json();
|
|
39
|
+
if (rawCookie != null) {
|
|
40
|
+
const tokensParseResult = tokensSchema.safeParse(rawCookie);
|
|
41
|
+
if (tokensParseResult.success && tokensParseResult.data.clientId === WIX_CLIENT_ID2) {
|
|
42
|
+
return tokensParseResult.data.tokens;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/middleware/auth.ts
|
|
50
|
+
var onRequest = async (context, next) => {
|
|
51
|
+
const existingTokens = getExistingTokens(context);
|
|
52
|
+
const usedTokens = existingTokens ?? await generateVisitorTokens();
|
|
53
|
+
const store = {
|
|
54
|
+
request: context.request,
|
|
55
|
+
sessionTokens: usedTokens
|
|
56
|
+
};
|
|
57
|
+
const response = await authAsyncLocalStorage.run(store, async () => {
|
|
58
|
+
return next();
|
|
59
|
+
});
|
|
60
|
+
if (!context.isPrerendered && existingTokens !== usedTokens) {
|
|
61
|
+
saveSessionTokensToCookie(context, usedTokens);
|
|
62
|
+
}
|
|
63
|
+
return response;
|
|
64
|
+
};
|
|
65
|
+
function getExistingTokens(context) {
|
|
66
|
+
const existingTokens = getSessionTokensFromCookie(context);
|
|
67
|
+
if (existingTokens && existingTokens.accessToken.expiresAt + 600 > Date.now() / 1e3) {
|
|
68
|
+
return existingTokens;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
onRequest
|
|
74
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRESTModule,
|
|
3
|
+
renameKeysFromRESTResponseToSDKResponse,
|
|
4
|
+
renameKeysFromSDKRequestToRESTRequest,
|
|
5
|
+
resolveUrl,
|
|
6
|
+
toURLSearchParams,
|
|
7
|
+
transformError
|
|
8
|
+
} from "../chunk-EK7YZVWJ.js";
|
|
9
|
+
import "../chunk-PSHIUVP2.js";
|
|
10
|
+
import {
|
|
11
|
+
__export
|
|
12
|
+
} from "../chunk-QRPWKJ4C.js";
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/@wix/auto_sdk_headless-site-assets_scripts/build/es/index.mjs
|
|
15
|
+
var es_exports = {};
|
|
16
|
+
__export(es_exports, {
|
|
17
|
+
PositionOnPage: () => PositionOnPage,
|
|
18
|
+
listSiteScripts: () => listSiteScripts4
|
|
19
|
+
});
|
|
20
|
+
function resolveWixAssetsScriptsV1SiteScriptsServiceUrl(opts) {
|
|
21
|
+
const domainToMappings = {
|
|
22
|
+
"bo._base_domain_": [
|
|
23
|
+
{
|
|
24
|
+
srcPath: "/_api/site-scripts",
|
|
25
|
+
destPath: ""
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"wixbo.ai": [
|
|
29
|
+
{
|
|
30
|
+
srcPath: "/_api/site-scripts",
|
|
31
|
+
destPath: ""
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"wix-bo.com": [
|
|
35
|
+
{
|
|
36
|
+
srcPath: "/_api/site-scripts",
|
|
37
|
+
destPath: ""
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"www.wixapis.com": [
|
|
41
|
+
{
|
|
42
|
+
srcPath: "/assets/scripts/v1/site-scripts",
|
|
43
|
+
destPath: "/v1/site-scripts"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
return resolveUrl(Object.assign(opts, { domainToMappings }));
|
|
48
|
+
}
|
|
49
|
+
var PACKAGE_NAME = "@wix/auto_sdk_headless-site-assets_scripts";
|
|
50
|
+
function listSiteScripts(payload) {
|
|
51
|
+
function __listSiteScripts({ host }) {
|
|
52
|
+
const metadata = {
|
|
53
|
+
entityFqdn: "wix.assets.v1.site_script",
|
|
54
|
+
method: "GET",
|
|
55
|
+
methodFqn: "wix.assets.scripts.v1.SiteScriptsService.ListSiteScripts",
|
|
56
|
+
packageName: PACKAGE_NAME,
|
|
57
|
+
url: resolveWixAssetsScriptsV1SiteScriptsServiceUrl({
|
|
58
|
+
protoPath: "/v1/site-scripts",
|
|
59
|
+
data: payload,
|
|
60
|
+
host
|
|
61
|
+
}),
|
|
62
|
+
params: toURLSearchParams(payload)
|
|
63
|
+
};
|
|
64
|
+
return metadata;
|
|
65
|
+
}
|
|
66
|
+
return __listSiteScripts;
|
|
67
|
+
}
|
|
68
|
+
var PositionOnPage = /* @__PURE__ */ ((PositionOnPage2) => {
|
|
69
|
+
PositionOnPage2["UNKNOWN_POSITION"] = "UNKNOWN_POSITION";
|
|
70
|
+
PositionOnPage2["HEAD"] = "HEAD";
|
|
71
|
+
PositionOnPage2["BODY_START"] = "BODY_START";
|
|
72
|
+
PositionOnPage2["BODY_END"] = "BODY_END";
|
|
73
|
+
return PositionOnPage2;
|
|
74
|
+
})(PositionOnPage || {});
|
|
75
|
+
async function listSiteScripts2() {
|
|
76
|
+
const { httpClient, sideEffects } = arguments[0];
|
|
77
|
+
const payload = renameKeysFromSDKRequestToRESTRequest({});
|
|
78
|
+
const reqOpts = listSiteScripts(payload);
|
|
79
|
+
sideEffects?.onSiteCall?.();
|
|
80
|
+
try {
|
|
81
|
+
const result = await httpClient.request(reqOpts);
|
|
82
|
+
sideEffects?.onSuccess?.(result);
|
|
83
|
+
return renameKeysFromRESTResponseToSDKResponse(result.data);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
const transformedError = transformError(
|
|
86
|
+
err,
|
|
87
|
+
{
|
|
88
|
+
spreadPathsToArguments: {},
|
|
89
|
+
explicitPathsToArguments: {},
|
|
90
|
+
singleArgumentUnchanged: false
|
|
91
|
+
},
|
|
92
|
+
[]
|
|
93
|
+
);
|
|
94
|
+
sideEffects?.onError?.(err);
|
|
95
|
+
throw transformedError;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function listSiteScripts3(httpClient) {
|
|
99
|
+
return () => listSiteScripts2(
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
{ httpClient }
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
var listSiteScripts4 = /* @__PURE__ */ createRESTModule(listSiteScripts3);
|
|
105
|
+
|
|
106
|
+
// src/utils/transformStreamUtils.ts
|
|
107
|
+
function injectAfterTransformStream(predicate, htmlToInject) {
|
|
108
|
+
let hasInjected = false;
|
|
109
|
+
return new TransformStream({
|
|
110
|
+
transform: (chunk, controller) => {
|
|
111
|
+
if (!hasInjected) {
|
|
112
|
+
const index = predicate.exec(chunk);
|
|
113
|
+
if (index) {
|
|
114
|
+
const position = index.index + index[0].length;
|
|
115
|
+
chunk = chunk.slice(0, position) + htmlToInject + chunk.slice(position);
|
|
116
|
+
hasInjected = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
controller.enqueue(chunk);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function injectBeforeTransformStream(predicate, htmlToInject) {
|
|
124
|
+
let hasInjected = false;
|
|
125
|
+
return new TransformStream({
|
|
126
|
+
transform: (chunk, controller) => {
|
|
127
|
+
if (!hasInjected) {
|
|
128
|
+
const index = chunk.indexOf(predicate);
|
|
129
|
+
if (index > -1) {
|
|
130
|
+
chunk = chunk.slice(0, index) + htmlToInject + chunk.slice(index);
|
|
131
|
+
hasInjected = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
controller.enqueue(chunk);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/middleware/html-embeds.ts
|
|
140
|
+
var bodyEndTransformStream = (htmlToInject) => injectBeforeTransformStream("</body>", htmlToInject);
|
|
141
|
+
var headTransformStream = (htmlToInject) => injectBeforeTransformStream("</head>", htmlToInject);
|
|
142
|
+
var bodyStartTransformStream = (htmlToInject) => injectAfterTransformStream(/<body(?![^>]*\/>)[^>]*>/, htmlToInject);
|
|
143
|
+
var onRequest = async (context, next) => {
|
|
144
|
+
const response = await next();
|
|
145
|
+
const contentType = response.headers.get("Content-Type");
|
|
146
|
+
if (contentType !== "text/html") {
|
|
147
|
+
return response;
|
|
148
|
+
}
|
|
149
|
+
if (context.url.pathname.startsWith("/_wix")) {
|
|
150
|
+
return response;
|
|
151
|
+
}
|
|
152
|
+
const { siteScripts } = await es_exports.listSiteScripts();
|
|
153
|
+
if (siteScripts == null) {
|
|
154
|
+
throw new Error("Could not fetch site scripts");
|
|
155
|
+
}
|
|
156
|
+
const headInjection = siteScripts.filter((x) => x.position === "HEAD").map((x) => x.html).join("\n");
|
|
157
|
+
const bodyStartInjection = siteScripts.filter((x) => x.position === "BODY_START").map((x) => x.html).join("\n");
|
|
158
|
+
const bodyEndInjection = siteScripts.filter((x) => x.position === "BODY_END").map((x) => x.html).join("\n");
|
|
159
|
+
return new Response(
|
|
160
|
+
response.body?.pipeThrough(new TextDecoderStream()).pipeThrough(headTransformStream(headInjection)).pipeThrough(bodyStartTransformStream(bodyStartInjection)).pipeThrough(bodyEndTransformStream(bodyEndInjection)).pipeThrough(new TextEncoderStream()),
|
|
161
|
+
response
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
export {
|
|
165
|
+
onRequest
|
|
166
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
object,
|
|
3
|
+
string
|
|
4
|
+
} from "../../chunk-Q3KPY4P2.js";
|
|
5
|
+
import {
|
|
6
|
+
auth,
|
|
7
|
+
oAuthStateCookieName
|
|
8
|
+
} from "../../chunk-UZPSWWI5.js";
|
|
9
|
+
import {
|
|
10
|
+
saveSessionTokensToCookie
|
|
11
|
+
} from "../../chunk-HPW4ZAEJ.js";
|
|
12
|
+
import "../../chunk-QRPWKJ4C.js";
|
|
13
|
+
|
|
14
|
+
// src/routes/auth/callback.ts
|
|
15
|
+
var oauthCookieSchema = object({
|
|
16
|
+
codeChallenge: string(),
|
|
17
|
+
codeVerifier: string(),
|
|
18
|
+
originalUri: string(),
|
|
19
|
+
redirectUri: string(),
|
|
20
|
+
state: string()
|
|
21
|
+
});
|
|
22
|
+
var GET = async (context) => {
|
|
23
|
+
const oauthStateCookie = context.cookies.get(oAuthStateCookieName);
|
|
24
|
+
if (oauthStateCookie == null) {
|
|
25
|
+
throw new Error(`Missing \`${oAuthStateCookieName}\` cookie`);
|
|
26
|
+
}
|
|
27
|
+
const oauthData = oauthCookieSchema.parse(JSON.parse(oauthStateCookie.value));
|
|
28
|
+
if (!oauthData.originalUri.startsWith("/")) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Invalid `originalUri` cookie param, only relative URLs are allowed"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const { code, error, errorDescription, state } = auth.parseFromUrl(
|
|
34
|
+
context.url.toString(),
|
|
35
|
+
"query"
|
|
36
|
+
);
|
|
37
|
+
if (error != null) {
|
|
38
|
+
throw new Error(`Error while authenticating: \`${errorDescription}\``);
|
|
39
|
+
}
|
|
40
|
+
const memberTokens = await auth.getMemberTokens(code, state, oauthData);
|
|
41
|
+
context.cookies.delete(oAuthStateCookieName, {
|
|
42
|
+
httpOnly: true,
|
|
43
|
+
path: "/",
|
|
44
|
+
sameSite: "lax",
|
|
45
|
+
secure: true
|
|
46
|
+
});
|
|
47
|
+
saveSessionTokensToCookie(context, memberTokens);
|
|
48
|
+
return context.redirect(oauthData.originalUri);
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
GET
|
|
52
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_enum,
|
|
3
|
+
object,
|
|
4
|
+
string
|
|
5
|
+
} from "../../chunk-Q3KPY4P2.js";
|
|
6
|
+
import {
|
|
7
|
+
auth,
|
|
8
|
+
oAuthStateCookieName
|
|
9
|
+
} from "../../chunk-UZPSWWI5.js";
|
|
10
|
+
import "../../chunk-QRPWKJ4C.js";
|
|
11
|
+
|
|
12
|
+
// src/routes/auth/login.ts
|
|
13
|
+
var loginSearchParams = object({
|
|
14
|
+
prompt: _enum(["login", "none"]).optional(),
|
|
15
|
+
returnToUrl: string().optional()
|
|
16
|
+
});
|
|
17
|
+
var GET = async ({ request, url }) => {
|
|
18
|
+
const { prompt, returnToUrl = "/" } = loginSearchParams.parse(
|
|
19
|
+
Object.fromEntries(url.searchParams.entries())
|
|
20
|
+
);
|
|
21
|
+
const callbackUrl = new URL("/api/auth/callback", url);
|
|
22
|
+
const referer = request.headers.get("referer");
|
|
23
|
+
if (referer != null) {
|
|
24
|
+
const originalUrl = new URL(referer);
|
|
25
|
+
callbackUrl.protocol = originalUrl.protocol;
|
|
26
|
+
}
|
|
27
|
+
const oauthData = auth.generateOAuthData(callbackUrl.toString(), returnToUrl);
|
|
28
|
+
const { authUrl } = await auth.getAuthUrl(oauthData, {
|
|
29
|
+
prompt,
|
|
30
|
+
responseMode: "query"
|
|
31
|
+
});
|
|
32
|
+
const sameSite = import.meta.env.DEV ? "None" : "Lax";
|
|
33
|
+
return new Response(null, {
|
|
34
|
+
headers: {
|
|
35
|
+
Location: authUrl,
|
|
36
|
+
"Set-Cookie": `${oAuthStateCookieName}=${JSON.stringify(
|
|
37
|
+
oauthData
|
|
38
|
+
)}; Max-Age=1800; Path=/; HttpOnly; Secure; SameSite=${sameSite}`
|
|
39
|
+
},
|
|
40
|
+
status: 302
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
GET
|
|
45
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
auth,
|
|
3
|
+
returnToQueryParamName
|
|
4
|
+
} from "../../chunk-UZPSWWI5.js";
|
|
5
|
+
import {
|
|
6
|
+
saveSessionTokensToCookie
|
|
7
|
+
} from "../../chunk-HPW4ZAEJ.js";
|
|
8
|
+
import "../../chunk-QRPWKJ4C.js";
|
|
9
|
+
|
|
10
|
+
// src/routes/auth/logout-callback.ts
|
|
11
|
+
var GET = async (context) => {
|
|
12
|
+
const returnTo = context.url.searchParams.get(returnToQueryParamName) ?? "/";
|
|
13
|
+
if (!returnTo.startsWith("/")) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Invalid \`${returnToQueryParamName}\` query param, only relative URLs are allowed`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
saveSessionTokensToCookie(context, await auth.generateVisitorTokens());
|
|
19
|
+
return context.redirect(returnTo);
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
GET
|
|
23
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
object,
|
|
3
|
+
string
|
|
4
|
+
} from "../../chunk-Q3KPY4P2.js";
|
|
5
|
+
import {
|
|
6
|
+
auth,
|
|
7
|
+
returnToQueryParamName
|
|
8
|
+
} from "../../chunk-UZPSWWI5.js";
|
|
9
|
+
import "../../chunk-QRPWKJ4C.js";
|
|
10
|
+
|
|
11
|
+
// src/routes/auth/logout.ts
|
|
12
|
+
var logoutSearchParams = object({
|
|
13
|
+
returnToUrl: string().optional()
|
|
14
|
+
});
|
|
15
|
+
var POST = async ({ redirect, request, url }) => {
|
|
16
|
+
const { returnToUrl = "/" } = logoutSearchParams.parse(
|
|
17
|
+
Object.fromEntries(url.searchParams.entries())
|
|
18
|
+
);
|
|
19
|
+
const baseUrl = `${new URL(request.url).origin}/${import.meta.env.BASE_URL}`;
|
|
20
|
+
const postFlowUrl = new URL("/api/auth/logout-callback", baseUrl);
|
|
21
|
+
const referer = request.headers.get("referer");
|
|
22
|
+
if (referer != null) {
|
|
23
|
+
const originalUrl = new URL(referer);
|
|
24
|
+
postFlowUrl.protocol = originalUrl.protocol;
|
|
25
|
+
}
|
|
26
|
+
postFlowUrl.searchParams.set(returnToQueryParamName, returnToUrl);
|
|
27
|
+
const { logoutUrl } = await auth.logout(postFlowUrl.toString());
|
|
28
|
+
return redirect(logoutUrl);
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
POST
|
|
32
|
+
};
|