@wix/astro 1.0.18 → 1.0.20
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 +91 -75
- 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 +3 -3
- package/build-runtime/routes/auth/logout.js +13 -5
- 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/directories.ts +1 -1
- package/src/index.ts +3 -3
- package/src/plugins/setupSsrContext.ts +33 -17
- 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
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
} from '../schemas.js';
|
|
15
15
|
import type { Model } from '../types.js';
|
|
16
16
|
|
|
17
|
-
export function generateAppManifest(model: Model) {
|
|
17
|
+
export function generateAppManifest(model: Model): DevCenterAppManifest {
|
|
18
18
|
const extensions = model.components
|
|
19
19
|
.map((component) => component.manifest)
|
|
20
20
|
.map((manifest) => {
|
|
@@ -22,7 +22,7 @@ export function generateAppManifest(model: Model) {
|
|
|
22
22
|
case 'BACK_OFFICE_EXTENSION_MENU_ITEM':
|
|
23
23
|
return manifest satisfies DevCenterBackofficeExtensionMenuItem;
|
|
24
24
|
case 'BACK_OFFICE_EXTENSION_WIDGET':
|
|
25
|
-
if (manifest.compData.backOfficeExtensionWidget.iframeUrl) {
|
|
25
|
+
if (manifest.compData.backOfficeExtensionWidget.iframeUrl != null) {
|
|
26
26
|
return manifest;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ export function generateAppManifest(model: Model) {
|
|
|
36
36
|
},
|
|
37
37
|
} satisfies DevCenterBackofficeExtensionWidget;
|
|
38
38
|
case 'BACK_OFFICE_MODAL':
|
|
39
|
-
if (manifest.compData.backOfficeModal.iframeUrl) {
|
|
39
|
+
if (manifest.compData.backOfficeModal.iframeUrl != null) {
|
|
40
40
|
return manifest;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -50,7 +50,7 @@ export function generateAppManifest(model: Model) {
|
|
|
50
50
|
},
|
|
51
51
|
} satisfies DevCenterBackofficeModal;
|
|
52
52
|
case 'BACK_OFFICE_PAGE':
|
|
53
|
-
if (manifest.compData.backOfficePage.iframeUrl) {
|
|
53
|
+
if (manifest.compData.backOfficePage.iframeUrl != null) {
|
|
54
54
|
return manifest;
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ export function generateAppManifest(model: Model) {
|
|
|
64
64
|
},
|
|
65
65
|
} satisfies DevCenterBackofficePage;
|
|
66
66
|
case 'ECOM_ADDITIONAL_FEES':
|
|
67
|
-
if (manifest.compData.ecomAdditionalFees.deploymentUri) {
|
|
67
|
+
if (manifest.compData.ecomAdditionalFees.deploymentUri != null) {
|
|
68
68
|
return manifest;
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -78,7 +78,7 @@ export function generateAppManifest(model: Model) {
|
|
|
78
78
|
},
|
|
79
79
|
} satisfies DevCenterEcomAdditionalFees;
|
|
80
80
|
case 'ECOM_DISCOUNTS_TRIGGER':
|
|
81
|
-
if (manifest.compData.ecomDiscountsTrigger.deploymentUri) {
|
|
81
|
+
if (manifest.compData.ecomDiscountsTrigger.deploymentUri != null) {
|
|
82
82
|
return manifest;
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -92,7 +92,7 @@ export function generateAppManifest(model: Model) {
|
|
|
92
92
|
},
|
|
93
93
|
} satisfies DevCenterEcomDiscountsTrigger;
|
|
94
94
|
case 'ECOM_PAYMENT_SETTINGS':
|
|
95
|
-
if (manifest.compData.ecomPaymentSettings.deploymentUri) {
|
|
95
|
+
if (manifest.compData.ecomPaymentSettings.deploymentUri != null) {
|
|
96
96
|
return manifest;
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -106,7 +106,7 @@ export function generateAppManifest(model: Model) {
|
|
|
106
106
|
},
|
|
107
107
|
} satisfies DevCenterEcomPaymentSettings;
|
|
108
108
|
case 'ECOM_SHIPPING_RATES':
|
|
109
|
-
if (manifest.compData.ecomShippingRates.deploymentUri) {
|
|
109
|
+
if (manifest.compData.ecomShippingRates.deploymentUri != null) {
|
|
110
110
|
return manifest;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -120,7 +120,7 @@ export function generateAppManifest(model: Model) {
|
|
|
120
120
|
},
|
|
121
121
|
} satisfies DevCenterEcomShippingRates;
|
|
122
122
|
case 'ECOM_VALIDATIONS':
|
|
123
|
-
if (manifest.compData.ecomValidations.deploymentUri) {
|
|
123
|
+
if (manifest.compData.ecomValidations.deploymentUri != null) {
|
|
124
124
|
return manifest;
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -134,7 +134,7 @@ export function generateAppManifest(model: Model) {
|
|
|
134
134
|
},
|
|
135
135
|
} satisfies DevCenterEcomValidations;
|
|
136
136
|
case 'GIFT_CARDS_PROVIDER':
|
|
137
|
-
if (manifest.compData.giftCardsProvider.deploymentUri) {
|
|
137
|
+
if (manifest.compData.giftCardsProvider.deploymentUri != null) {
|
|
138
138
|
return manifest;
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -148,7 +148,7 @@ export function generateAppManifest(model: Model) {
|
|
|
148
148
|
},
|
|
149
149
|
} satisfies DevCenterEcomGiftCardsProvider;
|
|
150
150
|
case 'WEBHOOK':
|
|
151
|
-
if (manifest.compData.webhook.callbackUrl) {
|
|
151
|
+
if (manifest.compData.webhook.callbackUrl != null) {
|
|
152
152
|
return manifest;
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -173,5 +173,5 @@ export function generateAppManifest(model: Model) {
|
|
|
173
173
|
return {
|
|
174
174
|
appId: model.appId,
|
|
175
175
|
components: [...extensions, ...unknownExtensions],
|
|
176
|
-
}
|
|
176
|
+
};
|
|
177
177
|
}
|
|
@@ -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
|