@osimart/create-storefront 1.0.4 → 1.0.7

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/app/app.vue CHANGED
@@ -4,12 +4,28 @@ import "#osi/assets/css/osi-controls.css";
4
4
  import { parseIds } from "#osi/utils/analytics";
5
5
 
6
6
  const { load, dir, store, error } = useStorefront();
7
+ // Captured before the first await (the request event needs Nuxt's context).
8
+ const requestEvent = import.meta.server ? useRequestEvent() : null;
7
9
  const { tokens, rootClasses, fontLinks } = useThemeTokens();
8
10
  const { start: startBuilderPreview, stop: stopBuilderPreview } = useBuilderPreview();
9
11
 
10
12
  const { error: fetchError } = await useAsyncData("storefront", () => load());
11
13
  const shown = computed(() => error.value ?? fetchError.value ?? null);
12
14
 
15
+ const unavailableStatus = computed(() => {
16
+ const e = shown.value;
17
+ if (!e) return null;
18
+ const status = Number(e.status ?? e.statusCode) || 0;
19
+ return status >= 400 && status < 500 ? status : 503;
20
+ });
21
+ if (requestEvent && unavailableStatus.value) {
22
+ setResponseStatus(requestEvent, unavailableStatus.value);
23
+ }
24
+
25
+ const publicConfig = useRuntimeConfig().public;
26
+ const osimartUrl = String(publicConfig.osimartUrl || "https://osimart.com").replace(/\/+$/, "");
27
+ const signupUrl = publicConfig.osimartSignupUrl || `${osimartUrl}/`;
28
+
13
29
  const isDev = import.meta.dev;
14
30
 
15
31
  onMounted(() => {
@@ -39,6 +55,8 @@ onBeforeUnmount(() => {
39
55
  useThemeSeo();
40
56
 
41
57
  useHead({
58
+ title: computed(() => (shown.value ? "Store unavailable" : undefined)),
59
+ meta: computed(() => (shown.value ? [{ name: "robots", content: "noindex" }] : [])),
42
60
  htmlAttrs: computed(() => ({ dir: dir.value })),
43
61
  noscript: computed(() =>
44
62
  parseIds(store.value?.meta_pixel_id, "pixel").map((id) => ({
@@ -46,10 +64,14 @@ useHead({
46
64
  innerHTML: `<img height="1" width="1" style="display:none" alt="" src="https://www.facebook.com/tr?id=${id}&ev=PageView&noscript=1" />`,
47
65
  })),
48
66
  ),
49
- bodyAttrs: computed(() => ({
50
- style: tokens.value,
51
- class: rootClasses.value.filter((c) => /^osi-(btns|inputs|labels)/.test(c)),
52
- })),
67
+ bodyAttrs: computed(() =>
68
+ shown.value
69
+ ? { class: "osi-unavailable-body" }
70
+ : {
71
+ style: tokens.value,
72
+ class: rootClasses.value.filter((c) => /^osi-(btns|inputs|labels)/.test(c)),
73
+ }
74
+ ),
53
75
  // A getter, not a snapshot: a font picked in the editor (or a theme that
54
76
  // loads later) must add its stylesheet.
55
77
  link: computed(() => [
@@ -63,13 +85,17 @@ useHead({
63
85
  </script>
64
86
 
65
87
  <template>
66
- <div v-if="shown" class="osi-fatal">
67
- <p>This store isn't available right now.</p>
88
+ <main v-if="shown" class="osi-unavailable" dir="ltr">
89
+ <a :href="osimartUrl" class="osi-unavailable-back">
90
+ <span aria-hidden="true">&larr;</span>
91
+ Osimart
92
+ </a>
93
+ <h1 class="osi-unavailable-title">This store is currently unavailable.</h1>
94
+ <a :href="signupUrl" class="osi-unavailable-cta">Start a free trial</a>
68
95
 
69
-
70
96
  <pre v-if="isDev" class="osi-fatal-detail">{{ shown.status ? `HTTP ${shown.status} — ` : "" }}{{ shown.message }}<template v-if="shown.data">
71
97
  {{ shown.data }}</template></pre>
72
- </div>
98
+ </main>
73
99
 
74
100
  <div v-else class="osi-root" :class="rootClasses" :style="tokens" :dir="dir">
75
101
  <NuxtLoadingIndicator
@@ -134,14 +160,74 @@ body .font-thoren {
134
160
  body .font-heading {
135
161
  font-family: var(--osi-font-heading);
136
162
  }
137
- .osi-fatal {
138
- padding: 4rem 1rem;
163
+ /* ---- Store unavailable (Shopify-style) — no theme tokens on purpose. */
164
+ body.osi-unavailable-body {
165
+ margin: 0;
166
+ background: #20336b;
167
+ }
168
+ .osi-unavailable {
169
+ min-height: 100vh;
170
+ min-height: 100dvh;
171
+ box-sizing: border-box;
172
+ display: flex;
173
+ flex-direction: column;
174
+ align-items: center;
175
+ padding: clamp(5rem, 18vh, 10.5rem) 1.5rem 4rem;
176
+ background: #20336b;
177
+ color: #fff;
139
178
  text-align: center;
140
- font-family: system-ui, sans-serif;
179
+ font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
180
+ -webkit-font-smoothing: antialiased;
181
+ }
182
+ .osi-unavailable a {
183
+ color: inherit;
184
+ text-decoration: none;
185
+ }
186
+ .osi-unavailable-back {
187
+ display: inline-flex;
188
+ align-items: center;
189
+ gap: 0.6rem;
190
+ font-size: 1.25rem;
191
+ line-height: 1;
192
+ opacity: 0.95;
193
+ transition: opacity 0.15s ease;
194
+ }
195
+ .osi-unavailable-back:hover {
196
+ opacity: 0.7;
197
+ }
198
+ .osi-unavailable-title {
199
+ margin: 2.25rem 0 0;
200
+ max-width: 18ch;
201
+ font-size: clamp(2.5rem, 5.6vw, 4.75rem);
202
+ font-weight: 400;
203
+ line-height: 1.05;
204
+ letter-spacing: -0.035em;
205
+ text-wrap: balance;
206
+ }
207
+ @media (min-width: 900px) {
208
+ .osi-unavailable-title {
209
+ max-width: none;
210
+ }
211
+ }
212
+ .osi-unavailable-cta {
213
+ margin-top: 1.75rem;
214
+ padding-bottom: 0.15rem;
215
+ font-size: 1.375rem;
216
+ line-height: 1.3;
217
+ border-bottom: 2px solid currentColor;
218
+ transition: opacity 0.15s ease;
219
+ }
220
+ .osi-unavailable-cta:hover {
221
+ opacity: 0.75;
222
+ }
223
+ .osi-unavailable :focus-visible {
224
+ outline: 2px solid #fff;
225
+ outline-offset: 4px;
226
+ border-radius: 2px;
141
227
  }
142
228
  .osi-fatal-detail {
143
229
  display: inline-block;
144
- margin-top: 1rem;
230
+ margin-top: 3rem;
145
231
  padding: 0.75rem 1rem;
146
232
  text-align: start;
147
233
  background: #fef2f2;
@@ -16,7 +16,9 @@ defineProps({
16
16
  // Hover / selection outlines are drawn by BuilderOverlay (pages/__builder-preview),
17
17
  // not here: a CSS outline gets clipped by overflow, can't carry a name tag or
18
18
  // buttons, and a nested block's outline would fight its section's.
19
- const { isPreview } = useBuilderPreview();
19
+ //
20
+ // A hidden section (disabled) isn't rendered at all — in the editor's preview
21
+ // too, like Shopify — so the preview shows exactly what the live store will.
20
22
  </script>
21
23
 
22
24
  <template>
@@ -24,11 +26,10 @@ const { isPreview } = useBuilderPreview();
24
26
  <template v-for="(section, i) in sections" :key="section.key">
25
27
  <component
26
28
  :is="resolveSection(section.type)"
27
- v-if="resolveSection(section.type)"
29
+ v-if="!section.disabled && resolveSection(section.type)"
28
30
  :section="section"
29
31
  :index="i"
30
32
  :data-osi-section="section.key"
31
- :class="{ 'osi-preview-disabled': isPreview && section.disabled }"
32
33
  />
33
34
  </template>
34
35
  </div>
@@ -38,9 +39,4 @@ const { isPreview } = useBuilderPreview();
38
39
  .osi-sections > :deep(*) + :deep(*) {
39
40
  margin-top: 0;
40
41
  }
41
-
42
- /* Editor only — never rendered on a live storefront. */
43
- .osi-preview-disabled {
44
- opacity: 0.45;
45
- }
46
42
  </style>
@@ -238,9 +238,18 @@ export function useContentTree(section, options = {}) {
238
238
  const HEADINGS = ["H1", "H2", "H3", "H4", "H5", "H6"];
239
239
 
240
240
  const plain = (html) => String(html || "").replace(/<(img|video|iframe)\b/gi, "x").replace(/<[^>]*>/g, "").replace(/&nbsp;/g, " ").trim();
241
- // A heading preset renders as <hN>: its richtext paragraphs become lines.
241
+ // A heading preset renders as <hN>, which can't hold blocks: the editor's
242
+ // paragraphs, headings and list items become lines (<br>) inside it.
243
+ // Inline formatting (<b>, <i>, <a>, …) is kept.
242
244
  const inline = (html) =>
243
- String(html).replace(/<\/p>\s*<p[^>]*>/gi, "<br>").replace(/^\s*<p[^>]*>/i, "").replace(/<\/p>\s*$/i, "");
245
+ String(html)
246
+ .replace(/<(p|h[1-6]|li)\b[^>]*>\s*<br\s*\/?>\s*<\/\1>/gi, "<$1></$1>") // a blank line = one <br>
247
+ .replace(/<\/?(ul|ol)\b[^>]*>/gi, "")
248
+ .replace(/<(p|h[1-6]|li|blockquote|div)\b[^>]*>/gi, "")
249
+ .replace(/<\/(p|h[1-6]|li|blockquote|div)>/gi, "<br>")
250
+ .replace(/^(\s*<br\s*\/?>)+/i, "")
251
+ .replace(/(<br\s*\/?>\s*)+$/i, "")
252
+ .trim();
244
253
 
245
254
  /* ------------------------------------------------------------ the tree */
246
255
 
@@ -47,6 +47,7 @@ const API_ROOT = storeApiBase
47
47
  console.log("storedataaaaa", bootstrapData.value);
48
48
  } catch (error) {
49
49
  console.error('[useStoreInit] Failed to fetch bootstrap data:', error);
50
+ throw error;
50
51
  }
51
52
 
52
53
  return bootstrapData.value;
@@ -22,6 +22,13 @@ const FOOTER_APPEARANCE = [
22
22
  "FOOTER_LINK_COLOR", "FOOTER_LINK_HOVER_COLOR",
23
23
  ];
24
24
 
25
+ function unavailable(status, message) {
26
+ const err = new Error(message);
27
+ err.status = status;
28
+ err.code = "STORE_UNAVAILABLE";
29
+ return err;
30
+ }
31
+
25
32
  /** Menus arrive as a map keyed by handle from bootstrap, and as a plain list
26
33
  * from the dashboard's MENUS message. Normalize to the map either way. */
27
34
  function menusAsMap(value) {
@@ -120,8 +127,7 @@ export function useStorefront() {
120
127
 
121
128
  // The bar's own on / off is now "is the section there (and shown)".
122
129
  const bar = chrome.find((s) => s.type === "ANNOUNCEMENT_BAR");
123
- out.ANNOUNCEMENT_ENABLED =
124
- !!bar && (!bar.disabled || !!previewState.value);
130
+ out.ANNOUNCEMENT_ENABLED = !!bar && !bar.disabled;
125
131
  return out;
126
132
  });
127
133
 
@@ -185,7 +191,14 @@ export function useStorefront() {
185
191
  // and derives baseUrl from the store's username in the response. Reuse
186
192
  // that payload instead of firing a second, redundant bootstrap request.
187
193
  if (!bootstrapData.value) await init();
188
- data.value = bootstrapData.value;
194
+ const payload = bootstrapData.value;
195
+
196
+ if (!payload?.store) throw unavailable(404, "No store for this address");
197
+ if (payload.store.is_active === false || payload.store.available === false) {
198
+ throw unavailable(402, "This store is currently unavailable");
199
+ }
200
+
201
+ data.value = payload;
189
202
 
190
203
  const available = data.value?.store?.locales ?? ["en"];
191
204
  if (!available.includes(locale.value)) {
@@ -39,13 +39,13 @@ export default function useLogic() {
39
39
  const { sectionGroups } = useStorefront();
40
40
  const { isPreview } = useBuilderPreview();
41
41
  const headerSections = computed(() => {
42
- const list = (sectionGroups.value?.header ?? []).filter((s) => isPreview.value || !s.disabled);
42
+ const list = (sectionGroups.value?.header ?? []).filter((s) => !s.disabled);
43
43
  if (chrome.value === "bare") return [];
44
44
  return chrome.value === "minimal" ? list.filter((s) => s.type === "HEADER") : list;
45
45
  });
46
46
  const footerSections = computed(() =>
47
47
  chrome.value === "full"
48
- ? (sectionGroups.value?.footer ?? []).filter((s) => isPreview.value || !s.disabled)
48
+ ? (sectionGroups.value?.footer ?? []).filter((s) => !s.disabled)
49
49
  : []
50
50
  );
51
51
 
@@ -471,9 +471,14 @@ export default {
471
471
  confirmPassword: "",
472
472
  };
473
473
 
474
- for (const messages of Object.values(apiErrors)) {
475
- errorMessages.push(...messages);
476
- }
474
+ const collect = (v) =>
475
+ typeof v === "string"
476
+ ? [v]
477
+ : v && typeof v === "object"
478
+ ? Object.values(v).flatMap(collect)
479
+ : [];
480
+
481
+ errorMessages.push(...collect(apiErrors));
477
482
 
478
483
  // Display errors in toast
479
484
  if (errorMessages.length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimart/create-storefront",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "Osimart storefront platform — logic, platform pages and CLI; extended by every theme repo",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",