@superwall/studio 1.1.1 → 1.3.0-beta.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.
Files changed (78) hide show
  1. package/README.md +61 -11
  2. package/dist/assets/index-DyLb5fiB.js +11 -0
  3. package/dist/assets/index-_HCp6gCi.css +1 -0
  4. package/dist/index.html +2 -2
  5. package/dist/lib/StudioApp.d.ts +6 -0
  6. package/dist/lib/components/OpenInApp.d.ts +5 -0
  7. package/dist/lib/components/PaywallToasts.d.ts +8 -0
  8. package/dist/lib/components/SurfaceCard.d.ts +11 -0
  9. package/dist/lib/components/chrome/StudioShell.d.ts +4 -0
  10. package/dist/lib/components/chrome/Toolbar.d.ts +6 -0
  11. package/dist/lib/components/chrome/TopBar.d.ts +8 -0
  12. package/dist/lib/components/controls.d.ts +24 -0
  13. package/dist/lib/components/icons.d.ts +18 -0
  14. package/dist/lib/components/menus/ActionMenu.d.ts +14 -0
  15. package/dist/lib/components/menus/CompareMenu.d.ts +13 -0
  16. package/dist/lib/components/panels/MissingProducts.d.ts +8 -0
  17. package/dist/lib/components/panels/SidePanel.d.ts +6 -0
  18. package/dist/lib/components/panels/VariablesPanel.d.ts +13 -0
  19. package/dist/lib/components/preview/DeviceChrome.d.ts +12 -0
  20. package/dist/lib/components/preview/DeviceFrame.d.ts +21 -0
  21. package/dist/lib/components/preview/HostedIframe.d.ts +7 -0
  22. package/dist/lib/icon.svg +5 -0
  23. package/dist/lib/index.d.ts +20 -0
  24. package/dist/lib/index.js +2268 -0
  25. package/dist/lib/lib/actions.d.ts +4 -0
  26. package/dist/lib/lib/contract.d.ts +33 -0
  27. package/dist/lib/lib/devices.d.ts +26 -0
  28. package/dist/lib/lib/host.d.ts +15 -0
  29. package/dist/lib/lib/notices.d.ts +9 -0
  30. package/dist/lib/lib/preview.d.ts +5 -0
  31. package/dist/lib/lib/products.d.ts +16 -0
  32. package/dist/lib/lib/project.d.ts +13 -0
  33. package/dist/lib/lib/steps.d.ts +5 -0
  34. package/dist/lib/lib/surfaces.d.ts +35 -0
  35. package/dist/lib/lib/time.d.ts +1 -0
  36. package/dist/lib/lib/variables.d.ts +12 -0
  37. package/dist/lib/products.js +65 -0
  38. package/dist/lib/screens/SurfaceEditor.d.ts +9 -0
  39. package/dist/lib/screens/SurfaceList.d.ts +7 -0
  40. package/dist/lib/studio.css +1 -0
  41. package/package.json +19 -4
  42. package/src/StudioApp.tsx +8 -11
  43. package/src/components/PaywallToasts.tsx +162 -85
  44. package/src/components/SurfaceCard.tsx +9 -2
  45. package/src/components/chrome/StudioShell.tsx +12 -0
  46. package/src/components/icons.tsx +0 -13
  47. package/src/components/{ActionMenu.tsx → menus/ActionMenu.tsx} +4 -4
  48. package/src/components/{CompareMenu.tsx → menus/CompareMenu.tsx} +3 -3
  49. package/src/components/{SidePanel.tsx → panels/SidePanel.tsx} +1 -1
  50. package/src/components/{VariablesPanel.tsx → panels/VariablesPanel.tsx} +4 -4
  51. package/src/components/{DeviceChrome.tsx → preview/DeviceChrome.tsx} +1 -1
  52. package/src/components/{DeviceFrame.tsx → preview/DeviceFrame.tsx} +14 -55
  53. package/src/components/preview/HostedIframe.tsx +46 -0
  54. package/src/index.ts +26 -6
  55. package/src/lib/actions.ts +1 -1
  56. package/src/lib/contract.ts +30 -0
  57. package/src/lib/devices.ts +5 -4
  58. package/src/lib/host.ts +80 -0
  59. package/src/lib/notices.ts +63 -0
  60. package/src/lib/preview.ts +11 -33
  61. package/src/lib/products.ts +116 -0
  62. package/src/lib/project.ts +2 -1
  63. package/src/lib/steps.ts +20 -0
  64. package/src/lib/surfaces.ts +41 -0
  65. package/src/lib/time.ts +1 -2
  66. package/src/lib/variables.ts +13 -0
  67. package/src/main.tsx +3 -3
  68. package/src/screens/SurfaceEditor.tsx +97 -67
  69. package/src/screens/SurfaceList.tsx +17 -7
  70. package/src/styles.css +8 -6
  71. package/src/vite-env.d.ts +1 -0
  72. package/dist/assets/index-CVKGrx00.js +0 -11
  73. package/dist/assets/index-D4RIpSbg.css +0 -1
  74. package/src/lib/events.ts +0 -77
  75. package/src/lib/types.ts +0 -85
  76. /package/src/components/{Toolbar.tsx → chrome/Toolbar.tsx} +0 -0
  77. /package/src/components/{TopBar.tsx → chrome/TopBar.tsx} +0 -0
  78. /package/src/components/{MissingProducts.tsx → panels/MissingProducts.tsx} +0 -0
package/src/index.ts CHANGED
@@ -3,18 +3,38 @@ import "./styles.css";
3
3
  export { StudioApp } from "./StudioApp";
4
4
  export { SurfaceEditor } from "./screens/SurfaceEditor";
5
5
  export { SurfaceList } from "./screens/SurfaceList";
6
- export { DeviceFrame } from "./components/DeviceFrame";
7
- export { TopBar } from "./components/TopBar";
8
- export { VariablesPanel } from "./components/VariablesPanel";
6
+ export { DeviceFrame } from "./components/preview/DeviceFrame";
7
+ export { HostedIframe } from "./components/preview/HostedIframe";
8
+ export { PaywallToasts, createStudioDelegate, useStudioDelegate } from "./components/PaywallToasts";
9
+ export { StudioShell } from "./components/chrome/StudioShell";
10
+ export { TopBar } from "./components/chrome/TopBar";
11
+ export { VariablesPanel } from "./components/panels/VariablesPanel";
9
12
  export { Segmented, Select, Switch } from "./components/controls";
10
13
  export { DEFAULT_DEVICE_ID, deviceById, STUDIO_DEVICES } from "./lib/devices";
11
14
  export type { StudioDevice } from "./lib/devices";
12
- export { buildPreviewPath } from "./lib/preview";
15
+ export { hostStateFor, studioDefaults } from "./lib/host";
16
+ export {
17
+ createHostState,
18
+ diffHostState,
19
+ hasIntroductoryOffer,
20
+ silentDelegate,
21
+ type HostDelegate,
22
+ type HostProduct,
23
+ type HostState,
24
+ } from "@superwall/host";
25
+ export type { HostInputs } from "./lib/host";
26
+ export { buildPreviewPath, hostedUrl, snapshotPreviewUrl, surfacePath } from "./lib/preview";
13
27
  export { parseProjectPayload, type StudioProjectPayload } from "./lib/project";
14
28
  export type {
15
- PreviewOverrides,
29
+ AppScheme,
16
30
  PreviewUrlBuilder,
31
+ Samples,
32
+ StudioActionName,
33
+ StudioActionProgress,
34
+ StudioActionResult,
17
35
  StudioSource,
36
+ StudioStatus,
18
37
  StudioSurface,
19
38
  StudioSurfaceKind,
20
- } from "./lib/types";
39
+ } from "./lib/surfaces";
40
+ export type { SampleDefaults, VariableOverrides } from "./lib/variables";
@@ -5,7 +5,7 @@ import type {
5
5
  StudioActionResult,
6
6
  StudioStatus,
7
7
  StudioSurface,
8
- } from "./types";
8
+ } from "./surfaces";
9
9
 
10
10
  export const runAction = async (
11
11
  surface: StudioSurface,
@@ -0,0 +1,30 @@
1
+ export type StudioActionName = "push" | "promote" | "publish";
2
+
3
+ export type StudioActionResult =
4
+ | { ok: true; version: number; live: boolean }
5
+ | { ok: false; error: string };
6
+
7
+ export type StudioActionProgress = (step: string, state: "start" | "done") => void;
8
+
9
+ export type StudioStatus = {
10
+ paywallId?: string;
11
+ identifier?: string;
12
+ liveUrl?: string;
13
+ active?: boolean;
14
+ updatedAt?: string;
15
+ unreachable?: string;
16
+ };
17
+
18
+ export type Samples = {
19
+ device?: Record<string, unknown>;
20
+ user?: Record<string, unknown>;
21
+ products?: Record<string, Record<string, unknown>>;
22
+ live?: { device: boolean; user: boolean };
23
+ unreachable?: string;
24
+ };
25
+
26
+ export type AppScheme = {
27
+ scheme?: string;
28
+ source?: "dashboard" | "app";
29
+ blocksLocalNetworking?: string;
30
+ };
@@ -25,7 +25,7 @@ const IPHONE_ISLAND: DeviceChromeSpec = {
25
25
  homeIndicator: true,
26
26
  };
27
27
 
28
- export const STUDIO_DEVICES: readonly StudioDevice[] = [
28
+ export const STUDIO_DEVICES: readonly [StudioDevice, ...StudioDevice[]] = [
29
29
  {
30
30
  id: "iphone-se",
31
31
  name: "iPhone SE",
@@ -103,7 +103,8 @@ export const DEFAULT_DEVICE_ID = "iphone-17";
103
103
  export const RESPONSIVE_ID = "responsive";
104
104
  export const RESPONSIVE_DEFAULT = { width: 393, height: 852 };
105
105
 
106
+ const DEFAULT_DEVICE: StudioDevice =
107
+ STUDIO_DEVICES.find((device) => device.id === DEFAULT_DEVICE_ID) ?? STUDIO_DEVICES[0];
108
+
106
109
  export const deviceById = (id: string): StudioDevice =>
107
- STUDIO_DEVICES.find((device) => device.id === id) ??
108
- STUDIO_DEVICES.find((device) => device.id === DEFAULT_DEVICE_ID) ??
109
- STUDIO_DEVICES[0];
110
+ STUDIO_DEVICES.find((device) => device.id === id) ?? DEFAULT_DEVICE;
@@ -0,0 +1,80 @@
1
+ import {
2
+ createHostState,
3
+ DEFAULT_PARAMS,
4
+ DEFAULT_USER,
5
+ defaultDevice,
6
+ EXAMPLE_PRODUCT_VARIABLES,
7
+ type HostProduct,
8
+ type HostState,
9
+ type HostVariables,
10
+ } from "@superwall/host";
11
+ import type { Samples, StudioSurface } from "./surfaces";
12
+ import type { SampleDefaults, VariableOverrides } from "./variables";
13
+
14
+ export type HostInputs = {
15
+ surface: StudioSurface;
16
+ defaults: SampleDefaults;
17
+ sourceSamples?: SampleDefaults;
18
+ samples: Samples;
19
+ frame?: Record<string, unknown>;
20
+ theme: "light" | "dark";
21
+ locale?: string;
22
+ edited: VariableOverrides;
23
+ };
24
+
25
+ export const studioDefaults = (): SampleDefaults => ({
26
+ device: defaultDevice(),
27
+ user: DEFAULT_USER,
28
+ params: DEFAULT_PARAMS,
29
+ });
30
+
31
+ export const hostStateFor = ({
32
+ surface,
33
+ defaults,
34
+ sourceSamples,
35
+ samples,
36
+ frame,
37
+ theme,
38
+ locale,
39
+ edited,
40
+ }: HostInputs): HostState => {
41
+ const device: HostVariables = {
42
+ ...defaults.device,
43
+ ...sourceSamples?.device,
44
+ ...samples.device,
45
+ ...frame,
46
+ interfaceStyle: theme === "dark" ? "Dark" : "Light",
47
+ ...(locale ? { deviceLocale: locale, deviceLanguageCode: locale.split(/[-_]/)[0] } : {}),
48
+ ...edited.device,
49
+ };
50
+ const user: HostVariables = {
51
+ ...defaults.user,
52
+ ...sourceSamples?.user,
53
+ ...samples.user,
54
+ ...edited.user,
55
+ };
56
+ const params: HostVariables = {
57
+ ...defaults.params,
58
+ ...sourceSamples?.params,
59
+ ...edited.params,
60
+ };
61
+ const products: HostProduct[] = Object.entries(surface.products ?? {}).map(
62
+ ([reference, productId]) => ({
63
+ reference,
64
+ productId,
65
+ variables: {
66
+ ...(samples.products?.[productId] ?? EXAMPLE_PRODUCT_VARIABLES),
67
+ ...edited.products?.[reference],
68
+ },
69
+ }),
70
+ );
71
+ return createHostState({
72
+ paywallId: surface.paywallId ?? "0",
73
+ paywallIdentifier: surface.paywallIdentifier ?? surface.id,
74
+ device,
75
+ user,
76
+ params,
77
+ products,
78
+ introductoryOfferEligible: edited.introductoryOfferEligible,
79
+ });
80
+ };
@@ -0,0 +1,63 @@
1
+ import type { TIncomingMessage, TOutgoingMessage } from "@superwall/host";
2
+
3
+ export type PaywallEventName = TOutgoingMessage["event_name"];
4
+
5
+ export type PaywallMessageName = PaywallEventName | TIncomingMessage["event_name"];
6
+
7
+ export type EventNotice = {
8
+ action: PaywallEventName;
9
+ subject?: string;
10
+ tone: "info" | "success" | "warning";
11
+ };
12
+
13
+ const SILENT: ReadonlySet<PaywallEventName> = new Set<PaywallEventName>([
14
+ "ping",
15
+ "page_view",
16
+ "page_styles",
17
+ "has_set_dom",
18
+ "haptic_feedback",
19
+ "var_click",
20
+ "purchase",
21
+ "restore",
22
+ ]);
23
+
24
+ const SUBJECT: Partial<Record<PaywallEventName, readonly string[]>> = {
25
+ open_url: ["url"],
26
+ open_url_external: ["url"],
27
+ open_deep_link: ["link"],
28
+ custom_placement: ["name"],
29
+ custom: ["name", "data"],
30
+ request_permission: ["permission_type"],
31
+ request_callback: ["name"],
32
+ schedule_notification: ["title"],
33
+ discount_redemption_result: ["code"],
34
+ };
35
+
36
+ const WARNING: ReadonlySet<PaywallEventName> = new Set<PaywallEventName>(["close"]);
37
+
38
+ const SUCCESS: ReadonlySet<PaywallEventName> = new Set<PaywallEventName>([
39
+ "stripe_checkout_complete",
40
+ "post_checkout_complete",
41
+ ]);
42
+
43
+ const subjectOf = (event: TOutgoingMessage): string | undefined => {
44
+ for (const key of SUBJECT[event.event_name] ?? []) {
45
+ const value = Reflect.get(event, key);
46
+ if (typeof value === "string" && value.length > 0) return value;
47
+ }
48
+ return undefined;
49
+ };
50
+
51
+ export const noticeFor = (event: TOutgoingMessage): EventNotice | undefined => {
52
+ if (SILENT.has(event.event_name)) return undefined;
53
+
54
+ return {
55
+ action: event.event_name,
56
+ subject: subjectOf(event),
57
+ tone: WARNING.has(event.event_name)
58
+ ? "warning"
59
+ : SUCCESS.has(event.event_name)
60
+ ? "success"
61
+ : "info",
62
+ };
63
+ };
@@ -1,39 +1,17 @@
1
- import type { PreviewOverrides, PreviewUrlBuilder, StudioSurface } from "./types";
2
-
3
- const overrideParams = (overrides: PreviewOverrides): URLSearchParams => {
4
- const params = new URLSearchParams();
5
- if (overrides.theme) params.set("theme", overrides.theme);
6
- if (overrides.locale) params.set("locale", overrides.locale);
7
- for (const [key, group] of [
8
- ["sw_device", overrides.device],
9
- ["sw_user", overrides.user],
10
- ["sw_params", overrides.params],
11
- ["sw_products", overrides.products],
12
- ] as const) {
13
- if (group && Object.keys(group).length > 0) params.set(key, JSON.stringify(group));
14
- }
15
- if (overrides.trialEligible !== undefined) {
16
- params.set("sw_trial", overrides.trialEligible ? "1" : "0");
17
- }
18
- return params;
19
- };
1
+ import type { PreviewUrlBuilder, StudioSurface } from "./surfaces";
20
2
 
21
3
  export const surfacePath = (surface: StudioSurface): string =>
22
4
  `${surface.project ? `/${surface.project}` : ""}/${surface.kind}/${surface.id}`;
23
5
 
24
- export const devicePreviewPath = (surface: StudioSurface): string =>
25
- `/preview${surfacePath(surface)}?sw_preview=1`;
26
-
27
- export const buildPreviewPath: PreviewUrlBuilder = (
28
- surface: StudioSurface,
29
- overrides: PreviewOverrides,
30
- ): string => {
31
- const query = overrideParams(overrides).toString();
32
- return `/preview${surfacePath(surface)}${query ? `?${query}` : ""}`;
6
+ export const hostedUrl = (url: string): string => {
7
+ if (/[?&]transport=editor(?:&|$)/.test(url)) return url;
8
+ return `${url}${url.includes("?") ? "&" : "?"}transport=editor`;
33
9
  };
34
10
 
35
- export const withOverrides = (url: string, overrides: PreviewOverrides): string => {
36
- const query = overrideParams(overrides).toString();
37
- if (!query) return url;
38
- return `${url}${url.includes("?") ? "&" : "?"}${query}`;
39
- };
11
+ export const buildPreviewPath: PreviewUrlBuilder = (surface) =>
12
+ hostedUrl(`/preview${surfacePath(surface)}`);
13
+
14
+ export const snapshotPreviewUrl =
15
+ (urlOf: (surface: StudioSurface) => string): PreviewUrlBuilder =>
16
+ (surface) =>
17
+ hostedUrl(urlOf(surface));
@@ -0,0 +1,116 @@
1
+ export interface DashboardPrice {
2
+ amount?: number;
3
+ currency?: string;
4
+ }
5
+
6
+ export interface DashboardProduct {
7
+ identifier?: string;
8
+ price?: DashboardPrice | null;
9
+ trial_price?: DashboardPrice | null;
10
+ monthly_billing_plan_price?: DashboardPrice | null;
11
+ subscription?: {
12
+ period?: string;
13
+ period_count?: number;
14
+ trial_period_days?: number | null;
15
+ } | null;
16
+ }
17
+
18
+ const SYMBOLS: Record<string, string> = {
19
+ USD: "$",
20
+ CAD: "$",
21
+ AUD: "$",
22
+ NZD: "$",
23
+ EUR: "€",
24
+ GBP: "£",
25
+ JPY: "¥",
26
+ CNY: "¥",
27
+ INR: "₹",
28
+ KRW: "₩",
29
+ BRL: "R$",
30
+ MXN: "$",
31
+ CHF: "CHF",
32
+ SEK: "kr",
33
+ NOK: "kr",
34
+ DKK: "kr",
35
+ PLN: "zł",
36
+ TRY: "₺",
37
+ RUB: "₽",
38
+ ZAR: "R",
39
+ };
40
+
41
+ const MINOR = 100;
42
+
43
+ const PER_YEAR: Record<string, number> = { day: 365, week: 52, month: 12, year: 1 };
44
+
45
+ const symbolFor = (currency: string): string => SYMBOLS[currency.toUpperCase()] ?? "";
46
+
47
+ const money = (amount: number, currency: string): string => {
48
+ try {
49
+ return new Intl.NumberFormat("en-US", { style: "currency", currency }).format(amount);
50
+ } catch {
51
+ return `${symbolFor(currency)}${amount.toFixed(2)}`;
52
+ }
53
+ };
54
+
55
+ const PERIODLY: Record<string, string> = {
56
+ day: "daily",
57
+ week: "weekly",
58
+ month: "monthly",
59
+ year: "yearly",
60
+ };
61
+
62
+ const PERIOD_UNITS: Record<string, { days: number; weeks: number; months: number; years: number }> =
63
+ {
64
+ day: { days: 1, weeks: 1 / 7, months: 1 / 30, years: 1 / 365 },
65
+ week: { days: 7, weeks: 1, months: 1 / 4, years: 1 / 52 },
66
+ month: { days: 30, weeks: 4, months: 1, years: 1 / 12 },
67
+ year: { days: 365, weeks: 52, months: 12, years: 1 },
68
+ };
69
+
70
+ const periodCounts = (period: string, count: number): Record<string, number> | undefined => {
71
+ const units = PERIOD_UNITS[period];
72
+ if (!units) return undefined;
73
+ return {
74
+ periodDays: units.days * count,
75
+ periodWeeks: Math.round(units.weeks * count),
76
+ periodMonths: Math.floor(units.months * count),
77
+ periodYears: Math.floor(units.years * count),
78
+ };
79
+ };
80
+
81
+ export const productVariables = (product: DashboardProduct): Record<string, unknown> => {
82
+ const variables: Record<string, unknown> = {};
83
+ if (product.identifier) variables.identifier = product.identifier;
84
+
85
+ const price = product.price;
86
+ if (!price || typeof price.amount !== "number" || !price.currency) return variables;
87
+
88
+ const currency = price.currency.toUpperCase();
89
+ const value = price.amount / MINOR;
90
+ variables.price = money(value, currency);
91
+ variables.rawPrice = value;
92
+ variables.currencyCode = currency;
93
+ variables.currencySymbol = symbolFor(currency);
94
+
95
+ const period = product.subscription?.period;
96
+ if (!period) return variables;
97
+
98
+ const count = product.subscription?.period_count ?? 1;
99
+ variables.period = period;
100
+ variables.periodly = PERIODLY[period] ?? `${period}ly`;
101
+ Object.assign(variables, periodCounts(period, count) ?? {});
102
+
103
+ const perYear = (PER_YEAR[period] ?? 1) / count;
104
+ variables.yearlyPrice = money(value * perYear, currency);
105
+ variables.monthlyPrice = money((value * perYear) / 12, currency);
106
+ variables.weeklyPrice = money((value * perYear) / 52, currency);
107
+ variables.dailyPrice = money((value * perYear) / 365, currency);
108
+
109
+ const trialDays = product.subscription?.trial_period_days;
110
+ if (typeof trialDays === "number" && trialDays > 0) {
111
+ variables.trialPeriodDays = trialDays;
112
+ variables.trialPeriodText = `${trialDays}-day`;
113
+ }
114
+
115
+ return variables;
116
+ };
@@ -1,4 +1,5 @@
1
- import type { SampleDefaults, StudioSurface, StudioSurfaceKind } from "./types";
1
+ import type { StudioSurface, StudioSurfaceKind } from "./surfaces";
2
+ import type { SampleDefaults } from "./variables";
2
3
 
3
4
  export type StudioProjectPayload = {
4
5
  title: string;
@@ -0,0 +1,20 @@
1
+ import type { StudioActionName } from "./contract";
2
+
3
+ export type StudioStepState = "pending" | "active" | "done" | "failed";
4
+
5
+ export type StudioActionStep = "link" | "build" | "assets" | "push" | "source" | "promote";
6
+
7
+ export const ACTION_STEPS: Record<StudioActionName, StudioActionStep[]> = {
8
+ push: ["link", "build", "assets", "push", "source"],
9
+ publish: ["link", "build", "assets", "push", "source", "promote"],
10
+ promote: ["link", "promote"],
11
+ };
12
+
13
+ export const STEP_LABELS: Record<StudioActionStep, string> = {
14
+ link: "Find paywall",
15
+ build: "Build snapshot",
16
+ assets: "Sync assets",
17
+ push: "Push version",
18
+ source: "Push source",
19
+ promote: "Promote to live",
20
+ };
@@ -0,0 +1,41 @@
1
+ import type { SampleDefaults } from "./variables";
2
+
3
+ export type {
4
+ AppScheme,
5
+ Samples,
6
+ StudioActionName,
7
+ StudioActionProgress,
8
+ StudioActionResult,
9
+ StudioStatus,
10
+ } from "./contract";
11
+
12
+ export type StudioSurfaceKind = "paywall" | "funnel";
13
+
14
+ export type StudioSurface = {
15
+ kind: StudioSurfaceKind;
16
+ id: string;
17
+ project?: string;
18
+ label?: string;
19
+ products?: Record<string, string>;
20
+ routes: string[];
21
+ locales: string[];
22
+ platforms?: string[];
23
+ paywallId?: string;
24
+ paywallIdentifier?: string;
25
+ };
26
+
27
+ export type PreviewUrlBuilder = (surface: StudioSurface) => string;
28
+
29
+ export type CompareTarget = { type: "live" } | { type: "surface"; surface: StudioSurface };
30
+
31
+ export type StudioSource = {
32
+ scheme?: string;
33
+ title: string;
34
+ surfaces: StudioSurface[];
35
+ diagnostics?: string[];
36
+ samples?: SampleDefaults;
37
+ previewUrl: PreviewUrlBuilder;
38
+ standaloneUrl?: PreviewUrlBuilder;
39
+ capabilities?: { actions: boolean };
40
+ compareHint?: string;
41
+ };
package/src/lib/time.ts CHANGED
@@ -5,7 +5,6 @@ const UNITS: [number, Intl.RelativeTimeFormatUnit][] = [
5
5
  [7, "day"],
6
6
  [4.348, "week"],
7
7
  [12, "month"],
8
- [Number.POSITIVE_INFINITY, "year"],
9
8
  ];
10
9
 
11
10
  export const timeAgo = (iso: string, now = Date.now()): string | undefined => {
@@ -17,5 +16,5 @@ export const timeAgo = (iso: string, now = Date.now()): string | undefined => {
17
16
  if (value < factor) return formatter.format(-Math.round(value), unit);
18
17
  value /= factor;
19
18
  }
20
- return undefined;
19
+ return formatter.format(-Math.round(value), "year");
21
20
  };
@@ -0,0 +1,13 @@
1
+ export type SampleDefaults = {
2
+ device: Record<string, unknown>;
3
+ user: Record<string, unknown>;
4
+ params: Record<string, unknown>;
5
+ };
6
+
7
+ export type VariableOverrides = {
8
+ device?: Record<string, unknown>;
9
+ user?: Record<string, unknown>;
10
+ params?: Record<string, unknown>;
11
+ products?: Record<string, Record<string, unknown>>;
12
+ introductoryOfferEligible?: boolean;
13
+ };
package/src/main.tsx CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { createRoot } from "react-dom/client";
3
- import { buildPreviewPath } from "./lib/preview";
3
+ import { buildPreviewPath, surfacePath } from "./lib/preview";
4
4
  import { parseProjectPayload } from "./lib/project";
5
5
  import { StudioApp } from "./StudioApp";
6
6
  import "./styles.css";
7
- import type { StudioSource } from "./lib/types";
7
+ import type { StudioSource } from "./lib/surfaces";
8
8
 
9
9
  const loadSource = async (): Promise<StudioSource> => {
10
10
  const response = await fetch("/__studio/project.json");
@@ -12,7 +12,7 @@ const loadSource = async (): Promise<StudioSource> => {
12
12
  throw new Error(`project data unavailable (${response.status})`);
13
13
  }
14
14
  const payload = parseProjectPayload(await response.json());
15
- return { ...payload, previewUrl: buildPreviewPath };
15
+ return { ...payload, previewUrl: buildPreviewPath, standaloneUrl: surfacePath };
16
16
  };
17
17
 
18
18
  const Failure = ({ error }: { error: unknown }) => (