@wix/astro 1.0.19 → 1.0.21
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.js +52 -48
- package/build/index.js.map +1 -1
- package/build-browser-runtime/setup.js +4082 -11
- package/build-runtime/middleware/auth.js +3 -3
- package/build-runtime/routes/auth/callback.d.ts +2 -2
- package/build-runtime/routes/auth/callback.js +6 -4
- package/build-runtime/routes/auth/login.d.ts +2 -2
- package/build-runtime/routes/auth/login.js +3 -3
- package/build-runtime/routes/auth/logout-callback.js +4 -2
- package/build-runtime/routes/auth/logout.d.ts +2 -2
- package/build-runtime/routes/auth/logout.js +12 -4
- package/package.json +2 -2
- package/src/context/non-elevated.ts +1 -1
- package/src/context/setup.ts +1 -1
- package/src/context/utils.ts +24 -13
- package/src/index.ts +2 -2
- package/src/routes/auth/callback.ts +6 -4
- package/src/routes/auth/login.ts +4 -4
- package/src/routes/auth/logout-callback.ts +3 -1
- package/src/routes/auth/logout.ts +12 -5
- package/src/routes/service-plugins.ts +2 -2
- package/src/routes/webhooks.ts +2 -2
- package/src/schemas.ts +2 -2
- package/src/utils/createProjectModel.ts +23 -21
- package/src/utils/fs-utils.ts +20 -20
- package/src/utils/generateAppManifest.ts +12 -12
- package/src/utils/generateVisitorTokens.ts +2 -1
- package/src/utils/getSessionTokensFromCookie.ts +3 -3
- package/src/utils/isValidBackofficeComponent.ts +4 -3
- package/src/utils/isValidServicePluginComponent.ts +6 -6
- package/src/utils/isValidWebhookComponent.ts +1 -1
- package/src/utils/loadEnvVars.ts +5 -2
- package/src/utils/saveSessionTokensToCookie.ts +10 -7
- package/src/utils/writeVirtualBackofficeExtensionFiles.ts +1 -1
- package/src/utils/writeVirtualServicePluginExtensionFiles.ts +1 -1
- package/src/utils/writeVirtualWebhookExtensionFiles.ts +1 -1
- package/tsup.config.mjs +17 -17
- package/build-runtime/{chunk-HVACFX6T.js → chunk-VMS3NKCF.js} +6 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Tokens } from '@wix/sdk';
|
|
1
2
|
import { OAuthStrategy } from '@wix/sdk';
|
|
2
3
|
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
3
4
|
|
|
@@ -5,6 +6,6 @@ const auth = OAuthStrategy({
|
|
|
5
6
|
clientId: WIX_CLIENT_ID,
|
|
6
7
|
});
|
|
7
8
|
|
|
8
|
-
export async function generateVisitorTokens() {
|
|
9
|
+
export async function generateVisitorTokens(): Promise<Tokens> {
|
|
9
10
|
return auth.generateVisitorTokens();
|
|
10
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { APIContext } from 'astro';
|
|
2
2
|
import { TokenRole } from '@wix/sdk';
|
|
3
|
-
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
4
3
|
import { z } from 'astro/zod';
|
|
4
|
+
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
5
5
|
|
|
6
6
|
const tokensSchema = z.object({
|
|
7
7
|
clientId: z.string(),
|
|
@@ -23,9 +23,9 @@ export function getSessionTokensFromCookie(
|
|
|
23
23
|
context: APIContext
|
|
24
24
|
): null | SessionTokens {
|
|
25
25
|
if (!context.isPrerendered) {
|
|
26
|
-
const rawCookie = context.cookies.get('wixSession')?.json();
|
|
26
|
+
const rawCookie = context.cookies.get('wixSession')?.json() as unknown;
|
|
27
27
|
|
|
28
|
-
if (rawCookie) {
|
|
28
|
+
if (rawCookie != null) {
|
|
29
29
|
const tokensParseResult = tokensSchema.safeParse(rawCookie);
|
|
30
30
|
|
|
31
31
|
if (
|
|
@@ -8,10 +8,11 @@ export function isValidBackofficeComponent(
|
|
|
8
8
|
| Component<'BackofficePage'> {
|
|
9
9
|
return (
|
|
10
10
|
(component.type === 'BackofficePage' &&
|
|
11
|
-
|
|
11
|
+
component.manifest.compData.backOfficePage.iframeUrl == null) ||
|
|
12
12
|
(component.type === 'BackofficeExtensionWidget' &&
|
|
13
|
-
|
|
13
|
+
component.manifest.compData.backOfficeExtensionWidget.iframeUrl ==
|
|
14
|
+
null) ||
|
|
14
15
|
(component.type === 'BackofficeModal' &&
|
|
15
|
-
|
|
16
|
+
component.manifest.compData.backOfficeModal.iframeUrl == null)
|
|
16
17
|
);
|
|
17
18
|
}
|
|
@@ -11,16 +11,16 @@ export function isValidServicePluginComponent(
|
|
|
11
11
|
| Component<'EcomValidations'> {
|
|
12
12
|
return (
|
|
13
13
|
(component.type === 'EcomShippingRates' &&
|
|
14
|
-
|
|
14
|
+
component.manifest.compData.ecomShippingRates.deploymentUri == null) ||
|
|
15
15
|
(component.type === 'EcomAdditionalFees' &&
|
|
16
|
-
|
|
16
|
+
component.manifest.compData.ecomAdditionalFees.deploymentUri == null) ||
|
|
17
17
|
(component.type === 'EcomDiscountsTrigger' &&
|
|
18
|
-
|
|
18
|
+
component.manifest.compData.ecomDiscountsTrigger.deploymentUri == null) ||
|
|
19
19
|
(component.type === 'EcomValidations' &&
|
|
20
|
-
|
|
20
|
+
component.manifest.compData.ecomValidations.deploymentUri == null) ||
|
|
21
21
|
(component.type === 'EcomPaymentSettings' &&
|
|
22
|
-
|
|
22
|
+
component.manifest.compData.ecomPaymentSettings.deploymentUri == null) ||
|
|
23
23
|
(component.type === 'EcomGiftCardsProvider' &&
|
|
24
|
-
|
|
24
|
+
component.manifest.compData.giftCardsProvider.deploymentUri == null)
|
|
25
25
|
);
|
|
26
26
|
}
|
package/src/utils/loadEnvVars.ts
CHANGED
|
@@ -5,11 +5,14 @@ import { loadEnv } from 'vite';
|
|
|
5
5
|
|
|
6
6
|
const wixClientIdEnvVar = 'WIX_CLIENT_ID';
|
|
7
7
|
|
|
8
|
-
export function loadEnvVars(
|
|
8
|
+
export function loadEnvVars(logger: AstroIntegrationLogger): {
|
|
9
|
+
appId: string;
|
|
10
|
+
env: Record<string, string>;
|
|
11
|
+
} {
|
|
9
12
|
const env = loadEnv(process.env.NODE_ENV ?? 'development', process.cwd(), '');
|
|
10
13
|
const appId = env[wixClientIdEnvVar];
|
|
11
14
|
|
|
12
|
-
if (
|
|
15
|
+
if (appId == null) {
|
|
13
16
|
logger.error(
|
|
14
17
|
outdent`
|
|
15
18
|
Missing environment variable ${chalk.blueBright(wixClientIdEnvVar)}
|
|
@@ -2,16 +2,19 @@ import type { Tokens } from '@wix/sdk';
|
|
|
2
2
|
import type { APIContext } from 'astro';
|
|
3
3
|
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
4
4
|
|
|
5
|
+
export function saveSessionTokensToCookie(
|
|
6
|
+
context: APIContext,
|
|
7
|
+
tokens: Tokens
|
|
8
|
+
): void {
|
|
9
|
+
context.cookies.set('wixSession', sessionCookieJson(tokens), {
|
|
10
|
+
path: '/',
|
|
11
|
+
secure: true,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
function sessionCookieJson(tokens: Tokens) {
|
|
6
16
|
return {
|
|
7
17
|
clientId: WIX_CLIENT_ID,
|
|
8
18
|
tokens,
|
|
9
19
|
};
|
|
10
20
|
}
|
|
11
|
-
|
|
12
|
-
export function saveSessionTokensToCookie(context: APIContext, tokens: Tokens) {
|
|
13
|
-
context.cookies.set('wixSession', sessionCookieJson(tokens), {
|
|
14
|
-
path: '/',
|
|
15
|
-
secure: true,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -11,7 +11,7 @@ import { toRelativePath } from './fs-utils.js';
|
|
|
11
11
|
export async function writeVirtualBackofficeExtensionFiles(
|
|
12
12
|
model: Model,
|
|
13
13
|
codegenDir: string
|
|
14
|
-
) {
|
|
14
|
+
): Promise<void> {
|
|
15
15
|
const backofficeComponents = model.components.filter(
|
|
16
16
|
isValidBackofficeComponent
|
|
17
17
|
);
|
|
@@ -9,7 +9,7 @@ import { isValidServicePluginComponent } from './isValidServicePluginComponent.j
|
|
|
9
9
|
export async function writeVirtualServicePluginExtensionFiles(
|
|
10
10
|
model: Model,
|
|
11
11
|
codegenDir: string
|
|
12
|
-
) {
|
|
12
|
+
): Promise<void> {
|
|
13
13
|
const servicePluginComponents = model.components.filter(
|
|
14
14
|
isValidServicePluginComponent
|
|
15
15
|
);
|
|
@@ -9,7 +9,7 @@ import { isValidWebhookComponent } from './isValidWebhookComponent.js';
|
|
|
9
9
|
export async function writeVirtualWebhookExtensionFiles(
|
|
10
10
|
model: Model,
|
|
11
11
|
codegenDir: string
|
|
12
|
-
) {
|
|
12
|
+
): Promise<void> {
|
|
13
13
|
const webhookComponents = model.components.filter(isValidWebhookComponent);
|
|
14
14
|
|
|
15
15
|
const existingFiles = await globby(`*.ts`, {
|
package/tsup.config.mjs
CHANGED
|
@@ -8,21 +8,21 @@ const astroExternals = ['astro', /^astro:/];
|
|
|
8
8
|
export default defineConfig([
|
|
9
9
|
// astro integration
|
|
10
10
|
{
|
|
11
|
-
entry: ['src/index.ts'],
|
|
12
|
-
target: 'node20.9',
|
|
13
|
-
format: ['esm'],
|
|
14
|
-
outDir: 'build',
|
|
15
11
|
clean: true,
|
|
16
|
-
sourcemap: true,
|
|
17
|
-
external: [...astroExternals, ...viteExternals],
|
|
18
12
|
dts: {
|
|
19
13
|
resolve: [...astroExternals, ...viteExternals],
|
|
20
14
|
},
|
|
15
|
+
entry: ['src/index.ts'],
|
|
16
|
+
external: [...astroExternals, ...viteExternals],
|
|
17
|
+
format: ['esm'],
|
|
18
|
+
outDir: 'build',
|
|
19
|
+
sourcemap: true,
|
|
20
|
+
target: 'node20.9',
|
|
21
21
|
// We specifically do not minify the code in packages **for node** in order to keep it readable for debugging purposes.
|
|
22
|
-
minify: false,
|
|
23
22
|
env: {
|
|
24
23
|
NODE_ENV: isCI ? 'production' : 'development',
|
|
25
24
|
},
|
|
25
|
+
minify: false,
|
|
26
26
|
shims: true,
|
|
27
27
|
// https://github.com/evanw/esbuild/issues/1921
|
|
28
28
|
banner: {
|
|
@@ -34,6 +34,9 @@ export default defineConfig([
|
|
|
34
34
|
},
|
|
35
35
|
// backend runtime
|
|
36
36
|
{
|
|
37
|
+
dts: {
|
|
38
|
+
resolve: [...astroExternals, ...viteExternals],
|
|
39
|
+
},
|
|
37
40
|
entry: [
|
|
38
41
|
// extensions
|
|
39
42
|
'src/routes/webhooks.ts',
|
|
@@ -50,23 +53,20 @@ export default defineConfig([
|
|
|
50
53
|
'src/routes/auth/callback.ts',
|
|
51
54
|
'src/routes/auth/logout-callback.ts',
|
|
52
55
|
],
|
|
53
|
-
|
|
56
|
+
external: [...astroExternals, ...viteExternals],
|
|
54
57
|
format: ['esm'],
|
|
55
58
|
outDir: 'build-runtime',
|
|
56
|
-
|
|
57
|
-
dts: {
|
|
58
|
-
resolve: [...astroExternals, ...viteExternals],
|
|
59
|
-
},
|
|
59
|
+
target: 'node20.9',
|
|
60
60
|
},
|
|
61
61
|
// browser runtime
|
|
62
62
|
{
|
|
63
|
-
entry: ['src/context/setup.ts'],
|
|
64
|
-
target: 'chrome130',
|
|
65
|
-
format: ['esm'],
|
|
66
|
-
outDir: 'build-browser-runtime',
|
|
67
|
-
external: [...astroExternals, ...viteExternals, '@wix/sdk-context'],
|
|
68
63
|
dts: {
|
|
69
64
|
resolve: [...astroExternals, ...viteExternals, '@wix/sdk-context'],
|
|
70
65
|
},
|
|
66
|
+
entry: ['src/context/setup.ts'],
|
|
67
|
+
external: [...astroExternals, ...viteExternals, '@wix/sdk-context'],
|
|
68
|
+
format: ['esm'],
|
|
69
|
+
outDir: 'build-browser-runtime',
|
|
70
|
+
target: 'chrome130',
|
|
71
71
|
},
|
|
72
72
|
]);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// src/utils/saveSessionTokensToCookie.ts
|
|
2
2
|
import { WIX_CLIENT_ID } from "astro:env/client";
|
|
3
|
-
function sessionCookieJson(tokens) {
|
|
4
|
-
return {
|
|
5
|
-
clientId: WIX_CLIENT_ID,
|
|
6
|
-
tokens
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
3
|
function saveSessionTokensToCookie(context, tokens) {
|
|
10
4
|
context.cookies.set("wixSession", sessionCookieJson(tokens), {
|
|
11
5
|
path: "/",
|
|
12
6
|
secure: true
|
|
13
7
|
});
|
|
14
8
|
}
|
|
9
|
+
function sessionCookieJson(tokens) {
|
|
10
|
+
return {
|
|
11
|
+
clientId: WIX_CLIENT_ID,
|
|
12
|
+
tokens
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
15
|
|
|
16
16
|
export {
|
|
17
17
|
saveSessionTokensToCookie
|