@wix/astro 1.0.30 → 1.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { APIRoute } from 'astro';
2
+
3
+ declare const GET: APIRoute;
4
+
5
+ export { GET };
@@ -0,0 +1,43 @@
1
+ import {
2
+ normalizeWixRedirectUrl
3
+ } from "../../chunk-YX6EVX5Q.js";
4
+ import {
5
+ es_exports
6
+ } from "../../chunk-N2TGCJPN.js";
7
+ import "../../chunk-FR26HCAT.js";
8
+ import "../../chunk-MLKGABMK.js";
9
+
10
+ // src/routes/robots/robots.ts
11
+ import { auth } from "@wix/essentials";
12
+ import { WIX_CLIENT_ID } from "astro:env/client";
13
+ var GET = async ({ request }) => {
14
+ const { redirectUrlWixPages } = await auth.elevate(es_exports.getOAuthApp)(
15
+ WIX_CLIENT_ID
16
+ );
17
+ if (redirectUrlWixPages == null) {
18
+ throw new Error(`Invalid Redirect URL: '${redirectUrlWixPages}'`);
19
+ }
20
+ const baseUrl = normalizeWixRedirectUrl({
21
+ wixRedirectUrl: redirectUrlWixPages
22
+ });
23
+ const robotsUrl = new URL("robots.txt", baseUrl);
24
+ const userAgent = request.headers.get("user-agent");
25
+ const originalRobotsFileResponse = await fetch(robotsUrl, {
26
+ headers: { ...userAgent != null ? { "User-Agent": userAgent } : {} }
27
+ });
28
+ if (!originalRobotsFileResponse.ok) {
29
+ throw new Error(
30
+ `Failed to retrieve original robots.txt from: ${robotsUrl.toString()}. Error: ${originalRobotsFileResponse.statusText}`
31
+ );
32
+ }
33
+ const contentType = originalRobotsFileResponse.headers.get("content-type");
34
+ return new Response(originalRobotsFileResponse.body, {
35
+ headers: {
36
+ ...contentType != null ? { "Content-Type": contentType } : {}
37
+ },
38
+ status: 200
39
+ });
40
+ };
41
+ export {
42
+ GET
43
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/astro",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "devDependencies": {
5
5
  "@wix/auth-management": "^1.0.70",
6
6
  "@wix/dashboard": "^1.3.35",
@@ -51,5 +51,5 @@
51
51
  "artifactId": "wix-astro"
52
52
  }
53
53
  },
54
- "falconPackageHash": "5dcf23446b8dffbca01615c5bdb7455061cb4a01c86e30fce676dfd9"
54
+ "falconPackageHash": "c450d60573cfa8794c6e4075c489ec25d48fbe2cbb3e8bae3b935b48"
55
55
  }
package/src/index.ts CHANGED
@@ -159,6 +159,34 @@ const createIntegration = (
159
159
  prerender: false,
160
160
  });
161
161
 
162
+ injectRoute({
163
+ entrypoint: new URL(
164
+ '../build-runtime/routes/paylink/checkout.js',
165
+ import.meta.url
166
+ ),
167
+ pattern: '/checkout',
168
+ prerender: false,
169
+ });
170
+
171
+ injectRoute({
172
+ entrypoint: new URL(
173
+ '../build-runtime/routes/paylink/checkout.js',
174
+ import.meta.url
175
+ ),
176
+ // https://github.com/wix-private/wix-cli-one/pull/205/files#r2312298435
177
+ pattern: '/__ecom/checkout',
178
+ prerender: false,
179
+ });
180
+
181
+ injectRoute({
182
+ entrypoint: new URL(
183
+ '../build-runtime/routes/robots/robots.js',
184
+ import.meta.url
185
+ ),
186
+ pattern: '/robots.txt',
187
+ prerender: false,
188
+ });
189
+
162
190
  updateConfig({
163
191
  env: {
164
192
  schema: {
@@ -31,6 +31,12 @@ const whitelistedFilePaths = [
31
31
  fileURLToPath(
32
32
  new URL('../build-runtime/routes/paylink/paylink.js', import.meta.url)
33
33
  ),
34
+ fileURLToPath(
35
+ new URL('../build-runtime/routes/paylink/checkout.js', import.meta.url)
36
+ ),
37
+ fileURLToPath(
38
+ new URL('../build-runtime/routes/robots/robots.js', import.meta.url)
39
+ ),
34
40
  ];
35
41
 
36
42
  export function setupSsrContext(rootDir: string): PluginOption {
@@ -0,0 +1,28 @@
1
+ import type { APIRoute } from 'astro';
2
+ import { oAuthApps } from '@wix/auth-management';
3
+ import { auth } from '@wix/essentials';
4
+ import { WIX_CLIENT_ID } from 'astro:env/client';
5
+ import { normalizeWixRedirectUrl } from '../../utils/normalizeWixRedirectUrl.js';
6
+
7
+ export const GET: APIRoute = async ({ url }) => {
8
+ const { redirectUrlWixPages } = await auth.elevate(oAuthApps.getOAuthApp)(
9
+ WIX_CLIENT_ID
10
+ );
11
+
12
+ if (redirectUrlWixPages == null) {
13
+ throw new Error(`Invalid Redirect URL: '${redirectUrlWixPages}'`);
14
+ }
15
+
16
+ const baseUrl = normalizeWixRedirectUrl({
17
+ wixRedirectUrl: redirectUrlWixPages,
18
+ });
19
+ const newCheckoutUrl = new URL(
20
+ url.pathname.replace('/', '') + url.search,
21
+ baseUrl
22
+ );
23
+
24
+ return new Response(null, {
25
+ headers: { Location: newCheckoutUrl.toString() },
26
+ status: 302,
27
+ });
28
+ };
@@ -0,0 +1,40 @@
1
+ import type { APIRoute } from 'astro';
2
+ import { oAuthApps } from '@wix/auth-management';
3
+ import { auth } from '@wix/essentials';
4
+ import { WIX_CLIENT_ID } from 'astro:env/client';
5
+ import { normalizeWixRedirectUrl } from '../../utils/normalizeWixRedirectUrl.js';
6
+
7
+ export const GET: APIRoute = async ({ request }) => {
8
+ const { redirectUrlWixPages } = await auth.elevate(oAuthApps.getOAuthApp)(
9
+ WIX_CLIENT_ID
10
+ );
11
+
12
+ if (redirectUrlWixPages == null) {
13
+ throw new Error(`Invalid Redirect URL: '${redirectUrlWixPages}'`);
14
+ }
15
+
16
+ const baseUrl = normalizeWixRedirectUrl({
17
+ wixRedirectUrl: redirectUrlWixPages,
18
+ });
19
+
20
+ const robotsUrl = new URL('robots.txt', baseUrl);
21
+ const userAgent = request.headers.get('user-agent');
22
+ const originalRobotsFileResponse = await fetch(robotsUrl, {
23
+ headers: { ...(userAgent != null ? { 'User-Agent': userAgent } : {}) },
24
+ });
25
+
26
+ if (!originalRobotsFileResponse.ok) {
27
+ throw new Error(
28
+ `Failed to retrieve original robots.txt from: ${robotsUrl.toString()}. Error: ${originalRobotsFileResponse.statusText}`
29
+ );
30
+ }
31
+
32
+ const contentType = originalRobotsFileResponse.headers.get('content-type');
33
+
34
+ return new Response(originalRobotsFileResponse.body, {
35
+ headers: {
36
+ ...(contentType != null ? { 'Content-Type': contentType } : {}),
37
+ },
38
+ status: 200,
39
+ });
40
+ };
@@ -0,0 +1,11 @@
1
+ export function normalizeWixRedirectUrl({
2
+ wixRedirectUrl,
3
+ }: {
4
+ wixRedirectUrl: string;
5
+ }): string {
6
+ const normalizedWixRedirectUrl = wixRedirectUrl.endsWith('/')
7
+ ? wixRedirectUrl
8
+ : `${wixRedirectUrl}/`;
9
+
10
+ return normalizedWixRedirectUrl;
11
+ }
package/tsup.config.mjs CHANGED
@@ -58,6 +58,12 @@ export default defineConfig([
58
58
  // paylink route
59
59
  'src/routes/paylink/paylink.ts',
60
60
 
61
+ // checkout route
62
+ 'src/routes/paylink/checkout.ts',
63
+
64
+ // robots route
65
+ 'src/routes/robots/robots.ts',
66
+
61
67
  // html embeds
62
68
  'src/middleware/html-embeds.ts',
63
69
  ],