@wix/astro 1.0.7 → 1.0.9
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 +1159 -199
- package/build/index.js.map +1 -1
- package/build-runtime/middleware/auth.js +2 -7902
- package/package.json +4 -2
- package/src/components.ts +77 -0
- package/src/index.ts +18 -28
- package/src/schemas.ts +81 -67
- package/src/types.ts +3 -13
- package/src/utils/createProjectModel.ts +98 -25
- package/src/utils/generateAppManifest.ts +28 -40
- package/src/utils/isValidBackofficeComponent.ts +13 -10
- package/src/utils/isValidServicePluginComponent.ts +22 -14
- package/src/utils/isValidWebhookComponent.ts +6 -3
- package/src/utils/resolveBuildMetadata.ts +30 -0
- package/src/utils/writeVirtualBackofficeExtensionFiles.ts +25 -11
- package/src/utils/writeVirtualServicePluginExtensionFiles.ts +7 -7
- package/src/utils/writeVirtualWebhookExtensionFiles.ts +6 -8
|
@@ -1,38 +1,26 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
DevCenterAppManifest,
|
|
3
|
+
DevCenterBackofficeExtensionMenuItem,
|
|
4
|
+
DevCenterBackofficeExtensionWidget,
|
|
5
|
+
DevCenterBackofficeModal,
|
|
6
|
+
DevCenterBackofficePage,
|
|
7
|
+
DevCenterEcomAdditionalFees,
|
|
8
|
+
DevCenterEcomDiscountsTrigger,
|
|
9
|
+
DevCenterEcomGiftCardsProvider,
|
|
10
|
+
DevCenterEcomPaymentSettings,
|
|
11
|
+
DevCenterEcomShippingRates,
|
|
12
|
+
DevCenterEcomValidations,
|
|
13
|
+
DevCenterWebhook,
|
|
14
14
|
} from '../schemas.js';
|
|
15
15
|
import type { Model } from '../types.js';
|
|
16
16
|
|
|
17
17
|
export function generateAppManifest(model: Model) {
|
|
18
|
-
const extensions = model.
|
|
19
|
-
.map((
|
|
18
|
+
const extensions = model.components
|
|
19
|
+
.map((component) => component.manifest)
|
|
20
20
|
.map((manifest) => {
|
|
21
21
|
switch (manifest.compType) {
|
|
22
22
|
case 'BACK_OFFICE_EXTENSION_MENU_ITEM':
|
|
23
|
-
|
|
24
|
-
return manifest;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
...manifest,
|
|
29
|
-
compData: {
|
|
30
|
-
backOfficeExtensionMenuItem: {
|
|
31
|
-
...manifest.compData.backOfficeExtensionMenuItem,
|
|
32
|
-
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
} satisfies BackofficeExtensionMenuItem;
|
|
23
|
+
return manifest satisfies DevCenterBackofficeExtensionMenuItem;
|
|
36
24
|
case 'BACK_OFFICE_EXTENSION_WIDGET':
|
|
37
25
|
if (manifest.compData.backOfficeExtensionWidget.iframeUrl) {
|
|
38
26
|
return manifest;
|
|
@@ -46,7 +34,7 @@ export function generateAppManifest(model: Model) {
|
|
|
46
34
|
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
47
35
|
},
|
|
48
36
|
},
|
|
49
|
-
} satisfies
|
|
37
|
+
} satisfies DevCenterBackofficeExtensionWidget;
|
|
50
38
|
case 'BACK_OFFICE_MODAL':
|
|
51
39
|
if (manifest.compData.backOfficeModal.iframeUrl) {
|
|
52
40
|
return manifest;
|
|
@@ -60,7 +48,7 @@ export function generateAppManifest(model: Model) {
|
|
|
60
48
|
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
61
49
|
},
|
|
62
50
|
},
|
|
63
|
-
} satisfies
|
|
51
|
+
} satisfies DevCenterBackofficeModal;
|
|
64
52
|
case 'BACK_OFFICE_PAGE':
|
|
65
53
|
if (manifest.compData.backOfficePage.iframeUrl) {
|
|
66
54
|
return manifest;
|
|
@@ -74,7 +62,7 @@ export function generateAppManifest(model: Model) {
|
|
|
74
62
|
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
75
63
|
},
|
|
76
64
|
},
|
|
77
|
-
} satisfies
|
|
65
|
+
} satisfies DevCenterBackofficePage;
|
|
78
66
|
case 'ECOM_ADDITIONAL_FEES':
|
|
79
67
|
if (manifest.compData.ecomAdditionalFees.deploymentUri) {
|
|
80
68
|
return manifest;
|
|
@@ -88,7 +76,7 @@ export function generateAppManifest(model: Model) {
|
|
|
88
76
|
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
89
77
|
},
|
|
90
78
|
},
|
|
91
|
-
} satisfies
|
|
79
|
+
} satisfies DevCenterEcomAdditionalFees;
|
|
92
80
|
case 'ECOM_DISCOUNTS_TRIGGER':
|
|
93
81
|
if (manifest.compData.ecomDiscountsTrigger.deploymentUri) {
|
|
94
82
|
return manifest;
|
|
@@ -102,7 +90,7 @@ export function generateAppManifest(model: Model) {
|
|
|
102
90
|
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
103
91
|
},
|
|
104
92
|
},
|
|
105
|
-
} satisfies
|
|
93
|
+
} satisfies DevCenterEcomDiscountsTrigger;
|
|
106
94
|
case 'ECOM_PAYMENT_SETTINGS':
|
|
107
95
|
if (manifest.compData.ecomPaymentSettings.deploymentUri) {
|
|
108
96
|
return manifest;
|
|
@@ -116,7 +104,7 @@ export function generateAppManifest(model: Model) {
|
|
|
116
104
|
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
117
105
|
},
|
|
118
106
|
},
|
|
119
|
-
} satisfies
|
|
107
|
+
} satisfies DevCenterEcomPaymentSettings;
|
|
120
108
|
case 'ECOM_SHIPPING_RATES':
|
|
121
109
|
if (manifest.compData.ecomShippingRates.deploymentUri) {
|
|
122
110
|
return manifest;
|
|
@@ -130,7 +118,7 @@ export function generateAppManifest(model: Model) {
|
|
|
130
118
|
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
131
119
|
},
|
|
132
120
|
},
|
|
133
|
-
} satisfies
|
|
121
|
+
} satisfies DevCenterEcomShippingRates;
|
|
134
122
|
case 'ECOM_VALIDATIONS':
|
|
135
123
|
if (manifest.compData.ecomValidations.deploymentUri) {
|
|
136
124
|
return manifest;
|
|
@@ -144,7 +132,7 @@ export function generateAppManifest(model: Model) {
|
|
|
144
132
|
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
145
133
|
},
|
|
146
134
|
},
|
|
147
|
-
} satisfies
|
|
135
|
+
} satisfies DevCenterEcomValidations;
|
|
148
136
|
case 'GIFT_CARDS_PROVIDER':
|
|
149
137
|
if (manifest.compData.giftCardsProvider.deploymentUri) {
|
|
150
138
|
return manifest;
|
|
@@ -158,7 +146,7 @@ export function generateAppManifest(model: Model) {
|
|
|
158
146
|
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
159
147
|
},
|
|
160
148
|
},
|
|
161
|
-
} satisfies
|
|
149
|
+
} satisfies DevCenterEcomGiftCardsProvider;
|
|
162
150
|
case 'WEBHOOK':
|
|
163
151
|
if (manifest.compData.webhook.callbackUrl) {
|
|
164
152
|
return manifest;
|
|
@@ -172,18 +160,18 @@ export function generateAppManifest(model: Model) {
|
|
|
172
160
|
callbackUrl: `_wix/extensions/webhooks/${manifest.compId}`,
|
|
173
161
|
},
|
|
174
162
|
},
|
|
175
|
-
} satisfies
|
|
163
|
+
} satisfies DevCenterWebhook;
|
|
176
164
|
default:
|
|
177
165
|
return manifest;
|
|
178
166
|
}
|
|
179
167
|
});
|
|
180
168
|
|
|
181
|
-
const unknownExtensions = model.
|
|
182
|
-
(
|
|
169
|
+
const unknownExtensions = model.unknownComponents.map(
|
|
170
|
+
(component) => component.manifest
|
|
183
171
|
);
|
|
184
172
|
|
|
185
173
|
return {
|
|
186
174
|
appId: model.appId,
|
|
187
175
|
components: [...extensions, ...unknownExtensions],
|
|
188
|
-
} satisfies
|
|
176
|
+
} satisfies DevCenterAppManifest;
|
|
189
177
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type { Component } from '../
|
|
1
|
+
import type { Component } from '../components.js';
|
|
2
2
|
|
|
3
|
-
export function isValidBackofficeComponent(
|
|
3
|
+
export function isValidBackofficeComponent(
|
|
4
|
+
component: Component
|
|
5
|
+
): component is
|
|
6
|
+
| Component<'BackofficeExtensionWidget'>
|
|
7
|
+
| Component<'BackofficeModal'>
|
|
8
|
+
| Component<'BackofficePage'> {
|
|
4
9
|
return (
|
|
5
|
-
(component.
|
|
6
|
-
!component.compData.backOfficePage.iframeUrl) ||
|
|
7
|
-
(component.
|
|
8
|
-
!component.compData.backOfficeExtensionWidget.iframeUrl) ||
|
|
9
|
-
(component.
|
|
10
|
-
!component.compData.
|
|
11
|
-
(component.compType === 'BACK_OFFICE_MODAL' &&
|
|
12
|
-
!component.compData.backOfficeModal.iframeUrl)
|
|
10
|
+
(component.type === 'BackofficePage' &&
|
|
11
|
+
!component.manifest.compData.backOfficePage.iframeUrl) ||
|
|
12
|
+
(component.type === 'BackofficeExtensionWidget' &&
|
|
13
|
+
!component.manifest.compData.backOfficeExtensionWidget.iframeUrl) ||
|
|
14
|
+
(component.type === 'BackofficeModal' &&
|
|
15
|
+
!component.manifest.compData.backOfficeModal.iframeUrl)
|
|
13
16
|
);
|
|
14
17
|
}
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import type { Component } from '../
|
|
1
|
+
import type { Component } from '../components.js';
|
|
2
2
|
|
|
3
|
-
export function isValidServicePluginComponent(
|
|
3
|
+
export function isValidServicePluginComponent(
|
|
4
|
+
component: Component
|
|
5
|
+
): component is
|
|
6
|
+
| Component<'EcomAdditionalFees'>
|
|
7
|
+
| Component<'EcomDiscountsTrigger'>
|
|
8
|
+
| Component<'EcomGiftCardsProvider'>
|
|
9
|
+
| Component<'EcomPaymentSettings'>
|
|
10
|
+
| Component<'EcomShippingRates'>
|
|
11
|
+
| Component<'EcomValidations'> {
|
|
4
12
|
return (
|
|
5
|
-
(component.
|
|
6
|
-
!component.compData.ecomShippingRates.deploymentUri) ||
|
|
7
|
-
(component.
|
|
8
|
-
!component.compData.ecomAdditionalFees.deploymentUri) ||
|
|
9
|
-
(component.
|
|
10
|
-
!component.compData.ecomDiscountsTrigger.deploymentUri) ||
|
|
11
|
-
(component.
|
|
12
|
-
!component.compData.ecomValidations.deploymentUri) ||
|
|
13
|
-
(component.
|
|
14
|
-
!component.compData.ecomPaymentSettings.deploymentUri) ||
|
|
15
|
-
(component.
|
|
16
|
-
!component.compData.giftCardsProvider.deploymentUri)
|
|
13
|
+
(component.type === 'EcomShippingRates' &&
|
|
14
|
+
!component.manifest.compData.ecomShippingRates.deploymentUri) ||
|
|
15
|
+
(component.type === 'EcomAdditionalFees' &&
|
|
16
|
+
!component.manifest.compData.ecomAdditionalFees.deploymentUri) ||
|
|
17
|
+
(component.type === 'EcomDiscountsTrigger' &&
|
|
18
|
+
!component.manifest.compData.ecomDiscountsTrigger.deploymentUri) ||
|
|
19
|
+
(component.type === 'EcomValidations' &&
|
|
20
|
+
!component.manifest.compData.ecomValidations.deploymentUri) ||
|
|
21
|
+
(component.type === 'EcomPaymentSettings' &&
|
|
22
|
+
!component.manifest.compData.ecomPaymentSettings.deploymentUri) ||
|
|
23
|
+
(component.type === 'EcomGiftCardsProvider' &&
|
|
24
|
+
!component.manifest.compData.giftCardsProvider.deploymentUri)
|
|
17
25
|
);
|
|
18
26
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { Component } from '../
|
|
1
|
+
import type { Component } from '../components.js';
|
|
2
2
|
|
|
3
|
-
export function isValidWebhookComponent(
|
|
3
|
+
export function isValidWebhookComponent(
|
|
4
|
+
component: Component
|
|
5
|
+
): component is Component<'Webhook'> {
|
|
4
6
|
return (
|
|
5
|
-
component.
|
|
7
|
+
component.type === 'Webhook' &&
|
|
8
|
+
!component.manifest.compData.webhook.callbackUrl
|
|
6
9
|
);
|
|
7
10
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AstroConfig } from 'astro';
|
|
2
|
+
import { pathExists } from './fs-utils.js';
|
|
3
|
+
|
|
4
|
+
interface BuildMetadata {
|
|
5
|
+
appManifestPath: string;
|
|
6
|
+
clientDir: string;
|
|
7
|
+
outDir: string;
|
|
8
|
+
// In SSG (static site generation) mode, there is no `serverDir`, only the client side output.
|
|
9
|
+
serverDir?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function resolveBuildMetadata(
|
|
13
|
+
appManifestPath: string,
|
|
14
|
+
config: AstroConfig
|
|
15
|
+
): Promise<BuildMetadata> {
|
|
16
|
+
const clientDir = (await pathExists(config.build.client.pathname))
|
|
17
|
+
? config.build.client.pathname
|
|
18
|
+
: config.outDir.pathname;
|
|
19
|
+
|
|
20
|
+
const serverDir = (await pathExists(config.build.server.pathname))
|
|
21
|
+
? config.build.server.pathname
|
|
22
|
+
: undefined;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
appManifestPath,
|
|
26
|
+
clientDir,
|
|
27
|
+
outDir: config.outDir.pathname,
|
|
28
|
+
serverDir,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -2,6 +2,8 @@ import { rm, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { globby } from 'globby';
|
|
4
4
|
import { outdent } from 'outdent';
|
|
5
|
+
import { match } from 'variant';
|
|
6
|
+
import type { Component } from '../components.js';
|
|
5
7
|
import type { Model } from '../types.js';
|
|
6
8
|
import { isValidBackofficeComponent } from '../utils/isValidBackofficeComponent.js';
|
|
7
9
|
|
|
@@ -9,8 +11,8 @@ export async function writeVirtualBackofficeExtensionFiles(
|
|
|
9
11
|
model: Model,
|
|
10
12
|
codegenDir: string
|
|
11
13
|
) {
|
|
12
|
-
const
|
|
13
|
-
isValidBackofficeComponent
|
|
14
|
+
const backofficeComponents = model.components.filter(
|
|
15
|
+
isValidBackofficeComponent
|
|
14
16
|
);
|
|
15
17
|
|
|
16
18
|
const existingFiles = await globby(`*.astro`, {
|
|
@@ -19,8 +21,8 @@ export async function writeVirtualBackofficeExtensionFiles(
|
|
|
19
21
|
});
|
|
20
22
|
|
|
21
23
|
for (const filename of existingFiles) {
|
|
22
|
-
const hasMatchingSourceFile =
|
|
23
|
-
(
|
|
24
|
+
const hasMatchingSourceFile = backofficeComponents.some(
|
|
25
|
+
(component) => `${component.manifest.compId}.astro` === filename
|
|
24
26
|
);
|
|
25
27
|
|
|
26
28
|
if (hasMatchingSourceFile) {
|
|
@@ -30,15 +32,12 @@ export async function writeVirtualBackofficeExtensionFiles(
|
|
|
30
32
|
await rm(join(codegenDir, filename));
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
for (const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
extension.cwd,
|
|
37
|
-
'page.tsx'
|
|
38
|
-
);
|
|
35
|
+
for (const component of backofficeComponents) {
|
|
36
|
+
const entryFilename = resolveEntry(component);
|
|
37
|
+
const originalEntrypoint = resolve(model.rootDir, entryFilename);
|
|
39
38
|
const virtualEntrypoint = join(
|
|
40
39
|
codegenDir,
|
|
41
|
-
`${
|
|
40
|
+
`${component.manifest.compId}.astro`
|
|
42
41
|
);
|
|
43
42
|
|
|
44
43
|
await writeFile(
|
|
@@ -55,3 +54,18 @@ export async function writeVirtualBackofficeExtensionFiles(
|
|
|
55
54
|
);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
57
|
+
|
|
58
|
+
function resolveEntry(
|
|
59
|
+
component:
|
|
60
|
+
| Component<'BackofficeExtensionWidget'>
|
|
61
|
+
| Component<'BackofficeModal'>
|
|
62
|
+
| Component<'BackofficePage'>
|
|
63
|
+
) {
|
|
64
|
+
const entryName = match(component, {
|
|
65
|
+
BackofficeExtensionWidget: () => 'widget.tsx',
|
|
66
|
+
BackofficeModal: () => 'modal.tsx',
|
|
67
|
+
BackofficePage: () => 'page.tsx',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return join(component.directory, entryName);
|
|
71
|
+
}
|
|
@@ -9,8 +9,8 @@ export async function writeVirtualServicePluginExtensionFiles(
|
|
|
9
9
|
model: Model,
|
|
10
10
|
codegenDir: string
|
|
11
11
|
) {
|
|
12
|
-
const
|
|
13
|
-
isValidServicePluginComponent
|
|
12
|
+
const servicePluginComponents = model.components.filter(
|
|
13
|
+
isValidServicePluginComponent
|
|
14
14
|
);
|
|
15
15
|
|
|
16
16
|
const existingFiles = await globby(`*.ts`, {
|
|
@@ -19,8 +19,8 @@ export async function writeVirtualServicePluginExtensionFiles(
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
for (const filename of existingFiles) {
|
|
22
|
-
const hasMatchingSourceFile =
|
|
23
|
-
(
|
|
22
|
+
const hasMatchingSourceFile = servicePluginComponents.some(
|
|
23
|
+
(component) => `${component.manifest.compId}.ts` === filename
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
if (hasMatchingSourceFile) {
|
|
@@ -30,11 +30,11 @@ export async function writeVirtualServicePluginExtensionFiles(
|
|
|
30
30
|
await rm(join(codegenDir, filename));
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
for (const
|
|
34
|
-
const originalEntrypoint = resolve(
|
|
33
|
+
for (const component of servicePluginComponents) {
|
|
34
|
+
const originalEntrypoint = resolve(component.directory, 'plugin.ts');
|
|
35
35
|
const virtualEntrypoint = join(
|
|
36
36
|
codegenDir,
|
|
37
|
-
`${
|
|
37
|
+
`${component.manifest.compId}.ts`
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
await writeFile(
|
|
@@ -9,9 +9,7 @@ export async function writeVirtualWebhookExtensionFiles(
|
|
|
9
9
|
model: Model,
|
|
10
10
|
codegenDir: string
|
|
11
11
|
) {
|
|
12
|
-
const
|
|
13
|
-
isValidWebhookComponent(extension.manifest)
|
|
14
|
-
);
|
|
12
|
+
const webhookComponents = model.components.filter(isValidWebhookComponent);
|
|
15
13
|
|
|
16
14
|
const existingFiles = await globby(`*.ts`, {
|
|
17
15
|
cwd: codegenDir,
|
|
@@ -19,8 +17,8 @@ export async function writeVirtualWebhookExtensionFiles(
|
|
|
19
17
|
});
|
|
20
18
|
|
|
21
19
|
for (const filename of existingFiles) {
|
|
22
|
-
const hasMatchingSourceFile =
|
|
23
|
-
(
|
|
20
|
+
const hasMatchingSourceFile = webhookComponents.some(
|
|
21
|
+
(component) => `${component.manifest.compId}.ts` === filename
|
|
24
22
|
);
|
|
25
23
|
|
|
26
24
|
if (hasMatchingSourceFile) {
|
|
@@ -30,11 +28,11 @@ export async function writeVirtualWebhookExtensionFiles(
|
|
|
30
28
|
await rm(join(codegenDir, filename));
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
for (const
|
|
34
|
-
const originalEntrypoint = resolve(
|
|
31
|
+
for (const component of webhookComponents) {
|
|
32
|
+
const originalEntrypoint = resolve(component.directory, 'event.ts');
|
|
35
33
|
const virtualEntrypoint = join(
|
|
36
34
|
codegenDir,
|
|
37
|
-
`${
|
|
35
|
+
`${component.manifest.compId}.ts`
|
|
38
36
|
);
|
|
39
37
|
|
|
40
38
|
await writeFile(
|