@ampless/admin 0.2.0-alpha.1 → 0.2.0-alpha.3

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.
@@ -507,22 +507,22 @@ function translate(dict, key, vars) {
507
507
 
508
508
  // src/lib/media.ts
509
509
  var state = { outputs: null, cmsConfig: null };
510
- function setAdminMediaContext(outputs, cmsConfig2) {
510
+ function setAdminMediaContext(outputs, cmsConfig) {
511
511
  state.outputs = outputs;
512
- state.cmsConfig = cmsConfig2;
512
+ state.cmsConfig = cmsConfig;
513
513
  }
514
514
  function publicMediaUrl(input) {
515
515
  if (/^https?:\/\//.test(input)) return input;
516
516
  let path = input.replace(/^\/+/, "");
517
517
  if (path.startsWith("public/")) path = path.slice("public/".length);
518
- const { outputs, cmsConfig: cmsConfig2 } = state;
519
- const delivery = cmsConfig2?.media?.delivery ?? "nextjs";
518
+ const { outputs, cmsConfig } = state;
519
+ const delivery = cmsConfig?.media?.delivery ?? "nextjs";
520
520
  if (delivery !== "s3-direct") return `/api/media/${path}`;
521
521
  const storage = outputs?.storage;
522
522
  if (!storage) return `/api/media/${path}`;
523
523
  return `https://${storage.bucket_name}.s3.${storage.aws_region}.amazonaws.com/public/${path}`;
524
524
  }
525
- function createMedia(outputs, cmsConfig2) {
525
+ function createMedia(outputs, cmsConfig) {
526
526
  const storage = outputs.storage;
527
527
  function s3DirectUrl(path) {
528
528
  if (!storage) return `/api/media/${path}`;
@@ -532,35 +532,14 @@ function createMedia(outputs, cmsConfig2) {
532
532
  if (/^https?:\/\//.test(input)) return input;
533
533
  let path = input.replace(/^\/+/, "");
534
534
  if (path.startsWith("public/")) path = path.slice("public/".length);
535
- const delivery = cmsConfig2.media?.delivery ?? "nextjs";
535
+ const delivery = cmsConfig.media?.delivery ?? "nextjs";
536
536
  return delivery === "s3-direct" ? s3DirectUrl(path) : `/api/media/${path}`;
537
537
  }
538
538
  return { publicMediaUrl: urlFor };
539
539
  }
540
540
 
541
- // src/lib/admin-site-client.ts
542
- import { DEFAULT_SITE_ID, isMultiSite } from "ampless";
541
+ // src/lib/admin-site-cookie.ts
543
542
  var ADMIN_SITE_COOKIE = "admin-site-id";
544
- var cmsConfig = null;
545
- function setAdminCmsConfig(config) {
546
- cmsConfig = config;
547
- }
548
- function readAdminSiteIdFromCookie() {
549
- if (!cmsConfig) return DEFAULT_SITE_ID;
550
- if (!isMultiSite(cmsConfig)) return DEFAULT_SITE_ID;
551
- const sites = cmsConfig.sites ?? {};
552
- if (typeof document !== "undefined") {
553
- const match = document.cookie.match(
554
- new RegExp(`(?:^|;\\s*)${ADMIN_SITE_COOKIE}=([^;]+)`)
555
- );
556
- if (match) {
557
- const v = decodeURIComponent(match[1]);
558
- if (sites[v]) return v;
559
- }
560
- }
561
- const first = Object.keys(sites)[0];
562
- return first ?? DEFAULT_SITE_ID;
563
- }
564
543
 
565
544
  export {
566
545
  resolveLocale,
@@ -569,7 +548,5 @@ export {
569
548
  setAdminMediaContext,
570
549
  publicMediaUrl,
571
550
  createMedia,
572
- ADMIN_SITE_COOKIE,
573
- setAdminCmsConfig,
574
- readAdminSiteIdFromCookie
551
+ ADMIN_SITE_COOKIE
575
552
  };