@wix/astro 1.0.28 → 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 -17084
- package/build/index.js.map +1 -1
- package/package.json +13 -30
- package/src/index.ts +26 -223
- package/tsup.config.mjs +0 -45
- 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-FR26HCAT.js +0 -471
- 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 -165
- 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/paylink/paylink.d.ts +0 -5
- package/build-runtime/routes/paylink/paylink.js +0 -1099
- 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 -68
- 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/paylink/paylink.ts +0 -27
- 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,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
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Tokens } from '@wix/sdk';
|
|
2
|
-
import type { APIContext } from 'astro';
|
|
3
|
-
import { TokenRole } from '@wix/sdk';
|
|
4
|
-
import { z } from 'astro/zod';
|
|
5
|
-
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
6
|
-
|
|
7
|
-
const tokensSchema = z.object({
|
|
8
|
-
clientId: z.string(),
|
|
9
|
-
tokens: z.object({
|
|
10
|
-
accessToken: z.object({
|
|
11
|
-
expiresAt: z.number(),
|
|
12
|
-
value: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
refreshToken: z.object({
|
|
15
|
-
role: z.nativeEnum(TokenRole),
|
|
16
|
-
value: z.string(),
|
|
17
|
-
}),
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export function getSessionTokensFromCookie(context: APIContext): null | Tokens {
|
|
22
|
-
if (!context.isPrerendered) {
|
|
23
|
-
const rawCookie = context.cookies.get('wixSession')?.json() as unknown;
|
|
24
|
-
|
|
25
|
-
if (rawCookie != null) {
|
|
26
|
-
const tokensParseResult = tokensSchema.safeParse(rawCookie);
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
tokensParseResult.success &&
|
|
30
|
-
tokensParseResult.data.clientId === WIX_CLIENT_ID
|
|
31
|
-
) {
|
|
32
|
-
return tokensParseResult.data.tokens;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}
|
package/src/utils/loadEnvVars.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { AstroIntegrationLogger } from 'astro';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { outdent } from 'outdent';
|
|
4
|
-
import { loadEnv } from 'vite';
|
|
5
|
-
|
|
6
|
-
const wixClientIdEnvVar = 'WIX_CLIENT_ID';
|
|
7
|
-
|
|
8
|
-
export function loadEnvVars({
|
|
9
|
-
logger,
|
|
10
|
-
rootDir,
|
|
11
|
-
}: {
|
|
12
|
-
logger: AstroIntegrationLogger;
|
|
13
|
-
rootDir: string;
|
|
14
|
-
}): {
|
|
15
|
-
appId: string;
|
|
16
|
-
env: Record<string, string>;
|
|
17
|
-
} {
|
|
18
|
-
const env = loadEnv(process.env.NODE_ENV ?? 'development', rootDir, '');
|
|
19
|
-
const appId = env[wixClientIdEnvVar];
|
|
20
|
-
|
|
21
|
-
if (appId == null) {
|
|
22
|
-
logger.error(
|
|
23
|
-
outdent`
|
|
24
|
-
Missing environment variable ${chalk.blueBright(wixClientIdEnvVar)}
|
|
25
|
-
To use the Wix SDK, you must provide the ${chalk.blueBright(
|
|
26
|
-
wixClientIdEnvVar
|
|
27
|
-
)} environment variable.
|
|
28
|
-
💡 To pull the required environment variables from Wix, run:
|
|
29
|
-
${chalk.magenta('npx wix env pull')}
|
|
30
|
-
🔍 Need Help?
|
|
31
|
-
- Visit our docs: https://dev.wix.com/docs/go-headless
|
|
32
|
-
- Join the community: https://discord.com/channels/1114269395317968906/1288424190969511987
|
|
33
|
-
`
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
throw new Error(
|
|
37
|
-
`${chalk.magenta(
|
|
38
|
-
wixClientIdEnvVar
|
|
39
|
-
)} not found in loaded environment variables`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
appId,
|
|
45
|
-
env,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { rm } from 'node:fs/promises';
|
|
2
|
-
import { basename } from 'node:path';
|
|
3
|
-
import { globby } from 'globby';
|
|
4
|
-
import type { Model } from '../types.js';
|
|
5
|
-
|
|
6
|
-
export async function removeUnusedCodegenFiles({
|
|
7
|
-
extensionsDir,
|
|
8
|
-
model,
|
|
9
|
-
}: {
|
|
10
|
-
extensionsDir: string;
|
|
11
|
-
model: Model;
|
|
12
|
-
}): Promise<void> {
|
|
13
|
-
const codegenFiles = await globby(`*/*`, {
|
|
14
|
-
absolute: true,
|
|
15
|
-
cwd: extensionsDir,
|
|
16
|
-
onlyDirectories: true,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
for (const dirname of codegenFiles) {
|
|
20
|
-
// rely on codegen files being in the following format:
|
|
21
|
-
// `backoffice/{componentId}/...`, `webhooks/{componentId}/...`, etc...
|
|
22
|
-
const componentId = basename(dirname);
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
model.components.some(
|
|
26
|
-
(component) => component.manifest.compId === componentId
|
|
27
|
-
)
|
|
28
|
-
) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await rm(dirname, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import type { AstroConfig } from 'astro';
|
|
3
|
-
import { pathExists } from './fs-utils.js';
|
|
4
|
-
|
|
5
|
-
interface BuildMetadata {
|
|
6
|
-
appManifestPath: string;
|
|
7
|
-
clientDir: string;
|
|
8
|
-
outDir: string;
|
|
9
|
-
serverDir?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function resolveBuildMetadata(
|
|
13
|
-
appManifestPath: string,
|
|
14
|
-
config: AstroConfig
|
|
15
|
-
): Promise<BuildMetadata> {
|
|
16
|
-
const outDir = fileURLToPath(config.outDir);
|
|
17
|
-
const buildClientDir = fileURLToPath(config.build.client);
|
|
18
|
-
const buildServerDir = fileURLToPath(config.build.server);
|
|
19
|
-
|
|
20
|
-
// When there are only static assets, everything is under the out dir.
|
|
21
|
-
// When there are static and server, the output is in the appropriate folders
|
|
22
|
-
const clientDir = (await pathExists(buildClientDir))
|
|
23
|
-
? buildClientDir
|
|
24
|
-
: outDir;
|
|
25
|
-
|
|
26
|
-
// In SSG (static site generation) mode, there is no `serverDir`, only the client side output.
|
|
27
|
-
const serverDir = (await pathExists(buildServerDir))
|
|
28
|
-
? buildServerDir
|
|
29
|
-
: undefined;
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
appManifestPath,
|
|
33
|
-
clientDir,
|
|
34
|
-
outDir,
|
|
35
|
-
serverDir,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Tokens } from '@wix/sdk';
|
|
2
|
-
import type { APIContext, AstroCookieSetOptions } from 'astro';
|
|
3
|
-
import { WIX_CLIENT_ID } from 'astro:env/client';
|
|
4
|
-
|
|
5
|
-
export function saveSessionTokensToCookie(
|
|
6
|
-
context: APIContext,
|
|
7
|
-
tokens: Tokens
|
|
8
|
-
): void {
|
|
9
|
-
const cookieOptions: AstroCookieSetOptions = {
|
|
10
|
-
path: '/',
|
|
11
|
-
secure: true,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
if (import.meta.env.DEV) {
|
|
15
|
-
cookieOptions.sameSite = 'none';
|
|
16
|
-
cookieOptions.maxAge = 10800;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
context.cookies.set('wixSession', sessionCookieJson(tokens), cookieOptions);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function sessionCookieJson(tokens: Tokens) {
|
|
23
|
-
return {
|
|
24
|
-
clientId: WIX_CLIENT_ID,
|
|
25
|
-
tokens,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function injectAfterTransformStream(
|
|
2
|
-
predicate: RegExp,
|
|
3
|
-
htmlToInject: string
|
|
4
|
-
): TransformStream<string> {
|
|
5
|
-
let hasInjected = false;
|
|
6
|
-
return new TransformStream<string>({
|
|
7
|
-
transform: (chunk, controller) => {
|
|
8
|
-
if (!hasInjected) {
|
|
9
|
-
const index = predicate.exec(chunk);
|
|
10
|
-
if (index) {
|
|
11
|
-
const position = index.index + index[0].length;
|
|
12
|
-
chunk =
|
|
13
|
-
chunk.slice(0, position) + htmlToInject + chunk.slice(position);
|
|
14
|
-
hasInjected = true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
controller.enqueue(chunk);
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function injectBeforeTransformStream(
|
|
23
|
-
predicate: string,
|
|
24
|
-
htmlToInject: string
|
|
25
|
-
): TransformStream<string> {
|
|
26
|
-
let hasInjected = false;
|
|
27
|
-
return new TransformStream<string>({
|
|
28
|
-
transform: (chunk, controller) => {
|
|
29
|
-
if (!hasInjected) {
|
|
30
|
-
const index = chunk.indexOf(predicate);
|
|
31
|
-
if (index > -1) {
|
|
32
|
-
chunk = chunk.slice(0, index) + htmlToInject + chunk.slice(index);
|
|
33
|
-
hasInjected = true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
controller.enqueue(chunk);
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|