@wix/astro 1.0.27 → 2.0.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.
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +15 -0
- package/build/index.d.ts +2 -3
- package/build/index.js +38 -17073
- package/build/index.js.map +1 -1
- package/package.json +13 -29
- package/src/index.ts +26 -214
- package/tsup.config.mjs +0 -42
- package/build-browser-runtime/setup.d.ts +0 -5
- package/build-browser-runtime/setup.js +0 -129
- package/build-runtime/chunk-B6RICTPP.js +0 -94
- package/build-runtime/chunk-HPW4ZAEJ.js +0 -23
- package/build-runtime/chunk-MLKGABMK.js +0 -9
- package/build-runtime/chunk-NVTQFGTR.js +0 -7
- package/build-runtime/chunk-RKE6XT5Z.js +0 -3104
- package/build-runtime/chunk-UZPSWWI5.js +0 -13
- package/build-runtime/chunk-W73LN534.js +0 -24
- package/build-runtime/context/elevated.d.ts +0 -2
- package/build-runtime/context/elevated.js +0 -24
- package/build-runtime/context/nonElevated.d.ts +0 -2
- package/build-runtime/context/nonElevated.js +0 -37
- package/build-runtime/context/setupServicePlugin.d.ts +0 -5
- package/build-runtime/context/setupServicePlugin.js +0 -16
- package/build-runtime/context/setupWebhook.d.ts +0 -5
- package/build-runtime/context/setupWebhook.js +0 -16
- package/build-runtime/middleware/auth.d.ts +0 -5
- package/build-runtime/middleware/auth.js +0 -74
- package/build-runtime/middleware/html-embeds.d.ts +0 -5
- package/build-runtime/middleware/html-embeds.js +0 -588
- package/build-runtime/routes/auth/callback.d.ts +0 -5
- package/build-runtime/routes/auth/callback.js +0 -52
- package/build-runtime/routes/auth/login.d.ts +0 -5
- package/build-runtime/routes/auth/login.js +0 -45
- package/build-runtime/routes/auth/logout-callback.d.ts +0 -5
- package/build-runtime/routes/auth/logout-callback.js +0 -23
- package/build-runtime/routes/auth/logout.d.ts +0 -5
- package/build-runtime/routes/auth/logout.js +0 -32
- package/build-runtime/routes/servicePluginsDevRoute.d.ts +0 -5
- package/build-runtime/routes/servicePluginsDevRoute.js +0 -13
- package/build-runtime/routes/webhooksDevRoute.d.ts +0 -5
- package/build-runtime/routes/webhooksDevRoute.js +0 -13
- package/runtime/entry.astro +0 -26
- package/src/client-context/setup.ts +0 -14
- package/src/client-context/utils.ts +0 -59
- package/src/components.ts +0 -98
- package/src/constants.ts +0 -2
- package/src/context/elevated.ts +0 -20
- package/src/context/hostProxy.ts +0 -38
- package/src/context/nonElevated.ts +0 -42
- package/src/context/setupServicePlugin.ts +0 -13
- package/src/context/setupWebhook.ts +0 -13
- package/src/context/utils.ts +0 -32
- package/src/directories.ts +0 -5
- package/src/env.d.ts +0 -11
- package/src/middleware/auth.ts +0 -38
- package/src/middleware/html-embeds.ts +0 -59
- package/src/plugins/patchAstroInlineScripts.ts +0 -27
- package/src/plugins/setupSsrContext.ts +0 -65
- package/src/routes/auth/callback.ts +0 -51
- package/src/routes/auth/login.ts +0 -42
- package/src/routes/auth/logout-callback.ts +0 -18
- package/src/routes/auth/logout.ts +0 -28
- package/src/routes/servicePluginsDevRoute.ts +0 -10
- package/src/routes/webhooksDevRoute.ts +0 -10
- package/src/schemas.ts +0 -227
- package/src/types.ts +0 -9
- package/src/utils/authAsyncLocalStorage.ts +0 -7
- package/src/utils/buildBackofficeComponent.ts +0 -64
- package/src/utils/buildComponents.ts +0 -182
- package/src/utils/buildServicePluginComponent.ts +0 -52
- package/src/utils/buildWebhookComponent.ts +0 -39
- package/src/utils/contextualAuth.ts +0 -4
- package/src/utils/createProjectModel.ts +0 -190
- package/src/utils/fs-utils.ts +0 -48
- package/src/utils/generateAppManifest.ts +0 -177
- package/src/utils/generateVisitorTokens.ts +0 -11
- package/src/utils/getSessionTokensFromCookie.ts +0 -38
- package/src/utils/loadEnvVars.ts +0 -47
- package/src/utils/removeUnusedCodegenFiles.ts +0 -34
- package/src/utils/resolveBuildMetadata.ts +0 -37
- package/src/utils/saveSessionTokensToCookie.ts +0 -27
- package/src/utils/transformStreamUtils.ts +0 -39
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import type { InjectedRoute } from 'astro';
|
|
3
|
-
import type { Model } from '../types.js';
|
|
4
|
-
import { buildBackofficeComponent } from './buildBackofficeComponent.js';
|
|
5
|
-
import { buildServicePluginComponent } from './buildServicePluginComponent.js';
|
|
6
|
-
import { buildWebhookComponent } from './buildWebhookComponent.js';
|
|
7
|
-
|
|
8
|
-
export async function buildComponents({
|
|
9
|
-
extensionsDir,
|
|
10
|
-
injectRoute: originalInjectRoute,
|
|
11
|
-
isDev,
|
|
12
|
-
model,
|
|
13
|
-
}: {
|
|
14
|
-
extensionsDir: string;
|
|
15
|
-
injectRoute: (injectRoute: InjectedRoute) => void;
|
|
16
|
-
isDev: boolean;
|
|
17
|
-
model: Model;
|
|
18
|
-
}): Promise<void> {
|
|
19
|
-
// during dev, a single dynamic route is injected so adding or removing
|
|
20
|
-
// components doesn't require re-running the dev command
|
|
21
|
-
const injectRoute = isDev ? () => null : originalInjectRoute;
|
|
22
|
-
|
|
23
|
-
const backofficeCodegenDir = join(extensionsDir, 'backoffice');
|
|
24
|
-
const webhooksCodegenDir = join(extensionsDir, 'webhooks');
|
|
25
|
-
const servicePluginsCodegenDir = join(extensionsDir, 'service-plugins');
|
|
26
|
-
|
|
27
|
-
for (const component of model.components) {
|
|
28
|
-
switch (component.type) {
|
|
29
|
-
case 'BackofficeExtensionMenuPlugin': {
|
|
30
|
-
// configuration only
|
|
31
|
-
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
case 'BackofficeExtensionWidget': {
|
|
35
|
-
if (
|
|
36
|
-
component.manifest.compData.backOfficeExtensionWidget.iframeUrl !=
|
|
37
|
-
null
|
|
38
|
-
) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await buildBackofficeComponent({
|
|
43
|
-
codegenDir: backofficeCodegenDir,
|
|
44
|
-
component,
|
|
45
|
-
entryFileName: 'widget.tsx',
|
|
46
|
-
injectRoute,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case 'BackofficeModal': {
|
|
52
|
-
if (component.manifest.compData.backOfficeModal.iframeUrl != null) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
await buildBackofficeComponent({
|
|
57
|
-
codegenDir: backofficeCodegenDir,
|
|
58
|
-
component,
|
|
59
|
-
entryFileName: 'modal.tsx',
|
|
60
|
-
injectRoute,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case 'BackofficePage': {
|
|
66
|
-
if (component.manifest.compData.backOfficePage.iframeUrl != null) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
await buildBackofficeComponent({
|
|
71
|
-
codegenDir: backofficeCodegenDir,
|
|
72
|
-
component,
|
|
73
|
-
entryFileName: 'page.tsx',
|
|
74
|
-
injectRoute,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case 'EcomAdditionalFees': {
|
|
80
|
-
if (
|
|
81
|
-
component.manifest.compData.ecomAdditionalFees.deploymentUri != null
|
|
82
|
-
) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
await buildServicePluginComponent({
|
|
87
|
-
codegenDir: servicePluginsCodegenDir,
|
|
88
|
-
component,
|
|
89
|
-
injectRoute,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case 'EcomDiscountsTrigger': {
|
|
95
|
-
if (
|
|
96
|
-
component.manifest.compData.ecomDiscountsTrigger.deploymentUri != null
|
|
97
|
-
) {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
await buildServicePluginComponent({
|
|
102
|
-
codegenDir: servicePluginsCodegenDir,
|
|
103
|
-
component,
|
|
104
|
-
injectRoute,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case 'EcomGiftCardsProvider': {
|
|
110
|
-
if (
|
|
111
|
-
component.manifest.compData.giftCardsProvider.deploymentUri != null
|
|
112
|
-
) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
await buildServicePluginComponent({
|
|
117
|
-
codegenDir: servicePluginsCodegenDir,
|
|
118
|
-
component,
|
|
119
|
-
injectRoute,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case 'EcomPaymentSettings': {
|
|
125
|
-
if (
|
|
126
|
-
component.manifest.compData.ecomPaymentSettings.deploymentUri != null
|
|
127
|
-
) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
await buildServicePluginComponent({
|
|
132
|
-
codegenDir: servicePluginsCodegenDir,
|
|
133
|
-
component,
|
|
134
|
-
injectRoute,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case 'EcomShippingRates': {
|
|
140
|
-
if (
|
|
141
|
-
component.manifest.compData.ecomShippingRates.deploymentUri != null
|
|
142
|
-
) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await buildServicePluginComponent({
|
|
147
|
-
codegenDir: servicePluginsCodegenDir,
|
|
148
|
-
component,
|
|
149
|
-
injectRoute,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case 'EcomValidations': {
|
|
155
|
-
if (component.manifest.compData.ecomValidations.deploymentUri != null) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
await buildServicePluginComponent({
|
|
160
|
-
codegenDir: servicePluginsCodegenDir,
|
|
161
|
-
component,
|
|
162
|
-
injectRoute,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
case 'Webhook': {
|
|
168
|
-
if (component.manifest.compData.webhook.callbackUrl != null) {
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
await buildWebhookComponent({
|
|
173
|
-
codegenDir: webhooksCodegenDir,
|
|
174
|
-
component,
|
|
175
|
-
injectRoute,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import type { InjectedRoute } from 'astro';
|
|
4
|
-
import { outdent } from 'outdent';
|
|
5
|
-
import type {
|
|
6
|
-
EcomAdditionalFees,
|
|
7
|
-
EcomDiscountsTrigger,
|
|
8
|
-
EcomGiftCardsProvider,
|
|
9
|
-
EcomPaymentSettings,
|
|
10
|
-
EcomShippingRates,
|
|
11
|
-
EcomValidations,
|
|
12
|
-
} from '../components.js';
|
|
13
|
-
import { outputDir, toRelativePath } from './fs-utils.js';
|
|
14
|
-
|
|
15
|
-
export async function buildServicePluginComponent({
|
|
16
|
-
codegenDir,
|
|
17
|
-
component,
|
|
18
|
-
injectRoute,
|
|
19
|
-
}: {
|
|
20
|
-
codegenDir: string;
|
|
21
|
-
component:
|
|
22
|
-
| EcomAdditionalFees
|
|
23
|
-
| EcomDiscountsTrigger
|
|
24
|
-
| EcomGiftCardsProvider
|
|
25
|
-
| EcomPaymentSettings
|
|
26
|
-
| EcomShippingRates
|
|
27
|
-
| EcomValidations;
|
|
28
|
-
injectRoute: (injectRoute: InjectedRoute) => void;
|
|
29
|
-
}): Promise<void> {
|
|
30
|
-
const directory = join(codegenDir, component.manifest.compId);
|
|
31
|
-
|
|
32
|
-
await outputDir(directory);
|
|
33
|
-
|
|
34
|
-
const entrypoint = join(directory, `entry.ts`);
|
|
35
|
-
const entryFilePath = join(component.directory, 'plugin.ts');
|
|
36
|
-
|
|
37
|
-
await writeFile(
|
|
38
|
-
entrypoint,
|
|
39
|
-
outdent`
|
|
40
|
-
import { setupServicePlugin } from '@wix/astro/context/setup-service-plugin';
|
|
41
|
-
|
|
42
|
-
export const ALL = await setupServicePlugin(
|
|
43
|
-
() => import('${toRelativePath(entrypoint, entryFilePath)}'),
|
|
44
|
-
);
|
|
45
|
-
`
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
injectRoute({
|
|
49
|
-
entrypoint,
|
|
50
|
-
pattern: `/_wix/extensions/service-plugins/${component.manifest.compId}`,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import type { InjectedRoute } from 'astro';
|
|
4
|
-
import { outdent } from 'outdent';
|
|
5
|
-
import type { Webhook } from '../components.js';
|
|
6
|
-
import { outputDir, toRelativePath } from './fs-utils.js';
|
|
7
|
-
|
|
8
|
-
export async function buildWebhookComponent({
|
|
9
|
-
codegenDir,
|
|
10
|
-
component,
|
|
11
|
-
injectRoute,
|
|
12
|
-
}: {
|
|
13
|
-
codegenDir: string;
|
|
14
|
-
component: Webhook;
|
|
15
|
-
injectRoute: (injectRoute: InjectedRoute) => void;
|
|
16
|
-
}): Promise<void> {
|
|
17
|
-
const directory = join(codegenDir, component.manifest.compId);
|
|
18
|
-
|
|
19
|
-
await outputDir(directory);
|
|
20
|
-
|
|
21
|
-
const entrypoint = join(directory, `entry.ts`);
|
|
22
|
-
const entryFilePath = join(component.directory, 'event.ts');
|
|
23
|
-
|
|
24
|
-
await writeFile(
|
|
25
|
-
entrypoint,
|
|
26
|
-
outdent`
|
|
27
|
-
import { setupWebhook } from '@wix/astro/context/setup-webhook';
|
|
28
|
-
|
|
29
|
-
export const ALL = await setupWebhook(
|
|
30
|
-
() => import('${toRelativePath(entrypoint, entryFilePath)}'),
|
|
31
|
-
);
|
|
32
|
-
`
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
injectRoute({
|
|
36
|
-
entrypoint,
|
|
37
|
-
pattern: `/_wix/extensions/webhooks/${component.manifest.compId}`,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import type { AstroIntegrationLogger } from 'astro';
|
|
3
|
-
import { globby } from 'globby';
|
|
4
|
-
import { outdent } from 'outdent';
|
|
5
|
-
import type { Component, UnknownComponent } from '../components.js';
|
|
6
|
-
import type { DevCenterComponent } from '../schemas.js';
|
|
7
|
-
import type { Model } from '../types.js';
|
|
8
|
-
import { EXTENSIONS_DIR } from '../directories.js';
|
|
9
|
-
import {
|
|
10
|
-
baseDevCenterComponentSchema,
|
|
11
|
-
devCenterComponentSchema,
|
|
12
|
-
} from '../schemas.js';
|
|
13
|
-
import { pathExists, readJson } from './fs-utils.js';
|
|
14
|
-
import { loadEnvVars } from './loadEnvVars.js';
|
|
15
|
-
|
|
16
|
-
export async function createProjectModel({
|
|
17
|
-
logger,
|
|
18
|
-
rootDir,
|
|
19
|
-
}: {
|
|
20
|
-
logger: AstroIntegrationLogger;
|
|
21
|
-
rootDir: string;
|
|
22
|
-
}): Promise<Model> {
|
|
23
|
-
const { appId, env } = loadEnvVars({ logger, rootDir });
|
|
24
|
-
|
|
25
|
-
const componentsPaths = await globby(
|
|
26
|
-
pathToGlobby(join(EXTENSIONS_DIR, '*')),
|
|
27
|
-
{
|
|
28
|
-
cwd: rootDir,
|
|
29
|
-
onlyDirectories: true,
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const components: Component[] = [];
|
|
34
|
-
const unknownComponents: UnknownComponent[] = [];
|
|
35
|
-
|
|
36
|
-
for (const componentRelativePath of componentsPaths) {
|
|
37
|
-
const componentPath = join(rootDir, componentRelativePath);
|
|
38
|
-
|
|
39
|
-
const extensionManifest = await readExtensionManifest(componentPath);
|
|
40
|
-
const knownManifest = parseKnownExtensionManifest(extensionManifest);
|
|
41
|
-
|
|
42
|
-
if (knownManifest != null) {
|
|
43
|
-
components.push(createComponent(knownManifest, componentPath));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const unknownManifest = parseBaseExtensionManifest(extensionManifest);
|
|
48
|
-
|
|
49
|
-
unknownComponents.push({
|
|
50
|
-
directory: componentPath,
|
|
51
|
-
manifest: unknownManifest,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
appId,
|
|
57
|
-
components,
|
|
58
|
-
env,
|
|
59
|
-
rootDir,
|
|
60
|
-
unknownComponents,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// https://github.com/mrmlnc/fast-glob/releases/tag/3.0.0
|
|
65
|
-
// globby using fast-glob under the hood accepts only forward slashes in patterns.
|
|
66
|
-
function createComponent(
|
|
67
|
-
manifest: DevCenterComponent,
|
|
68
|
-
directory: string
|
|
69
|
-
): Component {
|
|
70
|
-
switch (manifest.compType) {
|
|
71
|
-
case 'BACK_OFFICE_EXTENSION_MENU_ITEM':
|
|
72
|
-
return {
|
|
73
|
-
directory,
|
|
74
|
-
manifest,
|
|
75
|
-
type: 'BackofficeExtensionMenuPlugin',
|
|
76
|
-
};
|
|
77
|
-
case 'BACK_OFFICE_EXTENSION_WIDGET': {
|
|
78
|
-
return {
|
|
79
|
-
directory,
|
|
80
|
-
manifest,
|
|
81
|
-
type: 'BackofficeExtensionWidget',
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
case 'BACK_OFFICE_MODAL': {
|
|
85
|
-
return {
|
|
86
|
-
directory,
|
|
87
|
-
manifest,
|
|
88
|
-
type: 'BackofficeModal',
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
case 'BACK_OFFICE_PAGE': {
|
|
92
|
-
return {
|
|
93
|
-
directory,
|
|
94
|
-
manifest,
|
|
95
|
-
type: 'BackofficePage',
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
case 'ECOM_ADDITIONAL_FEES': {
|
|
99
|
-
return {
|
|
100
|
-
directory,
|
|
101
|
-
manifest,
|
|
102
|
-
type: 'EcomAdditionalFees',
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
case 'ECOM_DISCOUNTS_TRIGGER': {
|
|
106
|
-
return {
|
|
107
|
-
directory,
|
|
108
|
-
manifest,
|
|
109
|
-
type: 'EcomDiscountsTrigger',
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
case 'ECOM_PAYMENT_SETTINGS': {
|
|
113
|
-
return {
|
|
114
|
-
directory,
|
|
115
|
-
manifest,
|
|
116
|
-
type: 'EcomPaymentSettings',
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
case 'ECOM_SHIPPING_RATES': {
|
|
120
|
-
return {
|
|
121
|
-
directory,
|
|
122
|
-
manifest,
|
|
123
|
-
type: 'EcomShippingRates',
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
case 'ECOM_VALIDATIONS': {
|
|
127
|
-
return {
|
|
128
|
-
directory,
|
|
129
|
-
manifest,
|
|
130
|
-
type: 'EcomValidations',
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
case 'GIFT_CARDS_PROVIDER': {
|
|
134
|
-
return {
|
|
135
|
-
directory,
|
|
136
|
-
manifest,
|
|
137
|
-
type: 'EcomGiftCardsProvider',
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
case 'WEBHOOK': {
|
|
141
|
-
return {
|
|
142
|
-
directory,
|
|
143
|
-
manifest,
|
|
144
|
-
type: 'Webhook',
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function parseBaseExtensionManifest(extensionManifest: unknown) {
|
|
151
|
-
const appManifestResult =
|
|
152
|
-
baseDevCenterComponentSchema.safeParse(extensionManifest);
|
|
153
|
-
|
|
154
|
-
if (!appManifestResult.success) {
|
|
155
|
-
throw new Error(outdent`
|
|
156
|
-
Invalid extension configuration:
|
|
157
|
-
|
|
158
|
-
${appManifestResult.error.issues
|
|
159
|
-
.map((e) => `${e.path.join('.')}: ${e.message}`)
|
|
160
|
-
.join('\n')}
|
|
161
|
-
`);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return appManifestResult.data;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function parseKnownExtensionManifest(extensionManifest: unknown) {
|
|
168
|
-
const appManifestResult =
|
|
169
|
-
devCenterComponentSchema.safeParse(extensionManifest);
|
|
170
|
-
|
|
171
|
-
if (appManifestResult.error) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return appManifestResult.data;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function pathToGlobby(path: string) {
|
|
179
|
-
return path.replaceAll('\\', '/');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function readExtensionManifest(directoryPath: string) {
|
|
183
|
-
const manifestFilePath = join(directoryPath, 'extension.json');
|
|
184
|
-
|
|
185
|
-
if (!(await pathExists(manifestFilePath))) {
|
|
186
|
-
throw new Error('Missing extension manifest');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return await readJson(manifestFilePath);
|
|
190
|
-
}
|
package/src/utils/fs-utils.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
access,
|
|
3
|
-
readFile as fsReadFile,
|
|
4
|
-
mkdir,
|
|
5
|
-
rm,
|
|
6
|
-
writeFile,
|
|
7
|
-
} from 'node:fs/promises';
|
|
8
|
-
import { EOL } from 'node:os';
|
|
9
|
-
import { dirname, relative } from 'node:path';
|
|
10
|
-
|
|
11
|
-
export async function clearDir(dir: string): Promise<void> {
|
|
12
|
-
await rm(dir, { recursive: true });
|
|
13
|
-
await mkdir(dir);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function outputDir(dir: string): Promise<void> {
|
|
17
|
-
await mkdir(dir, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function pathExists(path: string): Promise<boolean> {
|
|
21
|
-
return access(path)
|
|
22
|
-
.then(() => true)
|
|
23
|
-
.catch(() => false);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function readJson(file: string): Promise<unknown> {
|
|
27
|
-
return JSON.parse(await fsReadFile(file, 'utf-8'));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function toRelativePath(from: string, to: string): string {
|
|
31
|
-
const rel = relative(dirname(from), to).replaceAll('\\', '/');
|
|
32
|
-
return rel.startsWith('.') ? rel : `./${rel}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function writeJson(
|
|
36
|
-
filePath: string,
|
|
37
|
-
object: unknown,
|
|
38
|
-
opts?: { spaces: number }
|
|
39
|
-
): Promise<void> {
|
|
40
|
-
const str = toJsonString(object, opts);
|
|
41
|
-
await outputDir(dirname(filePath));
|
|
42
|
-
|
|
43
|
-
await writeFile(filePath, str, 'utf-8');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function toJsonString(object: unknown, opts?: { spaces: number }) {
|
|
47
|
-
return `${JSON.stringify(object, null, opts?.spaces)}${EOL}`;
|
|
48
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
} from '../schemas.js';
|
|
15
|
-
import type { Model } from '../types.js';
|
|
16
|
-
|
|
17
|
-
export function generateAppManifest(model: Model): DevCenterAppManifest {
|
|
18
|
-
const extensions = model.components
|
|
19
|
-
.map((component) => component.manifest)
|
|
20
|
-
.map((manifest) => {
|
|
21
|
-
switch (manifest.compType) {
|
|
22
|
-
case 'BACK_OFFICE_EXTENSION_MENU_ITEM':
|
|
23
|
-
return manifest satisfies DevCenterBackofficeExtensionMenuItem;
|
|
24
|
-
case 'BACK_OFFICE_EXTENSION_WIDGET':
|
|
25
|
-
if (manifest.compData.backOfficeExtensionWidget.iframeUrl != null) {
|
|
26
|
-
return manifest;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
...manifest,
|
|
31
|
-
compData: {
|
|
32
|
-
backOfficeExtensionWidget: {
|
|
33
|
-
...manifest.compData.backOfficeExtensionWidget,
|
|
34
|
-
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
} satisfies DevCenterBackofficeExtensionWidget;
|
|
38
|
-
case 'BACK_OFFICE_MODAL':
|
|
39
|
-
if (manifest.compData.backOfficeModal.iframeUrl != null) {
|
|
40
|
-
return manifest;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
...manifest,
|
|
45
|
-
compData: {
|
|
46
|
-
backOfficeModal: {
|
|
47
|
-
...manifest.compData.backOfficeModal,
|
|
48
|
-
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
} satisfies DevCenterBackofficeModal;
|
|
52
|
-
case 'BACK_OFFICE_PAGE':
|
|
53
|
-
if (manifest.compData.backOfficePage.iframeUrl != null) {
|
|
54
|
-
return manifest;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
...manifest,
|
|
59
|
-
compData: {
|
|
60
|
-
backOfficePage: {
|
|
61
|
-
...manifest.compData.backOfficePage,
|
|
62
|
-
iframeUrl: `_wix/extensions/backoffice/${manifest.compId}`,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
} satisfies DevCenterBackofficePage;
|
|
66
|
-
case 'ECOM_ADDITIONAL_FEES':
|
|
67
|
-
if (manifest.compData.ecomAdditionalFees.deploymentUri != null) {
|
|
68
|
-
return manifest;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
...manifest,
|
|
73
|
-
compData: {
|
|
74
|
-
ecomAdditionalFees: {
|
|
75
|
-
...manifest.compData.ecomAdditionalFees,
|
|
76
|
-
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
} satisfies DevCenterEcomAdditionalFees;
|
|
80
|
-
case 'ECOM_DISCOUNTS_TRIGGER':
|
|
81
|
-
if (manifest.compData.ecomDiscountsTrigger.deploymentUri != null) {
|
|
82
|
-
return manifest;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
...manifest,
|
|
87
|
-
compData: {
|
|
88
|
-
ecomDiscountsTrigger: {
|
|
89
|
-
...manifest.compData.ecomDiscountsTrigger,
|
|
90
|
-
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
} satisfies DevCenterEcomDiscountsTrigger;
|
|
94
|
-
case 'ECOM_PAYMENT_SETTINGS':
|
|
95
|
-
if (manifest.compData.ecomPaymentSettings.deploymentUri != null) {
|
|
96
|
-
return manifest;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
...manifest,
|
|
101
|
-
compData: {
|
|
102
|
-
ecomPaymentSettings: {
|
|
103
|
-
...manifest.compData.ecomPaymentSettings,
|
|
104
|
-
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
} satisfies DevCenterEcomPaymentSettings;
|
|
108
|
-
case 'ECOM_SHIPPING_RATES':
|
|
109
|
-
if (manifest.compData.ecomShippingRates.deploymentUri != null) {
|
|
110
|
-
return manifest;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
...manifest,
|
|
115
|
-
compData: {
|
|
116
|
-
ecomShippingRates: {
|
|
117
|
-
...manifest.compData.ecomShippingRates,
|
|
118
|
-
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
} satisfies DevCenterEcomShippingRates;
|
|
122
|
-
case 'ECOM_VALIDATIONS':
|
|
123
|
-
if (manifest.compData.ecomValidations.deploymentUri != null) {
|
|
124
|
-
return manifest;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
...manifest,
|
|
129
|
-
compData: {
|
|
130
|
-
ecomValidations: {
|
|
131
|
-
...manifest.compData.ecomValidations,
|
|
132
|
-
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
} satisfies DevCenterEcomValidations;
|
|
136
|
-
case 'GIFT_CARDS_PROVIDER':
|
|
137
|
-
if (manifest.compData.giftCardsProvider.deploymentUri != null) {
|
|
138
|
-
return manifest;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
...manifest,
|
|
143
|
-
compData: {
|
|
144
|
-
giftCardsProvider: {
|
|
145
|
-
...manifest.compData.giftCardsProvider,
|
|
146
|
-
deploymentUri: `_wix/extensions/service-plugins/${manifest.compId}`,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
} satisfies DevCenterEcomGiftCardsProvider;
|
|
150
|
-
case 'WEBHOOK':
|
|
151
|
-
if (manifest.compData.webhook.callbackUrl != null) {
|
|
152
|
-
return manifest;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
...manifest,
|
|
157
|
-
compData: {
|
|
158
|
-
webhook: {
|
|
159
|
-
...manifest.compData.webhook,
|
|
160
|
-
callbackUrl: `_wix/extensions/webhooks/${manifest.compId}`,
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
} satisfies DevCenterWebhook;
|
|
164
|
-
default:
|
|
165
|
-
return manifest;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const unknownExtensions = model.unknownComponents.map(
|
|
170
|
-
(component) => component.manifest
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
appId: model.appId,
|
|
175
|
-
components: [...extensions, ...unknownExtensions],
|
|
176
|
-
};
|
|
177
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Tokens } from '@wix/sdk';
|
|
2
|
-
import { OAuthStrategy } from '@wix/sdk';
|
|
3
|
-
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
4
|
-
|
|
5
|
-
const auth = OAuthStrategy({
|
|
6
|
-
clientId: WIX_CLIENT_ID,
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export async function generateVisitorTokens(): Promise<Tokens> {
|
|
10
|
-
return auth.generateVisitorTokens();
|
|
11
|
-
}
|