@wix/astro 2.18.0 → 2.19.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.
Files changed (44) hide show
  1. package/build/dependencies/astro-auth/backend-runtime/{chunk-IUZYED2S.js → chunk-4UEBUUCA.js} +8 -11
  2. package/build/dependencies/astro-auth/backend-runtime/chunk-USQSPPTM.js +14 -0
  3. package/build/dependencies/astro-auth/backend-runtime/middleware/auth.js +16 -19
  4. package/build/dependencies/astro-auth/backend-runtime/middleware/localization.d.ts +5 -0
  5. package/build/dependencies/astro-auth/backend-runtime/middleware/localization.js +219 -0
  6. package/build/dependencies/astro-auth/backend-runtime/runtime/backend/setupContextualClient.js +9 -1
  7. package/build/dependencies/astro-backend-extensions/backend-runtime/chunk-CPGTXQVH.js +75 -0
  8. package/build/dependencies/astro-backend-extensions/backend-runtime/routes/extensions.js +41 -0
  9. package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupServicePlugin.d.ts +7 -2
  10. package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupServicePlugin.js +25 -4
  11. package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupWebhook.d.ts +6 -2
  12. package/build/dependencies/astro-backend-extensions/backend-runtime/runtime/setupWebhook.js +24 -5
  13. package/build/dependencies/astro-backend-extensions/backend-runtime/utils-B7jr2PES.d.ts +5 -0
  14. package/build/dependencies/astro-context-providers-extensions/browser-runtime/hmr.js +26 -0
  15. package/build/dependencies/astro-context-providers-extensions/browser-runtime/sdk.js +21 -0
  16. package/build/dependencies/astro-context-providers-extensions/types/index.d.ts +32 -0
  17. package/build/dependencies/astro-core/types/index.d.ts +4 -3
  18. package/build/dependencies/astro-function-libraries-extensions/browser-runtime/sdk.js +21 -0
  19. package/build/dependencies/astro-function-libraries-extensions/types/index.d.ts +23 -0
  20. package/build/dependencies/astro-html-embeds/backend-runtime/html-embeds.js +4 -2
  21. package/build/dependencies/astro-site-components-extensions/types/index.d.ts +5 -0
  22. package/build/integration/builders-experimental.d.ts +53 -0
  23. package/build/integration/builders-experimental.js +20 -0
  24. package/build/integration/builders-experimental.js.map +1 -0
  25. package/build/integration/builders.d.ts +8 -57
  26. package/build/integration/builders.js +3 -41
  27. package/build/integration/builders.js.map +1 -1
  28. package/build/integration/chunk-QHGDEGZS.js +809 -0
  29. package/build/integration/chunk-QHGDEGZS.js.map +1 -0
  30. package/build/integration/chunk-WK4OVFTZ.js +1078 -0
  31. package/build/integration/chunk-WK4OVFTZ.js.map +1 -0
  32. package/build/integration/{chunk-IOVROVEX.js → chunk-ZOHC6VQD.js} +1960 -2845
  33. package/build/integration/chunk-ZOHC6VQD.js.map +1 -0
  34. package/build/integration/index.d-DMz9m26S.d.ts +58 -0
  35. package/build/integration/index.d.ts +5 -0
  36. package/build/integration/index.js +51 -30
  37. package/build/integration/index.js.map +1 -1
  38. package/package.json +10 -6
  39. package/build/dependencies/astro-backend-extensions/backend-runtime/chunk-F7JXR3EK.js +0 -25
  40. package/build/dependencies/astro-backend-extensions/backend-runtime/routes/servicePlugins.js +0 -18
  41. package/build/dependencies/astro-backend-extensions/backend-runtime/routes/webhooks.d.ts +0 -5
  42. package/build/dependencies/astro-backend-extensions/backend-runtime/routes/webhooks.js +0 -18
  43. package/build/integration/chunk-IOVROVEX.js.map +0 -1
  44. /package/build/dependencies/astro-backend-extensions/backend-runtime/routes/{servicePlugins.d.ts → extensions.d.ts} +0 -0
@@ -1,14 +1,14 @@
1
+ import {
2
+ authAsyncLocalStorage,
3
+ createHost
4
+ } from "./chunk-USQSPPTM.js";
5
+
1
6
  // src/runtime/backend/contextualClient.ts
2
7
  import { createClient, OAuthStrategy } from "@wix/sdk";
3
8
  import { WIX_CLIENT_ID } from "astro:env/client";
4
9
 
5
- // src/utils/authAsyncLocalStorage.ts
6
- import { AsyncLocalStorage } from "async_hooks";
7
- var authAsyncLocalStorage = new AsyncLocalStorage();
8
-
9
10
  // src/runtime/backend/hostProxy.ts
10
- import { headlessNode } from "@wix/headless-node";
11
- var defaultHost = headlessNode.host({});
11
+ var defaultHost = createHost();
12
12
  var resolveHostForCurrentRequest = () => {
13
13
  const store = authAsyncLocalStorage.getStore();
14
14
  return store?.sdkHost ?? defaultHost;
@@ -81,10 +81,7 @@ var elevatedContextualClient = createClient2({
81
81
  host: hostProxy
82
82
  });
83
83
 
84
- // src/runtime/backend/setupContextualClient.ts
85
- contextualClient.enableContext("module");
86
- elevatedContextualClient.enableContext("module", { elevated: true });
87
-
88
84
  export {
89
- authAsyncLocalStorage
85
+ contextualClient,
86
+ elevatedContextualClient
90
87
  };
@@ -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,13 +2,15 @@ import {
2
2
  saveSessionTokensToCookie
3
3
  } from "../chunk-HPW4ZAEJ.js";
4
4
  import {
5
- authAsyncLocalStorage
6
- } from "../chunk-IUZYED2S.js";
5
+ contextualClient,
6
+ elevatedContextualClient
7
+ } from "../chunk-4UEBUUCA.js";
8
+ import {
9
+ authAsyncLocalStorage,
10
+ createHost
11
+ } from "../chunk-USQSPPTM.js";
7
12
  import "../chunk-MLKGABMK.js";
8
13
 
9
- // src/middleware/auth.ts
10
- import { headlessNode } from "@wix/headless-node";
11
-
12
14
  // src/utils/generateVisitorTokens.ts
13
15
  import { OAuthStrategy } from "@wix/sdk";
14
16
  import { WIX_CLIENT_ID } from "astro:env/client";
@@ -50,6 +52,8 @@ function getSessionTokensFromCookie(context) {
50
52
  }
51
53
 
52
54
  // src/middleware/auth.ts
55
+ contextualClient.enableContext("module");
56
+ elevatedContextualClient.enableContext("module", { elevated: true });
53
57
  var onRequest = async (context, next) => {
54
58
  if (context.url.pathname.startsWith("/_wix/extensions/")) {
55
59
  return next();
@@ -57,24 +61,17 @@ var onRequest = async (context, next) => {
57
61
  const existingTokens = getExistingTokens(context);
58
62
  const usedTokens = existingTokens ?? await generateVisitorTokens();
59
63
  const store = {
60
- sdkHost: headlessNode.host({ req: context.request }),
64
+ sdkHost: createHost(context.request),
61
65
  sessionTokens: usedTokens
62
66
  };
63
- const response = await authAsyncLocalStorage.run(store, async () => {
67
+ const acceptHeader = context.request.headers.get("Accept");
68
+ const isStandardBrowserRequest = acceptHeader?.includes("text/html");
69
+ if (!context.isPrerendered && existingTokens !== usedTokens && isStandardBrowserRequest) {
70
+ saveSessionTokensToCookie(context, usedTokens);
71
+ }
72
+ return await authAsyncLocalStorage.run(store, async () => {
64
73
  return next();
65
74
  });
66
- const contentType = response.headers.get("Content-Type");
67
- if (contentType !== "text/html") {
68
- return response;
69
- }
70
- if (context.isPrerendered) {
71
- return response;
72
- }
73
- if (existingTokens === usedTokens) {
74
- return response;
75
- }
76
- saveSessionTokensToCookie(context, usedTokens);
77
- return response;
78
75
  };
79
76
  function getExistingTokens(context) {
80
77
  const existingTokens = getSessionTokensFromCookie(context);
@@ -0,0 +1,5 @@
1
+ import { MiddlewareHandler } from 'astro';
2
+
3
+ declare const onRequest: MiddlewareHandler;
4
+
5
+ export { onRequest };
@@ -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
+ };
@@ -1,2 +1,10 @@
1
- import "../../chunk-IUZYED2S.js";
1
+ import {
2
+ contextualClient,
3
+ elevatedContextualClient
4
+ } from "../../chunk-4UEBUUCA.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
+ };
@@ -1,5 +1,10 @@
1
- import { APIRoute } from 'astro';
1
+ import { A as AppStrategyOptions } from '../utils-B7jr2PES.js';
2
+ import '@wix/sdk';
2
3
 
3
- declare function setupServicePlugin(fn: () => Promise<unknown>): Promise<APIRoute>;
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 };
@@ -1,12 +1,33 @@
1
1
  import {
2
+ authAsyncLocalStorage,
3
+ contextualClient,
4
+ createAppStrategy,
5
+ elevatedContextualClient,
2
6
  setupClient
3
- } from "../chunk-F7JXR3EK.js";
7
+ } from "../chunk-CPGTXQVH.js";
4
8
 
5
9
  // src/runtime/setupServicePlugin.ts
10
+ contextualClient.enableContext("module");
11
+ elevatedContextualClient.enableContext("module", { elevated: true });
6
12
  async function setupServicePlugin(fn) {
7
- const client = await setupClient(fn);
8
- return async function(context) {
9
- return client.servicePlugins.processRequest(context.request);
13
+ const { client, setAuthOptions } = await setupClient(fn);
14
+ return async function({
15
+ authOptions,
16
+ payload,
17
+ url
18
+ }) {
19
+ setAuthOptions(authOptions);
20
+ const processedRequest = await client.servicePlugins.parseJWT(payload);
21
+ return authAsyncLocalStorage.run(
22
+ {
23
+ auth: null,
24
+ elevatedAuth: createAppStrategy({
25
+ instanceId: processedRequest.metadata.instanceId,
26
+ ...authOptions
27
+ })
28
+ },
29
+ async () => client.servicePlugins.executeHandler(processedRequest, url)
30
+ );
10
31
  };
11
32
  }
12
33
  export {
@@ -1,5 +1,9 @@
1
- import { APIRoute } from 'astro';
1
+ import { A as AppStrategyOptions } from '../utils-B7jr2PES.js';
2
+ import '@wix/sdk';
2
3
 
3
- declare function setupWebhook(fn: () => Promise<unknown>): Promise<APIRoute>;
4
+ declare function setupWebhook(fn: () => Promise<unknown>): Promise<({ authOptions, payload, }: {
5
+ authOptions: AppStrategyOptions;
6
+ payload: string;
7
+ }) => Promise<void>>;
4
8
 
5
9
  export { setupWebhook };
@@ -1,13 +1,32 @@
1
1
  import {
2
+ authAsyncLocalStorage,
3
+ contextualClient,
4
+ createAppStrategy,
5
+ elevatedContextualClient,
2
6
  setupClient
3
- } from "../chunk-F7JXR3EK.js";
7
+ } from "../chunk-CPGTXQVH.js";
4
8
 
5
9
  // src/runtime/setupWebhook.ts
10
+ contextualClient.enableContext("module");
11
+ elevatedContextualClient.enableContext("module", { elevated: true });
6
12
  async function setupWebhook(fn) {
7
- const client = await setupClient(fn);
8
- return async function(context) {
9
- await client.webhooks.processRequest(context.request);
10
- return new Response("OK");
13
+ const { client, setAuthOptions } = await setupClient(fn);
14
+ return async function({
15
+ authOptions,
16
+ payload
17
+ }) {
18
+ setAuthOptions(authOptions);
19
+ const processedRequest = await client.webhooks.parseJWT(payload);
20
+ return authAsyncLocalStorage.run(
21
+ {
22
+ auth: null,
23
+ elevatedAuth: createAppStrategy({
24
+ instanceId: processedRequest.instanceId,
25
+ ...authOptions
26
+ })
27
+ },
28
+ async () => client.webhooks.executeHandlers(processedRequest)
29
+ );
11
30
  };
12
31
  }
13
32
  export {
@@ -0,0 +1,5 @@
1
+ import { AppStrategy } from '@wix/sdk';
2
+
3
+ type AppStrategyOptions = Partial<Parameters<typeof AppStrategy>[0]>;
4
+
5
+ export type { AppStrategyOptions as A };
@@ -0,0 +1,26 @@
1
+ // ../astro-browser-runtime/src/hmr/react-component.tsx
2
+ import React, { useEffect, useRef, useState } from "react";
3
+ function createComponentHmrWrapper(OriginalComponent, hotData) {
4
+ return (props) => {
5
+ const [WrappedComponent, setComponent] = useState(
6
+ () => hotData.Component ?? OriginalComponent
7
+ );
8
+ const isMountedRef = useRef(false);
9
+ useEffect(() => {
10
+ isMountedRef.current = true;
11
+ hotData.setComponent = (NewComponent) => {
12
+ hotData.Component = NewComponent;
13
+ if (isMountedRef.current) {
14
+ setComponent(() => NewComponent);
15
+ }
16
+ };
17
+ return () => {
18
+ isMountedRef.current = false;
19
+ };
20
+ }, []);
21
+ return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props });
22
+ };
23
+ }
24
+ export {
25
+ createComponentHmrWrapper
26
+ };
@@ -0,0 +1,21 @@
1
+ // ../astro-browser-runtime/src/sdk/site.ts
2
+ import { createClient } from "@wix/sdk";
3
+ import { site } from "@wix/site";
4
+ var enableClient = (applicationId) => {
5
+ const host = site.host({ applicationId });
6
+ const auth = site.auth();
7
+ const wixClient = createClient({
8
+ auth,
9
+ host
10
+ });
11
+ wixClient.enableContext("module");
12
+ return auth.getAccessTokenInjector();
13
+ };
14
+
15
+ // src/runtime/sdk.ts
16
+ function createContext() {
17
+ return enableClient(import.meta.env.WIX_CLIENT_ID);
18
+ }
19
+ export {
20
+ createContext
21
+ };
@@ -0,0 +1,32 @@
1
+ import { WixIntegration, BaseExtension } from '@wix/astro-core';
2
+
3
+ declare const createIntegration: () => WixIntegration;
4
+
5
+ interface ContextProvider extends BaseExtension {
6
+ type: 'ContextProvider';
7
+ options: Options;
8
+ }
9
+ interface Options {
10
+ id: string;
11
+ type: string;
12
+ context?: Record<string, unknown>;
13
+ data?: Record<string, unknown>;
14
+ resources: {
15
+ [key: string]: unknown;
16
+ client: {
17
+ [key: string]: unknown;
18
+ url: string;
19
+ };
20
+ contextSpecifier: {
21
+ [key: string]: unknown;
22
+ hook: string;
23
+ };
24
+ editor?: {
25
+ [key: string]: unknown;
26
+ url: string;
27
+ };
28
+ };
29
+ }
30
+ declare function contextProvider(options: Options): ContextProvider;
31
+
32
+ export { contextProvider, createIntegration as default };
@@ -74,11 +74,12 @@ interface IntegrationHooks {
74
74
  }) => Promise<void> | void;
75
75
  /**
76
76
  * Wrapper around `astro:build:setup`, called during `astro build`.
77
- *
78
- * Note: Applied only for `target: 'client'`.
79
77
  */
80
78
  'wix:build:setup': (options: {
81
79
  createExtensionViteConfig: CreateExtensionViteConfig;
80
+ target: 'client' | 'server';
81
+ updateConfig: (newConfig: InlineConfig) => void;
82
+ vite: InlineConfig;
82
83
  }) => Promise<void> | void;
83
84
  }
84
85
  type WixIntegration = AstroIntegration & {
@@ -93,7 +94,7 @@ declare const createIntegration: ({ integrations, }: {
93
94
 
94
95
  declare class App {
95
96
  private extensions;
96
- use(extension: BaseExtension): this;
97
+ use(extension: BaseDevCenterComponent | BaseExtension): this;
97
98
  }
98
99
  declare function app(): App;
99
100