@wix/astro 1.0.16 → 1.0.18

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.
Files changed (40) hide show
  1. package/build/index.d.ts +3 -1
  2. package/build/index.js +62 -10
  3. package/build/index.js.map +1 -1
  4. package/build-browser-runtime/{chunk-HJBVRKIZ.js → setup.js} +13 -5
  5. package/build-runtime/chunk-C3QOE2TZ.js +7 -0
  6. package/build-runtime/chunk-HVACFX6T.js +18 -0
  7. package/build-runtime/chunk-UZPSWWI5.js +13 -0
  8. package/build-runtime/chunk-YMZMZCBN.js +4063 -0
  9. package/build-runtime/context/non-elevated.js +26 -14
  10. package/build-runtime/middleware/auth.js +6 -18
  11. package/build-runtime/routes/auth/callback.d.ts +5 -0
  12. package/build-runtime/routes/auth/callback.js +48 -0
  13. package/build-runtime/routes/auth/login.d.ts +5 -0
  14. package/build-runtime/routes/auth/login.js +38 -0
  15. package/build-runtime/routes/auth/logout-callback.d.ts +5 -0
  16. package/build-runtime/routes/auth/logout-callback.js +20 -0
  17. package/build-runtime/routes/auth/logout.d.ts +5 -0
  18. package/build-runtime/routes/auth/logout.js +17 -0
  19. package/package.json +8 -6
  20. package/src/constants.ts +2 -0
  21. package/src/context/non-elevated.ts +31 -9
  22. package/src/context/setup.ts +14 -0
  23. package/src/context/utils.ts +0 -4
  24. package/src/directories.ts +1 -1
  25. package/src/env.d.ts +2 -0
  26. package/src/index.ts +48 -4
  27. package/src/plugins/setupSsrContext.ts +9 -7
  28. package/src/routes/auth/callback.ts +49 -0
  29. package/src/routes/auth/login.ts +35 -0
  30. package/src/routes/auth/logout-callback.ts +16 -0
  31. package/src/routes/auth/logout.ts +14 -0
  32. package/src/utils/contextualAuth.ts +4 -0
  33. package/src/utils/writeVirtualBackofficeExtensionFiles.ts +18 -2
  34. package/tsup.config.mjs +13 -7
  35. package/build-browser-runtime/before-hydration.js +0 -24
  36. package/build-browser-runtime/page.d.ts +0 -5
  37. package/build-browser-runtime/page.js +0 -14
  38. package/src/context/before-hydration.ts +0 -21
  39. package/src/context/page.ts +0 -7
  40. /package/build-browser-runtime/{before-hydration.d.ts → setup.d.ts} +0 -0
package/build/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { AstroIntegration } from 'astro';
2
2
 
3
- declare const createIntegration: () => AstroIntegration;
3
+ declare const createIntegration: (options?: {
4
+ enableAuthRoutes?: boolean;
5
+ }) => AstroIntegration;
4
6
 
5
7
  export { createIntegration as default };
package/build/index.js CHANGED
@@ -12471,8 +12471,7 @@ function patchGlobal() {
12471
12471
  // src/plugins/setupSsrContext.ts
12472
12472
  init_esm_shims();
12473
12473
  import { extname, join as join2 } from "node:path";
12474
- function setupSsrContext(rootDir) {
12475
- const srcDir = join2(rootDir, SRC_DIR);
12474
+ function setupSsrContext() {
12476
12475
  const nonElevatedSetupUrl = new URL(
12477
12476
  "../build-runtime/context/non-elevated.js",
12478
12477
  import.meta.url
@@ -12487,10 +12486,14 @@ function setupSsrContext(rootDir) {
12487
12486
  },
12488
12487
  name: "setup-ssr-context",
12489
12488
  transform(code, id) {
12490
- if (!id.startsWith(srcDir)) {
12489
+ const extension = extname(id);
12490
+ if (
12491
+ // ignore node_modules
12492
+ id.includes("node_modules") && // but allow injected runtime
12493
+ !id.includes(join2("node_modules", "@wix", "astro"))
12494
+ ) {
12491
12495
  return null;
12492
12496
  }
12493
- const extension = extname(id);
12494
12497
  if (extension !== ".js" && extension !== ".astro" && extension !== ".ts" && extension !== ".tsx") {
12495
12498
  return null;
12496
12499
  }
@@ -18152,6 +18155,19 @@ async function writeVirtualBackofficeExtensionFiles(model, codegenDir) {
18152
18155
  for (const component of backofficeComponents) {
18153
18156
  const entryFilename = resolveEntry(component);
18154
18157
  const originalEntrypoint = resolve(model.rootDir, entryFilename);
18158
+ const virtualHocEntrypoint = join4(
18159
+ codegenDir,
18160
+ `hoc_${component.manifest.compId}.tsx`
18161
+ );
18162
+ await writeFile2(
18163
+ virtualHocEntrypoint,
18164
+ defaultOutdent`
18165
+ import Component from '${toRelativePath2(virtualHocEntrypoint, originalEntrypoint)}';
18166
+ import { withContextualWixClient } from '@wix/dashboard/internal';
18167
+
18168
+ export const WrappedComponent = withContextualWixClient(Component);
18169
+ `
18170
+ );
18155
18171
  const virtualEntrypoint = join4(
18156
18172
  codegenDir,
18157
18173
  `${component.manifest.compId}.astro`
@@ -18160,11 +18176,11 @@ async function writeVirtualBackofficeExtensionFiles(model, codegenDir) {
18160
18176
  virtualEntrypoint,
18161
18177
  defaultOutdent`
18162
18178
  ---
18163
- import Component from '${toRelativePath2(virtualEntrypoint, originalEntrypoint)}';
18179
+ import { WrappedComponent } from '${toRelativePath2(virtualEntrypoint, virtualHocEntrypoint)}';
18164
18180
  ---
18165
18181
 
18166
18182
  <div>
18167
- <Component client:only="react" />
18183
+ <WrappedComponent client:only="react" />
18168
18184
  </div>
18169
18185
  `
18170
18186
  );
@@ -18301,7 +18317,9 @@ async function writeVirtualWebhookExtensionFiles(model, codegenDir) {
18301
18317
  }
18302
18318
 
18303
18319
  // src/index.ts
18304
- var createIntegration = () => {
18320
+ var createIntegration = (options = {
18321
+ enableAuthRoutes: true
18322
+ }) => {
18305
18323
  let _config;
18306
18324
  let model = null;
18307
18325
  return {
@@ -18340,7 +18358,7 @@ var createIntegration = () => {
18340
18358
  "before-hydration",
18341
18359
  defaultOutdent`
18342
18360
  import { WIX_CLIENT_ID } from 'astro:env/client';
18343
- import { setup } from '@wix/astro/context/before-hydration';
18361
+ import { setup } from '@wix/astro/context/setup';
18344
18362
 
18345
18363
  setup({ clientId: WIX_CLIENT_ID });
18346
18364
  `
@@ -18349,7 +18367,7 @@ var createIntegration = () => {
18349
18367
  "page",
18350
18368
  defaultOutdent`
18351
18369
  import { WIX_CLIENT_ID } from 'astro:env/client';
18352
- import { setup } from '@wix/astro/context/page';
18370
+ import { setup } from '@wix/astro/context/setup';
18353
18371
 
18354
18372
  setup({ clientId: WIX_CLIENT_ID });
18355
18373
  `
@@ -18390,10 +18408,44 @@ var createIntegration = () => {
18390
18408
  plugins: [
18391
18409
  patchGlobal(),
18392
18410
  patchAstroInlineScripts(),
18393
- setupSsrContext(rootDir)
18411
+ setupSsrContext()
18394
18412
  ]
18395
18413
  }
18396
18414
  });
18415
+ if (options.enableAuthRoutes) {
18416
+ injectRoute({
18417
+ entrypoint: new URL(
18418
+ "../build-runtime/routes/auth/login.js",
18419
+ import.meta.url
18420
+ ),
18421
+ pattern: "/api/auth/login",
18422
+ prerender: false
18423
+ });
18424
+ injectRoute({
18425
+ entrypoint: new URL(
18426
+ "../build-runtime/routes/auth/logout.js",
18427
+ import.meta.url
18428
+ ),
18429
+ pattern: "/api/auth/logout",
18430
+ prerender: false
18431
+ });
18432
+ injectRoute({
18433
+ entrypoint: new URL(
18434
+ "../build-runtime/routes/auth/callback.js",
18435
+ import.meta.url
18436
+ ),
18437
+ pattern: "/api/auth/callback",
18438
+ prerender: false
18439
+ });
18440
+ injectRoute({
18441
+ entrypoint: new URL(
18442
+ "../build-runtime/routes/auth/logout-callback.js",
18443
+ import.meta.url
18444
+ ),
18445
+ pattern: "/api/auth/logout-callback",
18446
+ prerender: false
18447
+ });
18448
+ }
18397
18449
  const webhookCodegenDir = join7(codegenDir, "extensions/webhooks");
18398
18450
  await outputDir(webhookCodegenDir);
18399
18451
  if (command === "dev") {