@wix/astro 2.18.0 → 2.20.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/build/dependencies/astro-auth/backend-runtime/chunk-24J7STEA.js +8 -0
- package/build/dependencies/astro-auth/backend-runtime/chunk-352W54SQ.js +70 -0
- package/build/dependencies/astro-auth/backend-runtime/chunk-USQSPPTM.js +14 -0
- package/build/dependencies/astro-auth/backend-runtime/middleware/auth.js +68 -20
- package/build/dependencies/astro-auth/backend-runtime/middleware/localization.d.ts +5 -0
- package/build/dependencies/astro-auth/backend-runtime/middleware/localization.js +219 -0
- package/build/dependencies/astro-auth/backend-runtime/routes/callback.js +3 -2
- package/build/dependencies/astro-auth/backend-runtime/routes/login.js +3 -2
- package/build/dependencies/astro-auth/backend-runtime/routes/logout-callback.js +3 -2
- package/build/dependencies/astro-auth/backend-runtime/routes/logout.js +3 -2
- package/build/dependencies/astro-auth/backend-runtime/runtime/backend/setupContextualClient.js +9 -1
- package/build/dependencies/astro-backend-extensions/backend-runtime/chunk-CPGTXQVH.js +75 -0
- package/build/dependencies/astro-backend-extensions/backend-runtime/routes/extensions.js +41 -0
- package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupServicePlugin.d.ts +7 -2
- package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupServicePlugin.js +25 -4
- package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupWebhook.d.ts +6 -2
- package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupWebhook.js +24 -5
- package/build/dependencies/astro-backend-extensions/backend-runtime/utils-B7jr2PES.d.ts +5 -0
- package/build/dependencies/astro-context-providers-extensions/browser-runtime/hmr.js +26 -0
- package/build/dependencies/astro-context-providers-extensions/browser-runtime/sdk.js +21 -0
- package/build/dependencies/astro-context-providers-extensions/types/index.d.ts +32 -0
- package/build/dependencies/astro-core/types/index.d.ts +4 -3
- package/build/dependencies/astro-function-libraries-extensions/browser-runtime/sdk.js +21 -0
- package/build/dependencies/astro-function-libraries-extensions/types/index.d.ts +23 -0
- package/build/dependencies/astro-html-embeds/backend-runtime/html-embeds.js +4 -2
- package/build/dependencies/astro-site-components-extensions/types/index.d.ts +5 -0
- package/build/integration/builders-experimental.d.ts +53 -0
- package/build/integration/builders-experimental.js +20 -0
- package/build/integration/builders-experimental.js.map +1 -0
- package/build/integration/builders.d.ts +8 -57
- package/build/integration/builders.js +3 -41
- package/build/integration/builders.js.map +1 -1
- package/build/integration/chunk-QHGDEGZS.js +809 -0
- package/build/integration/chunk-QHGDEGZS.js.map +1 -0
- package/build/integration/chunk-WK4OVFTZ.js +1078 -0
- package/build/integration/chunk-WK4OVFTZ.js.map +1 -0
- package/build/integration/{chunk-IOVROVEX.js → chunk-ZOHC6VQD.js} +1960 -2845
- package/build/integration/chunk-ZOHC6VQD.js.map +1 -0
- package/build/integration/index.d-DMz9m26S.d.ts +58 -0
- package/build/integration/index.d.ts +5 -0
- package/build/integration/index.js +51 -30
- package/build/integration/index.js.map +1 -1
- package/package.json +10 -6
- package/build/dependencies/astro-auth/backend-runtime/chunk-IUZYED2S.js +0 -90
- package/build/dependencies/astro-auth/backend-runtime/chunk-YHKPE45V.js +0 -13
- package/build/dependencies/astro-backend-extensions/backend-runtime/chunk-F7JXR3EK.js +0 -25
- package/build/dependencies/astro-backend-extensions/backend-runtime/routes/servicePlugins.js +0 -18
- package/build/dependencies/astro-backend-extensions/backend-runtime/routes/webhooks.d.ts +0 -5
- package/build/dependencies/astro-backend-extensions/backend-runtime/routes/webhooks.js +0 -18
- package/build/integration/chunk-IOVROVEX.js.map +0 -1
- /package/build/dependencies/astro-backend-extensions/backend-runtime/routes/{servicePlugins.d.ts → extensions.d.ts} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authAsyncLocalStorage,
|
|
3
|
+
createHost
|
|
4
|
+
} from "./chunk-USQSPPTM.js";
|
|
5
|
+
|
|
6
|
+
// src/runtime/backend/contextualClient.ts
|
|
7
|
+
import { createClient } from "@wix/sdk";
|
|
8
|
+
|
|
9
|
+
// src/runtime/backend/hostProxy.ts
|
|
10
|
+
var defaultHost = createHost();
|
|
11
|
+
var resolveHostForCurrentRequest = () => {
|
|
12
|
+
const store = authAsyncLocalStorage.getStore();
|
|
13
|
+
return store?.sdkHost ?? defaultHost;
|
|
14
|
+
};
|
|
15
|
+
var hostProxy = new Proxy(
|
|
16
|
+
{},
|
|
17
|
+
{
|
|
18
|
+
get(target, prop) {
|
|
19
|
+
const host = resolveHostForCurrentRequest();
|
|
20
|
+
const value = host[prop];
|
|
21
|
+
if (typeof value !== "function") {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return function(...args) {
|
|
25
|
+
const anotherHost = resolveHostForCurrentRequest();
|
|
26
|
+
return (
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
28
|
+
anotherHost[prop].apply(
|
|
29
|
+
anotherHost,
|
|
30
|
+
args
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// src/runtime/backend/contextualClient.ts
|
|
39
|
+
var contextualClient = createClient({
|
|
40
|
+
auth: () => {
|
|
41
|
+
const store = authAsyncLocalStorage.getStore();
|
|
42
|
+
if (store?.auth == null) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Cannot find authentication on `AsyncLocalStorage` instance"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return store.auth;
|
|
48
|
+
},
|
|
49
|
+
host: hostProxy
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// src/runtime/backend/elevatedContextualClient.ts
|
|
53
|
+
import { createClient as createClient2 } from "@wix/sdk";
|
|
54
|
+
var elevatedContextualClient = createClient2({
|
|
55
|
+
auth: () => {
|
|
56
|
+
const store = authAsyncLocalStorage.getStore();
|
|
57
|
+
if (store?.elevatedAuth == null) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
"Cannot find authentication on `AsyncLocalStorage` instance"
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return store.elevatedAuth;
|
|
63
|
+
},
|
|
64
|
+
host: hostProxy
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
contextualClient,
|
|
69
|
+
elevatedContextualClient
|
|
70
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/utils/authAsyncLocalStorage.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
var authAsyncLocalStorage = new AsyncLocalStorage();
|
|
4
|
+
|
|
5
|
+
// src/utils/host-utils.ts
|
|
6
|
+
import { headlessNode } from "@wix/headless-node";
|
|
7
|
+
function createHost(request, essentials) {
|
|
8
|
+
return headlessNode.host({ essentials, req: request });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
authAsyncLocalStorage,
|
|
13
|
+
createHost
|
|
14
|
+
};
|
|
@@ -2,12 +2,23 @@ import {
|
|
|
2
2
|
saveSessionTokensToCookie
|
|
3
3
|
} from "../chunk-HPW4ZAEJ.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
contextualClient,
|
|
6
|
+
elevatedContextualClient
|
|
7
|
+
} from "../chunk-352W54SQ.js";
|
|
8
|
+
import {
|
|
9
|
+
authAsyncLocalStorage,
|
|
10
|
+
createHost
|
|
11
|
+
} from "../chunk-USQSPPTM.js";
|
|
7
12
|
import "../chunk-MLKGABMK.js";
|
|
8
13
|
|
|
9
14
|
// src/middleware/auth.ts
|
|
10
|
-
import {
|
|
15
|
+
import { AppStrategy, OAuthStrategy as OAuthStrategy2 } from "@wix/sdk";
|
|
16
|
+
import { WIX_CLIENT_ID as WIX_CLIENT_ID3 } from "astro:env/client";
|
|
17
|
+
import {
|
|
18
|
+
WIX_CLIENT_INSTANCE_ID,
|
|
19
|
+
WIX_CLIENT_PUBLIC_KEY,
|
|
20
|
+
WIX_CLIENT_SECRET
|
|
21
|
+
} from "astro:env/server";
|
|
11
22
|
|
|
12
23
|
// src/utils/generateVisitorTokens.ts
|
|
13
24
|
import { OAuthStrategy } from "@wix/sdk";
|
|
@@ -50,30 +61,67 @@ function getSessionTokensFromCookie(context) {
|
|
|
50
61
|
}
|
|
51
62
|
|
|
52
63
|
// src/middleware/auth.ts
|
|
64
|
+
contextualClient.enableContext("module");
|
|
65
|
+
elevatedContextualClient.enableContext("module", { elevated: true });
|
|
53
66
|
var onRequest = async (context, next) => {
|
|
54
67
|
if (context.url.pathname.startsWith("/_wix/extensions/")) {
|
|
55
68
|
return next();
|
|
56
69
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
const accessToken = context.request.headers.get("Authorization");
|
|
71
|
+
if (accessToken != null) {
|
|
72
|
+
const auth2 = AppStrategy({
|
|
73
|
+
accessToken,
|
|
74
|
+
appId: WIX_CLIENT_ID3
|
|
75
|
+
});
|
|
76
|
+
const elevatedAuth = await auth2.elevated();
|
|
77
|
+
return authAsyncLocalStorage.run(
|
|
78
|
+
{
|
|
79
|
+
auth: auth2,
|
|
80
|
+
elevatedAuth,
|
|
81
|
+
sdkHost: createHost(context.request)
|
|
82
|
+
},
|
|
83
|
+
async () => next()
|
|
84
|
+
);
|
|
69
85
|
}
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
const existingToken = getExistingTokens(context);
|
|
87
|
+
if (existingToken) {
|
|
88
|
+
return authAsyncLocalStorage.run(
|
|
89
|
+
{
|
|
90
|
+
auth: OAuthStrategy2({
|
|
91
|
+
clientId: WIX_CLIENT_ID3,
|
|
92
|
+
tokens: existingToken
|
|
93
|
+
}),
|
|
94
|
+
elevatedAuth: AppStrategy({
|
|
95
|
+
appId: WIX_CLIENT_ID3,
|
|
96
|
+
appSecret: WIX_CLIENT_SECRET,
|
|
97
|
+
instanceId: WIX_CLIENT_INSTANCE_ID,
|
|
98
|
+
publicKey: WIX_CLIENT_PUBLIC_KEY
|
|
99
|
+
}),
|
|
100
|
+
sdkHost: createHost(context.request)
|
|
101
|
+
},
|
|
102
|
+
async () => next()
|
|
103
|
+
);
|
|
72
104
|
}
|
|
73
|
-
|
|
74
|
-
|
|
105
|
+
const visitorToken = await generateVisitorTokens();
|
|
106
|
+
if (context.request.headers.get("Accept")?.includes("text/html") && !context.isPrerendered) {
|
|
107
|
+
saveSessionTokensToCookie(context, visitorToken);
|
|
75
108
|
}
|
|
76
|
-
|
|
109
|
+
const response = await authAsyncLocalStorage.run(
|
|
110
|
+
{
|
|
111
|
+
auth: OAuthStrategy2({
|
|
112
|
+
clientId: WIX_CLIENT_ID3,
|
|
113
|
+
tokens: visitorToken
|
|
114
|
+
}),
|
|
115
|
+
elevatedAuth: AppStrategy({
|
|
116
|
+
appId: WIX_CLIENT_ID3,
|
|
117
|
+
appSecret: WIX_CLIENT_SECRET,
|
|
118
|
+
instanceId: WIX_CLIENT_INSTANCE_ID,
|
|
119
|
+
publicKey: WIX_CLIENT_PUBLIC_KEY
|
|
120
|
+
}),
|
|
121
|
+
sdkHost: createHost(context.request)
|
|
122
|
+
},
|
|
123
|
+
async () => next()
|
|
124
|
+
);
|
|
77
125
|
return response;
|
|
78
126
|
};
|
|
79
127
|
function getExistingTokens(context) {
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authAsyncLocalStorage,
|
|
3
|
+
createHost
|
|
4
|
+
} from "../chunk-USQSPPTM.js";
|
|
5
|
+
import "../chunk-MLKGABMK.js";
|
|
6
|
+
|
|
7
|
+
// ../request-transform-utils/src/transformStreamUtils.ts
|
|
8
|
+
function injectBeforeTransformStream(predicate, htmlToInject) {
|
|
9
|
+
let hasInjected = false;
|
|
10
|
+
return new TransformStream({
|
|
11
|
+
transform: (chunk, controller) => {
|
|
12
|
+
if (!hasInjected) {
|
|
13
|
+
const index = chunk.indexOf(predicate);
|
|
14
|
+
if (index > -1) {
|
|
15
|
+
chunk = chunk.slice(0, index) + htmlToInject + chunk.slice(index);
|
|
16
|
+
hasInjected = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
controller.enqueue(chunk);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ../request-transform-utils/src/index.ts
|
|
25
|
+
var headTransformStream = (htmlToInject) => injectBeforeTransformStream("</head>", htmlToInject);
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/outdent/lib-module/index.js
|
|
28
|
+
function noop() {
|
|
29
|
+
var args = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
args[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function createWeakMap() {
|
|
35
|
+
if (typeof WeakMap !== "undefined") {
|
|
36
|
+
return /* @__PURE__ */ new WeakMap();
|
|
37
|
+
} else {
|
|
38
|
+
return fakeSetOrMap();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function fakeSetOrMap() {
|
|
42
|
+
return {
|
|
43
|
+
add: noop,
|
|
44
|
+
delete: noop,
|
|
45
|
+
get: noop,
|
|
46
|
+
set: noop,
|
|
47
|
+
has: function(k) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var hop = Object.prototype.hasOwnProperty;
|
|
53
|
+
var has = function(obj, prop) {
|
|
54
|
+
return hop.call(obj, prop);
|
|
55
|
+
};
|
|
56
|
+
function extend(target, source) {
|
|
57
|
+
for (var prop in source) {
|
|
58
|
+
if (has(source, prop)) {
|
|
59
|
+
target[prop] = source[prop];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
|
|
65
|
+
var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
|
|
66
|
+
var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
|
|
67
|
+
var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
|
|
68
|
+
var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
|
|
69
|
+
function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
|
|
70
|
+
var indentationLevel = 0;
|
|
71
|
+
var match = strings[0].match(reDetectIndentation);
|
|
72
|
+
if (match) {
|
|
73
|
+
indentationLevel = match[1].length;
|
|
74
|
+
}
|
|
75
|
+
var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
|
|
76
|
+
var reMatchIndent = new RegExp(reSource, "g");
|
|
77
|
+
if (firstInterpolatedValueSetsIndentationLevel) {
|
|
78
|
+
strings = strings.slice(1);
|
|
79
|
+
}
|
|
80
|
+
var newline = options.newline, trimLeadingNewline = options.trimLeadingNewline, trimTrailingNewline = options.trimTrailingNewline;
|
|
81
|
+
var normalizeNewlines = typeof newline === "string";
|
|
82
|
+
var l = strings.length;
|
|
83
|
+
var outdentedStrings = strings.map(function(v, i) {
|
|
84
|
+
v = v.replace(reMatchIndent, "$1");
|
|
85
|
+
if (i === 0 && trimLeadingNewline) {
|
|
86
|
+
v = v.replace(reLeadingNewline, "");
|
|
87
|
+
}
|
|
88
|
+
if (i === l - 1 && trimTrailingNewline) {
|
|
89
|
+
v = v.replace(reTrailingNewline, "");
|
|
90
|
+
}
|
|
91
|
+
if (normalizeNewlines) {
|
|
92
|
+
v = v.replace(/\r\n|\n|\r/g, function(_) {
|
|
93
|
+
return newline;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return v;
|
|
97
|
+
});
|
|
98
|
+
return outdentedStrings;
|
|
99
|
+
}
|
|
100
|
+
function concatStringsAndValues(strings, values) {
|
|
101
|
+
var ret = "";
|
|
102
|
+
for (var i = 0, l = strings.length; i < l; i++) {
|
|
103
|
+
ret += strings[i];
|
|
104
|
+
if (i < l - 1) {
|
|
105
|
+
ret += values[i];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
function isTemplateStringsArray(v) {
|
|
111
|
+
return has(v, "raw") && has(v, "length");
|
|
112
|
+
}
|
|
113
|
+
function createInstance(options) {
|
|
114
|
+
var arrayAutoIndentCache = createWeakMap();
|
|
115
|
+
var arrayFirstInterpSetsIndentCache = createWeakMap();
|
|
116
|
+
function outdent(stringsOrOptions) {
|
|
117
|
+
var values = [];
|
|
118
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
119
|
+
values[_i - 1] = arguments[_i];
|
|
120
|
+
}
|
|
121
|
+
if (isTemplateStringsArray(stringsOrOptions)) {
|
|
122
|
+
var strings = stringsOrOptions;
|
|
123
|
+
var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]);
|
|
124
|
+
var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
|
|
125
|
+
var renderedArray = cache.get(strings);
|
|
126
|
+
if (!renderedArray) {
|
|
127
|
+
renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
|
|
128
|
+
cache.set(strings, renderedArray);
|
|
129
|
+
}
|
|
130
|
+
if (values.length === 0) {
|
|
131
|
+
return renderedArray[0];
|
|
132
|
+
}
|
|
133
|
+
var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
|
|
134
|
+
return rendered;
|
|
135
|
+
} else {
|
|
136
|
+
return createInstance(extend(extend({}, options), stringsOrOptions || {}));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
var fullOutdent = extend(outdent, {
|
|
140
|
+
string: function(str) {
|
|
141
|
+
return _outdentArray([str], false, options)[0];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return fullOutdent;
|
|
145
|
+
}
|
|
146
|
+
var defaultOutdent = createInstance({
|
|
147
|
+
trimLeadingNewline: true,
|
|
148
|
+
trimTrailingNewline: true
|
|
149
|
+
});
|
|
150
|
+
if (typeof module !== "undefined") {
|
|
151
|
+
try {
|
|
152
|
+
module.exports = defaultOutdent;
|
|
153
|
+
Object.defineProperty(defaultOutdent, "__esModule", { value: true });
|
|
154
|
+
defaultOutdent.default = defaultOutdent;
|
|
155
|
+
defaultOutdent.outdent = defaultOutdent;
|
|
156
|
+
} catch (e) {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/utils/localizationUtils.ts
|
|
161
|
+
import {
|
|
162
|
+
getLocalizationData as getLocalizationDataFromUtils,
|
|
163
|
+
MULTILINGUAL_COOKIE_HEADER_KEY
|
|
164
|
+
} from "@wix/headless-localization-utils";
|
|
165
|
+
import { scripts } from "@wix/headless-site-assets";
|
|
166
|
+
async function getLocalizationData(context) {
|
|
167
|
+
return getLocalizationDataFromUtils(
|
|
168
|
+
context.url,
|
|
169
|
+
context.request.headers,
|
|
170
|
+
(await scripts.getSiteMetadata()).properties ?? {}
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
function setMultilingualCookie(context, language) {
|
|
174
|
+
if (context.cookies.get(MULTILINGUAL_COOKIE_HEADER_KEY)?.value !== language) {
|
|
175
|
+
context.cookies.set(MULTILINGUAL_COOKIE_HEADER_KEY, language, {
|
|
176
|
+
httpOnly: false,
|
|
177
|
+
path: "/",
|
|
178
|
+
sameSite: "lax"
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/middleware/localization.ts
|
|
184
|
+
var onRequest = async (context, next) => {
|
|
185
|
+
const store = authAsyncLocalStorage.getStore();
|
|
186
|
+
if (!store) {
|
|
187
|
+
return next();
|
|
188
|
+
}
|
|
189
|
+
let localizationData;
|
|
190
|
+
try {
|
|
191
|
+
localizationData = await getLocalizationData(context);
|
|
192
|
+
} catch {
|
|
193
|
+
return next();
|
|
194
|
+
}
|
|
195
|
+
const { cleanUrl, essentials } = localizationData;
|
|
196
|
+
if (essentials.language == null || essentials.multilingual === void 0) {
|
|
197
|
+
return next();
|
|
198
|
+
}
|
|
199
|
+
store.sdkHost = createHost(context.request, essentials);
|
|
200
|
+
setMultilingualCookie(context, essentials.language);
|
|
201
|
+
const nextResponse = cleanUrl !== context.url.href ? await next(cleanUrl) : await next();
|
|
202
|
+
return modifyHtmlEmbed(nextResponse, context, essentials);
|
|
203
|
+
};
|
|
204
|
+
function modifyHtmlEmbed(response, context, essentials) {
|
|
205
|
+
const contentType = response.headers.get("Content-Type");
|
|
206
|
+
if (contentType !== "text/html" || context.url.pathname.startsWith("/_wix") || !response.body) {
|
|
207
|
+
return response;
|
|
208
|
+
}
|
|
209
|
+
const essentialsScript = defaultOutdent`
|
|
210
|
+
<script>window.essentials = ${JSON.stringify(essentials)};</script>
|
|
211
|
+
`;
|
|
212
|
+
return new Response(
|
|
213
|
+
response.body.pipeThrough(new TextDecoderStream()).pipeThrough(headTransformStream(essentialsScript)).pipeThrough(new TextEncoderStream()),
|
|
214
|
+
response
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
onRequest
|
|
219
|
+
};
|
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
string
|
|
7
7
|
} from "../chunk-BIARYLOZ.js";
|
|
8
8
|
import {
|
|
9
|
-
auth,
|
|
10
9
|
oAuthStateCookieName
|
|
11
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-24J7STEA.js";
|
|
12
11
|
import "../chunk-MLKGABMK.js";
|
|
13
12
|
|
|
14
13
|
// src/routes/callback.ts
|
|
14
|
+
import { getContextualAuth } from "@wix/sdk-runtime/context";
|
|
15
15
|
var oauthCookieSchema = object({
|
|
16
16
|
codeChallenge: string(),
|
|
17
17
|
codeVerifier: string(),
|
|
@@ -30,6 +30,7 @@ var GET = async (context) => {
|
|
|
30
30
|
"Invalid `originalUri` cookie param, only relative URLs are allowed"
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
+
const auth = getContextualAuth();
|
|
33
34
|
const { code, error, errorDescription, state } = auth.parseFromUrl(
|
|
34
35
|
context.url.toString(),
|
|
35
36
|
"query"
|
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
string
|
|
5
5
|
} from "../chunk-BIARYLOZ.js";
|
|
6
6
|
import {
|
|
7
|
-
auth,
|
|
8
7
|
oAuthStateCookieName
|
|
9
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-24J7STEA.js";
|
|
10
9
|
import "../chunk-MLKGABMK.js";
|
|
11
10
|
|
|
12
11
|
// src/routes/login.ts
|
|
12
|
+
import { getContextualAuth } from "@wix/sdk-runtime/context";
|
|
13
13
|
var loginSearchParams = object({
|
|
14
14
|
prompt: _enum(["login", "none"]).optional(),
|
|
15
15
|
returnToUrl: string().optional()
|
|
@@ -24,6 +24,7 @@ var GET = async ({ request, url }) => {
|
|
|
24
24
|
const originalUrl = new URL(referer);
|
|
25
25
|
callbackUrl.protocol = originalUrl.protocol;
|
|
26
26
|
}
|
|
27
|
+
const auth = getContextualAuth();
|
|
27
28
|
const oauthData = auth.generateOAuthData(callbackUrl.toString(), returnToUrl);
|
|
28
29
|
const { authUrl } = await auth.getAuthUrl(oauthData, {
|
|
29
30
|
prompt,
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
saveSessionTokensToCookie
|
|
3
3
|
} from "../chunk-HPW4ZAEJ.js";
|
|
4
4
|
import {
|
|
5
|
-
auth,
|
|
6
5
|
returnToQueryParamName
|
|
7
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-24J7STEA.js";
|
|
8
7
|
import "../chunk-MLKGABMK.js";
|
|
9
8
|
|
|
10
9
|
// src/routes/logout-callback.ts
|
|
10
|
+
import { getContextualAuth } from "@wix/sdk-runtime/context";
|
|
11
11
|
var GET = async (context) => {
|
|
12
12
|
const returnTo = context.url.searchParams.get(returnToQueryParamName) ?? "/";
|
|
13
13
|
if (!returnTo.startsWith("/")) {
|
|
@@ -15,6 +15,7 @@ var GET = async (context) => {
|
|
|
15
15
|
`Invalid \`${returnToQueryParamName}\` query param, only relative URLs are allowed`
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
|
+
const auth = getContextualAuth();
|
|
18
19
|
saveSessionTokensToCookie(context, await auth.generateVisitorTokens());
|
|
19
20
|
return context.redirect(returnTo);
|
|
20
21
|
};
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
string
|
|
4
4
|
} from "../chunk-BIARYLOZ.js";
|
|
5
5
|
import {
|
|
6
|
-
auth,
|
|
7
6
|
returnToQueryParamName
|
|
8
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-24J7STEA.js";
|
|
9
8
|
import "../chunk-MLKGABMK.js";
|
|
10
9
|
|
|
11
10
|
// src/routes/logout.ts
|
|
11
|
+
import { getContextualAuth } from "@wix/sdk-runtime/context";
|
|
12
12
|
var logoutSearchParams = object({
|
|
13
13
|
returnToUrl: string().optional()
|
|
14
14
|
});
|
|
@@ -24,6 +24,7 @@ var POST = async ({ redirect, request, url }) => {
|
|
|
24
24
|
postFlowUrl.protocol = originalUrl.protocol;
|
|
25
25
|
}
|
|
26
26
|
postFlowUrl.searchParams.set(returnToQueryParamName, returnToUrl);
|
|
27
|
+
const auth = getContextualAuth();
|
|
27
28
|
const { logoutUrl } = await auth.logout(postFlowUrl.toString());
|
|
28
29
|
return redirect(logoutUrl);
|
|
29
30
|
};
|
package/build/dependencies/astro-auth/backend-runtime/runtime/backend/setupContextualClient.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
contextualClient,
|
|
3
|
+
elevatedContextualClient
|
|
4
|
+
} from "../../chunk-352W54SQ.js";
|
|
5
|
+
import "../../chunk-USQSPPTM.js";
|
|
2
6
|
import "../../chunk-MLKGABMK.js";
|
|
7
|
+
|
|
8
|
+
// src/runtime/backend/setupContextualClient.ts
|
|
9
|
+
contextualClient.enableContext("module");
|
|
10
|
+
elevatedContextualClient.enableContext("module", { elevated: true });
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/runtime/contextualClient.ts
|
|
2
|
+
import { createClient } from "@wix/sdk";
|
|
3
|
+
var elevateNeededError = new Error(
|
|
4
|
+
"Contextual client is not available for events and service plugins, please use elevate() instead."
|
|
5
|
+
);
|
|
6
|
+
var contextualClient = createClient({
|
|
7
|
+
auth: {
|
|
8
|
+
getActiveToken: () => {
|
|
9
|
+
throw elevateNeededError;
|
|
10
|
+
},
|
|
11
|
+
getAuthHeaders: async () => {
|
|
12
|
+
throw elevateNeededError;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// src/runtime/authAsyncLocalStorage.ts
|
|
18
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
19
|
+
var authAsyncLocalStorage = new AsyncLocalStorage();
|
|
20
|
+
|
|
21
|
+
// src/runtime/elevatedContextualClient.ts
|
|
22
|
+
import { createClient as createClient2 } from "@wix/sdk";
|
|
23
|
+
var elevatedContextualClient = createClient2({
|
|
24
|
+
auth: {
|
|
25
|
+
getAuthHeaders: async (host) => {
|
|
26
|
+
const store = authAsyncLocalStorage.getStore();
|
|
27
|
+
if (!store) {
|
|
28
|
+
throw new Error("Cannot find an authentication strategy");
|
|
29
|
+
}
|
|
30
|
+
if (store.elevatedAuth) {
|
|
31
|
+
return store.elevatedAuth.getAuthHeaders(host);
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Cannot find an elevated authentication strategy");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// src/runtime/utils.ts
|
|
39
|
+
import { AppStrategy, createClient as createClient3 } from "@wix/sdk";
|
|
40
|
+
import { wixContext } from "@wix/sdk-context";
|
|
41
|
+
function createAppStrategy(opts = {}) {
|
|
42
|
+
return AppStrategy({
|
|
43
|
+
...opts,
|
|
44
|
+
appId: import.meta.env.WIX_CLIENT_ID
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function setupClient(fn) {
|
|
48
|
+
let authOptions = {};
|
|
49
|
+
const client = createClient3({
|
|
50
|
+
auth: () => AppStrategy({
|
|
51
|
+
appId: import.meta.env.WIX_CLIENT_ID,
|
|
52
|
+
...authOptions
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
const olderClient = wixContext.client;
|
|
56
|
+
client.enableContext("module");
|
|
57
|
+
await fn();
|
|
58
|
+
if (olderClient) {
|
|
59
|
+
olderClient.enableContext("module");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
client,
|
|
63
|
+
setAuthOptions: (options) => {
|
|
64
|
+
authOptions = options;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
contextualClient,
|
|
71
|
+
authAsyncLocalStorage,
|
|
72
|
+
elevatedContextualClient,
|
|
73
|
+
createAppStrategy,
|
|
74
|
+
setupClient
|
|
75
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/routes/extensions.ts
|
|
2
|
+
import { WIX_CLIENT_PUBLIC_KEY, WIX_CLIENT_SECRET } from "astro:env/server";
|
|
3
|
+
var authOptions = {
|
|
4
|
+
appSecret: WIX_CLIENT_SECRET,
|
|
5
|
+
publicKey: WIX_CLIENT_PUBLIC_KEY
|
|
6
|
+
};
|
|
7
|
+
var runExtension = await createServeExtensionRunner();
|
|
8
|
+
var ALL = async (context) => {
|
|
9
|
+
const componentId = context.params.compId;
|
|
10
|
+
if (componentId == null) {
|
|
11
|
+
return new Response(null, { status: 404 });
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return await runExtension({
|
|
15
|
+
componentId,
|
|
16
|
+
payload: await context.request.text(),
|
|
17
|
+
url: context.request.url
|
|
18
|
+
});
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return Response.json(error, { status: 500 });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
async function createServeExtensionRunner() {
|
|
24
|
+
const { entries } = await import("@virtual/wix-backend-entries");
|
|
25
|
+
return async ({
|
|
26
|
+
componentId,
|
|
27
|
+
payload,
|
|
28
|
+
url
|
|
29
|
+
}) => {
|
|
30
|
+
const loadModule = entries[componentId];
|
|
31
|
+
if (loadModule == null) {
|
|
32
|
+
return new Response(null, { status: 404 });
|
|
33
|
+
}
|
|
34
|
+
const module = await loadModule();
|
|
35
|
+
const result = await module.default({ authOptions, payload, url });
|
|
36
|
+
return Response.json(result ?? null);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
ALL
|
|
41
|
+
};
|
package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupServicePlugin.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as AppStrategyOptions } from '../utils-B7jr2PES.js';
|
|
2
|
+
import '@wix/sdk';
|
|
2
3
|
|
|
3
|
-
declare function setupServicePlugin(fn: () => Promise<unknown>): Promise<
|
|
4
|
+
declare function setupServicePlugin(fn: () => Promise<unknown>): Promise<({ authOptions, payload, url, }: {
|
|
5
|
+
authOptions: AppStrategyOptions;
|
|
6
|
+
payload: string;
|
|
7
|
+
url: string;
|
|
8
|
+
}) => Promise<unknown>>;
|
|
4
9
|
|
|
5
10
|
export { setupServicePlugin };
|