@wix/astro 1.0.15 → 1.0.16
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 +74 -30
- package/build/index.js.map +1 -1
- package/build-runtime/context/elevated.d.ts +2 -0
- package/build-runtime/context/elevated.js +17 -0
- package/build-runtime/context/non-elevated.d.ts +2 -0
- package/build-runtime/context/non-elevated.js +20 -0
- package/build-runtime/middleware/auth.js +30 -73
- package/package.json +2 -2
- package/src/context/elevated.ts +18 -0
- package/src/context/non-elevated.ts +18 -0
- package/src/directories.ts +1 -2
- package/src/index.ts +6 -1
- package/src/middleware/auth.ts +9 -73
- package/src/plugins/setupSsrContext.ts +47 -0
- package/src/utils/authAsyncLocalStorage.ts +6 -0
- package/src/utils/fs-utils.ts +6 -1
- package/src/utils/generateVisitorTokens.ts +10 -0
- package/src/utils/getSessionTokensFromCookie.ts +16 -12
- package/src/utils/writeVirtualBackofficeExtensionFiles.ts +2 -1
- package/src/utils/writeVirtualServicePluginExtensionFiles.ts +2 -1
- package/src/utils/writeVirtualWebhookExtensionFiles.ts +2 -1
- package/tsup.config.mjs +2 -0
- package/src/utils/authStrategyAsyncLocalStorage.ts +0 -7
package/build/index.js
CHANGED
|
@@ -8611,15 +8611,15 @@ var require_pattern = __commonJS({
|
|
|
8611
8611
|
exports.removeDuplicateSlashes = removeDuplicateSlashes;
|
|
8612
8612
|
function partitionAbsoluteAndRelative(patterns) {
|
|
8613
8613
|
const absolute = [];
|
|
8614
|
-
const
|
|
8614
|
+
const relative2 = [];
|
|
8615
8615
|
for (const pattern of patterns) {
|
|
8616
8616
|
if (isAbsolute(pattern)) {
|
|
8617
8617
|
absolute.push(pattern);
|
|
8618
8618
|
} else {
|
|
8619
|
-
|
|
8619
|
+
relative2.push(pattern);
|
|
8620
8620
|
}
|
|
8621
8621
|
}
|
|
8622
|
-
return [absolute,
|
|
8622
|
+
return [absolute, relative2];
|
|
8623
8623
|
}
|
|
8624
8624
|
exports.partitionAbsoluteAndRelative = partitionAbsoluteAndRelative;
|
|
8625
8625
|
function isAbsolute(pattern) {
|
|
@@ -12285,7 +12285,7 @@ var require_lib = __commonJS({
|
|
|
12285
12285
|
// src/index.ts
|
|
12286
12286
|
init_esm_shims();
|
|
12287
12287
|
var import_chokidar = __toESM(require_chokidar(), 1);
|
|
12288
|
-
import { join as
|
|
12288
|
+
import { join as join7 } from "node:path";
|
|
12289
12289
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
12290
12290
|
import { envField, passthroughImageService } from "astro/config";
|
|
12291
12291
|
|
|
@@ -12468,9 +12468,45 @@ function patchGlobal() {
|
|
|
12468
12468
|
];
|
|
12469
12469
|
}
|
|
12470
12470
|
|
|
12471
|
+
// src/plugins/setupSsrContext.ts
|
|
12472
|
+
init_esm_shims();
|
|
12473
|
+
import { extname, join as join2 } from "node:path";
|
|
12474
|
+
function setupSsrContext(rootDir) {
|
|
12475
|
+
const srcDir = join2(rootDir, SRC_DIR);
|
|
12476
|
+
const nonElevatedSetupUrl = new URL(
|
|
12477
|
+
"../build-runtime/context/non-elevated.js",
|
|
12478
|
+
import.meta.url
|
|
12479
|
+
);
|
|
12480
|
+
const elevatedSetupUrl = new URL(
|
|
12481
|
+
"../build-runtime/context/elevated.js",
|
|
12482
|
+
import.meta.url
|
|
12483
|
+
);
|
|
12484
|
+
return {
|
|
12485
|
+
applyToEnvironment(environment) {
|
|
12486
|
+
return environment.name === "ssr";
|
|
12487
|
+
},
|
|
12488
|
+
name: "setup-ssr-context",
|
|
12489
|
+
transform(code, id) {
|
|
12490
|
+
if (!id.startsWith(srcDir)) {
|
|
12491
|
+
return null;
|
|
12492
|
+
}
|
|
12493
|
+
const extension = extname(id);
|
|
12494
|
+
if (extension !== ".js" && extension !== ".astro" && extension !== ".ts" && extension !== ".tsx") {
|
|
12495
|
+
return null;
|
|
12496
|
+
}
|
|
12497
|
+
return defaultOutdent`
|
|
12498
|
+
import '${nonElevatedSetupUrl}';
|
|
12499
|
+
import '${elevatedSetupUrl}';
|
|
12500
|
+
|
|
12501
|
+
${code}
|
|
12502
|
+
`;
|
|
12503
|
+
}
|
|
12504
|
+
};
|
|
12505
|
+
}
|
|
12506
|
+
|
|
12471
12507
|
// src/utils/createProjectModel.ts
|
|
12472
12508
|
init_esm_shims();
|
|
12473
|
-
import { join as
|
|
12509
|
+
import { join as join3 } from "node:path";
|
|
12474
12510
|
import { cwd } from "node:process";
|
|
12475
12511
|
|
|
12476
12512
|
// ../../node_modules/globby/index.js
|
|
@@ -17219,7 +17255,7 @@ import {
|
|
|
17219
17255
|
writeFile
|
|
17220
17256
|
} from "node:fs/promises";
|
|
17221
17257
|
import { EOL } from "node:os";
|
|
17222
|
-
import { dirname } from "node:path";
|
|
17258
|
+
import { dirname, relative } from "node:path";
|
|
17223
17259
|
function toJsonString(object, opts) {
|
|
17224
17260
|
return JSON.stringify(object, null, opts?.spaces).concat(EOL);
|
|
17225
17261
|
}
|
|
@@ -17237,6 +17273,10 @@ function pathExists(path2) {
|
|
|
17237
17273
|
async function outputDir(dir) {
|
|
17238
17274
|
await mkdir(dir, { recursive: true });
|
|
17239
17275
|
}
|
|
17276
|
+
function toRelativePath2(from, to) {
|
|
17277
|
+
const rel = relative(dirname(from), to).replaceAll("\\", "/");
|
|
17278
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
17279
|
+
}
|
|
17240
17280
|
|
|
17241
17281
|
// src/utils/loadEnvVars.ts
|
|
17242
17282
|
init_esm_shims();
|
|
@@ -17773,7 +17813,7 @@ async function createProjectModel(logger) {
|
|
|
17773
17813
|
const rootDir = cwd();
|
|
17774
17814
|
const { appId, env: env2 } = loadEnvVars(rootDir, logger);
|
|
17775
17815
|
const componentsPaths = await globby(
|
|
17776
|
-
pathToGlobby(
|
|
17816
|
+
pathToGlobby(join3(EXTENSIONS_DIR, "*")),
|
|
17777
17817
|
{
|
|
17778
17818
|
cwd: rootDir,
|
|
17779
17819
|
onlyDirectories: true
|
|
@@ -17895,7 +17935,7 @@ async function parseBaseExtensionManifest(extensionManifest) {
|
|
|
17895
17935
|
return appManifestResult.data;
|
|
17896
17936
|
}
|
|
17897
17937
|
async function readExtensionManifest(directoryPath) {
|
|
17898
|
-
const manifestFilePath =
|
|
17938
|
+
const manifestFilePath = join3(directoryPath, "extension.json");
|
|
17899
17939
|
if (!await pathExists(manifestFilePath)) {
|
|
17900
17940
|
throw new Error("Missing extension manifest");
|
|
17901
17941
|
}
|
|
@@ -18090,7 +18130,7 @@ async function resolveBuildMetadata(appManifestPath, config) {
|
|
|
18090
18130
|
// src/utils/writeVirtualBackofficeExtensionFiles.ts
|
|
18091
18131
|
init_esm_shims();
|
|
18092
18132
|
import { rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
18093
|
-
import { join as
|
|
18133
|
+
import { join as join4, resolve } from "node:path";
|
|
18094
18134
|
var import_variant2 = __toESM(require_lib(), 1);
|
|
18095
18135
|
async function writeVirtualBackofficeExtensionFiles(model, codegenDir) {
|
|
18096
18136
|
const backofficeComponents = model.components.filter(
|
|
@@ -18107,12 +18147,12 @@ async function writeVirtualBackofficeExtensionFiles(model, codegenDir) {
|
|
|
18107
18147
|
if (hasMatchingSourceFile) {
|
|
18108
18148
|
continue;
|
|
18109
18149
|
}
|
|
18110
|
-
await rm(
|
|
18150
|
+
await rm(join4(codegenDir, filename));
|
|
18111
18151
|
}
|
|
18112
18152
|
for (const component of backofficeComponents) {
|
|
18113
18153
|
const entryFilename = resolveEntry(component);
|
|
18114
18154
|
const originalEntrypoint = resolve(model.rootDir, entryFilename);
|
|
18115
|
-
const virtualEntrypoint =
|
|
18155
|
+
const virtualEntrypoint = join4(
|
|
18116
18156
|
codegenDir,
|
|
18117
18157
|
`${component.manifest.compId}.astro`
|
|
18118
18158
|
);
|
|
@@ -18120,7 +18160,7 @@ async function writeVirtualBackofficeExtensionFiles(model, codegenDir) {
|
|
|
18120
18160
|
virtualEntrypoint,
|
|
18121
18161
|
defaultOutdent`
|
|
18122
18162
|
---
|
|
18123
|
-
import Component from '${originalEntrypoint}';
|
|
18163
|
+
import Component from '${toRelativePath2(virtualEntrypoint, originalEntrypoint)}';
|
|
18124
18164
|
---
|
|
18125
18165
|
|
|
18126
18166
|
<div>
|
|
@@ -18136,13 +18176,13 @@ function resolveEntry(component) {
|
|
|
18136
18176
|
BackofficeModal: () => "modal.tsx",
|
|
18137
18177
|
BackofficePage: () => "page.tsx"
|
|
18138
18178
|
});
|
|
18139
|
-
return
|
|
18179
|
+
return join4(component.directory, entryName);
|
|
18140
18180
|
}
|
|
18141
18181
|
|
|
18142
18182
|
// src/utils/writeVirtualServicePluginExtensionFiles.ts
|
|
18143
18183
|
init_esm_shims();
|
|
18144
18184
|
import { rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
|
|
18145
|
-
import { join as
|
|
18185
|
+
import { join as join5, resolve as resolve2 } from "node:path";
|
|
18146
18186
|
async function writeVirtualServicePluginExtensionFiles(model, codegenDir) {
|
|
18147
18187
|
const servicePluginComponents = model.components.filter(
|
|
18148
18188
|
isValidServicePluginComponent
|
|
@@ -18158,11 +18198,11 @@ async function writeVirtualServicePluginExtensionFiles(model, codegenDir) {
|
|
|
18158
18198
|
if (hasMatchingSourceFile) {
|
|
18159
18199
|
continue;
|
|
18160
18200
|
}
|
|
18161
|
-
await rm2(
|
|
18201
|
+
await rm2(join5(codegenDir, filename));
|
|
18162
18202
|
}
|
|
18163
18203
|
for (const component of servicePluginComponents) {
|
|
18164
18204
|
const originalEntrypoint = resolve2(component.directory, "plugin.ts");
|
|
18165
|
-
const virtualEntrypoint =
|
|
18205
|
+
const virtualEntrypoint = join5(
|
|
18166
18206
|
codegenDir,
|
|
18167
18207
|
`${component.manifest.compId}.ts`
|
|
18168
18208
|
);
|
|
@@ -18186,7 +18226,7 @@ async function writeVirtualServicePluginExtensionFiles(model, codegenDir) {
|
|
|
18186
18226
|
|
|
18187
18227
|
client.enableContext('global');
|
|
18188
18228
|
|
|
18189
|
-
await import('${originalEntrypoint}');
|
|
18229
|
+
await import('${toRelativePath2(virtualEntrypoint, originalEntrypoint)}');
|
|
18190
18230
|
|
|
18191
18231
|
if (olderClient) {
|
|
18192
18232
|
olderClient.enableContext('global');
|
|
@@ -18203,7 +18243,7 @@ async function writeVirtualServicePluginExtensionFiles(model, codegenDir) {
|
|
|
18203
18243
|
// src/utils/writeVirtualWebhookExtensionFiles.ts
|
|
18204
18244
|
init_esm_shims();
|
|
18205
18245
|
import { rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
|
|
18206
|
-
import { join as
|
|
18246
|
+
import { join as join6, resolve as resolve3 } from "node:path";
|
|
18207
18247
|
async function writeVirtualWebhookExtensionFiles(model, codegenDir) {
|
|
18208
18248
|
const webhookComponents = model.components.filter(isValidWebhookComponent);
|
|
18209
18249
|
const existingFiles = await globby(`*.ts`, {
|
|
@@ -18217,11 +18257,11 @@ async function writeVirtualWebhookExtensionFiles(model, codegenDir) {
|
|
|
18217
18257
|
if (hasMatchingSourceFile) {
|
|
18218
18258
|
continue;
|
|
18219
18259
|
}
|
|
18220
|
-
await rm3(
|
|
18260
|
+
await rm3(join6(codegenDir, filename));
|
|
18221
18261
|
}
|
|
18222
18262
|
for (const component of webhookComponents) {
|
|
18223
18263
|
const originalEntrypoint = resolve3(component.directory, "event.ts");
|
|
18224
|
-
const virtualEntrypoint =
|
|
18264
|
+
const virtualEntrypoint = join6(
|
|
18225
18265
|
codegenDir,
|
|
18226
18266
|
`${component.manifest.compId}.ts`
|
|
18227
18267
|
);
|
|
@@ -18245,7 +18285,7 @@ async function writeVirtualWebhookExtensionFiles(model, codegenDir) {
|
|
|
18245
18285
|
|
|
18246
18286
|
client.enableContext('global');
|
|
18247
18287
|
|
|
18248
|
-
await import('${originalEntrypoint}');
|
|
18288
|
+
await import('${toRelativePath2(virtualEntrypoint, originalEntrypoint)}');
|
|
18249
18289
|
|
|
18250
18290
|
if (olderClient) {
|
|
18251
18291
|
olderClient.enableContext('global');
|
|
@@ -18271,10 +18311,10 @@ var createIntegration = () => {
|
|
|
18271
18311
|
const appManifest = generateAppManifest(model);
|
|
18272
18312
|
const outDir = fileURLToPath3(_config.outDir);
|
|
18273
18313
|
const rootDir = fileURLToPath3(_config.root);
|
|
18274
|
-
const appManifestPath =
|
|
18314
|
+
const appManifestPath = join7(outDir, "_wix/app-manifest.json");
|
|
18275
18315
|
await writeJson(appManifestPath, appManifest, { spaces: 2 });
|
|
18276
18316
|
await writeJson(
|
|
18277
|
-
|
|
18317
|
+
join7(rootDir, GIT_IGNORED_DIR, "build-metadata.json"),
|
|
18278
18318
|
await resolveBuildMetadata(appManifestPath, _config),
|
|
18279
18319
|
{ spaces: 2 }
|
|
18280
18320
|
);
|
|
@@ -18347,10 +18387,14 @@ var createIntegration = () => {
|
|
|
18347
18387
|
service: passthroughImageService()
|
|
18348
18388
|
},
|
|
18349
18389
|
vite: {
|
|
18350
|
-
plugins: [
|
|
18390
|
+
plugins: [
|
|
18391
|
+
patchGlobal(),
|
|
18392
|
+
patchAstroInlineScripts(),
|
|
18393
|
+
setupSsrContext(rootDir)
|
|
18394
|
+
]
|
|
18351
18395
|
}
|
|
18352
18396
|
});
|
|
18353
|
-
const webhookCodegenDir =
|
|
18397
|
+
const webhookCodegenDir = join7(codegenDir, "extensions/webhooks");
|
|
18354
18398
|
await outputDir(webhookCodegenDir);
|
|
18355
18399
|
if (command === "dev") {
|
|
18356
18400
|
injectRoute({
|
|
@@ -18374,7 +18418,7 @@ var createIntegration = () => {
|
|
|
18374
18418
|
isValidWebhookComponent
|
|
18375
18419
|
);
|
|
18376
18420
|
for (const component of webhookComponents) {
|
|
18377
|
-
const virtualEntrypoint =
|
|
18421
|
+
const virtualEntrypoint = join7(
|
|
18378
18422
|
webhookCodegenDir,
|
|
18379
18423
|
`${component.manifest.compId}.ts`
|
|
18380
18424
|
);
|
|
@@ -18385,7 +18429,7 @@ var createIntegration = () => {
|
|
|
18385
18429
|
}
|
|
18386
18430
|
}
|
|
18387
18431
|
await writeVirtualWebhookExtensionFiles(model, webhookCodegenDir);
|
|
18388
|
-
const servicePluginCodegenDir =
|
|
18432
|
+
const servicePluginCodegenDir = join7(
|
|
18389
18433
|
codegenDir,
|
|
18390
18434
|
"extensions/service-plugins"
|
|
18391
18435
|
);
|
|
@@ -18415,7 +18459,7 @@ var createIntegration = () => {
|
|
|
18415
18459
|
isValidServicePluginComponent
|
|
18416
18460
|
);
|
|
18417
18461
|
for (const component of servicePluginComponents) {
|
|
18418
|
-
const virtualEntrypoint =
|
|
18462
|
+
const virtualEntrypoint = join7(
|
|
18419
18463
|
servicePluginCodegenDir,
|
|
18420
18464
|
`${component.manifest.compId}.ts`
|
|
18421
18465
|
);
|
|
@@ -18429,7 +18473,7 @@ var createIntegration = () => {
|
|
|
18429
18473
|
model,
|
|
18430
18474
|
servicePluginCodegenDir
|
|
18431
18475
|
);
|
|
18432
|
-
const backofficeCodegenDir =
|
|
18476
|
+
const backofficeCodegenDir = join7(codegenDir, "extensions/backoffice");
|
|
18433
18477
|
await outputDir(backofficeCodegenDir);
|
|
18434
18478
|
if (command === "dev") {
|
|
18435
18479
|
injectRoute({
|
|
@@ -18453,7 +18497,7 @@ var createIntegration = () => {
|
|
|
18453
18497
|
isValidBackofficeComponent
|
|
18454
18498
|
);
|
|
18455
18499
|
for (const component of backofficeComponents) {
|
|
18456
|
-
const virtualEntrypoint =
|
|
18500
|
+
const virtualEntrypoint = join7(
|
|
18457
18501
|
backofficeCodegenDir,
|
|
18458
18502
|
`${component.manifest.compId}.astro`
|
|
18459
18503
|
);
|