@hartl-services/medusa-storefront 0.5.0 → 0.6.0

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/README.md CHANGED
@@ -97,6 +97,12 @@ the account with the company address as default address and submits the
97
97
  application from it; while the e-mail is unconfirmed, both wait until the
98
98
  first login.
99
99
 
100
+ The catalog leaves out partner-only products for everyone but a partner. A
101
+ shop may let others see them too with `canSeePartnerOnlyProducts` in the
102
+ server config, e.g. a CMS editor in preview who checks such a product's page
103
+ (since 0.6.0). It only affects what is shown; the backend still refuses
104
+ partner-only products at checkout for non-partners.
105
+
100
106
  ## Wiring rules
101
107
 
102
108
  - Create `createStorefrontServer` and `createStorefrontBrowser` once each, at
@@ -4,7 +4,7 @@
4
4
  "title": "Customer account",
5
5
  "description": "Sign-in with password or e-mail code, password reset, account verification, address book with UID check, profile, orders, the account workspace layout and the document download route.",
6
6
  "dependencies": [
7
- "@hartl-services/medusa-storefront@^0.5.0",
7
+ "@hartl-services/medusa-storefront@^0.6.0",
8
8
  "@hartl-services/medusa-contracts@^1.5.0",
9
9
  "@medusajs/types@^2.19.0",
10
10
  "lucide-react"
@@ -4,7 +4,7 @@
4
4
  "title": "Partner portal",
5
5
  "description": "Partner portal: gated registration with UID check, links, coupon codes, commissions with date filter, consignment reports, and its Route Handlers.",
6
6
  "dependencies": [
7
- "@hartl-services/medusa-storefront@^0.5.0",
7
+ "@hartl-services/medusa-storefront@^0.6.0",
8
8
  "@hartl-services/medusa-contracts@^1.5.0",
9
9
  "@medusajs/types@^2.19.0",
10
10
  "lucide-react",
@@ -4,7 +4,7 @@
4
4
  "title": "Cart",
5
5
  "description": "Cart widget with popover, line items, totals, cart page, add-to-cart button, variant picker and product price.",
6
6
  "dependencies": [
7
- "@hartl-services/medusa-storefront@^0.5.0",
7
+ "@hartl-services/medusa-storefront@^0.6.0",
8
8
  "@medusajs/types@^2.19.0",
9
9
  "lucide-react"
10
10
  ],
@@ -4,7 +4,7 @@
4
4
  "title": "Checkout",
5
5
  "description": "Checkout page (address, login prompt, shipping and Stripe payment, coupon, UID status) and the order confirmation page.",
6
6
  "dependencies": [
7
- "@hartl-services/medusa-storefront@^0.5.0",
7
+ "@hartl-services/medusa-storefront@^0.6.0",
8
8
  "@medusajs/types@^2.19.0",
9
9
  "@stripe/react-stripe-js@^5.6.1",
10
10
  "@stripe/stripe-js@^8.11.0",
@@ -4,7 +4,7 @@
4
4
  "title": "Storefront form kit",
5
5
  "description": "The shop's TanStack form hook (useAppForm) with unstyled field components; the package's hooks hand their formOptions to it.",
6
6
  "dependencies": [
7
- "@hartl-services/medusa-storefront@^0.5.0",
7
+ "@hartl-services/medusa-storefront@^0.6.0",
8
8
  "@tanstack/react-form@^1.33.5",
9
9
  "input-otp",
10
10
  "lucide-react"
@@ -7,7 +7,7 @@
7
7
  "title": "Storefront setup",
8
8
  "description": "Wires the storefront package into a Next shop: server and browser instances, the Server Action wrappers, texts, error reporting and the provider root for the [countryCode] layout.",
9
9
  "dependencies": [
10
- "@hartl-services/medusa-storefront@^0.5.0",
10
+ "@hartl-services/medusa-storefront@^0.6.0",
11
11
  "@hartl-services/medusa-contracts@^1.5.0",
12
12
  "@medusajs/framework@^2.19.0",
13
13
  "@medusajs/js-sdk@^2.19.0",
@@ -73,7 +73,7 @@
73
73
  "title": "Storefront form kit",
74
74
  "description": "The shop's TanStack form hook (useAppForm) with unstyled field components; the package's hooks hand their formOptions to it.",
75
75
  "dependencies": [
76
- "@hartl-services/medusa-storefront@^0.5.0",
76
+ "@hartl-services/medusa-storefront@^0.6.0",
77
77
  "@tanstack/react-form@^1.33.5",
78
78
  "input-otp",
79
79
  "lucide-react"
@@ -197,7 +197,7 @@
197
197
  "title": "Cart",
198
198
  "description": "Cart widget with popover, line items, totals, cart page, add-to-cart button, variant picker and product price.",
199
199
  "dependencies": [
200
- "@hartl-services/medusa-storefront@^0.5.0",
200
+ "@hartl-services/medusa-storefront@^0.6.0",
201
201
  "@medusajs/types@^2.19.0",
202
202
  "lucide-react"
203
203
  ],
@@ -306,7 +306,7 @@
306
306
  "title": "Customer account",
307
307
  "description": "Sign-in with password or e-mail code, password reset, account verification, address book with UID check, profile, orders, the account workspace layout and the document download route.",
308
308
  "dependencies": [
309
- "@hartl-services/medusa-storefront@^0.5.0",
309
+ "@hartl-services/medusa-storefront@^0.6.0",
310
310
  "@hartl-services/medusa-contracts@^1.5.0",
311
311
  "@medusajs/types@^2.19.0",
312
312
  "lucide-react"
@@ -516,7 +516,7 @@
516
516
  "title": "Checkout",
517
517
  "description": "Checkout page (address, login prompt, shipping and Stripe payment, coupon, UID status) and the order confirmation page.",
518
518
  "dependencies": [
519
- "@hartl-services/medusa-storefront@^0.5.0",
519
+ "@hartl-services/medusa-storefront@^0.6.0",
520
520
  "@medusajs/types@^2.19.0",
521
521
  "@stripe/react-stripe-js@^5.6.1",
522
522
  "@stripe/stripe-js@^8.11.0",
@@ -661,7 +661,7 @@
661
661
  "title": "Partner portal",
662
662
  "description": "Partner portal: gated registration with UID check, links, coupon codes, commissions with date filter, consignment reports, and its Route Handlers.",
663
663
  "dependencies": [
664
- "@hartl-services/medusa-storefront@^0.5.0",
664
+ "@hartl-services/medusa-storefront@^0.6.0",
665
665
  "@hartl-services/medusa-contracts@^1.5.0",
666
666
  "@medusajs/types@^2.19.0",
667
667
  "lucide-react",
@@ -4,7 +4,7 @@
4
4
  "title": "Storefront setup",
5
5
  "description": "Wires the storefront package into a Next shop: server and browser instances, the Server Action wrappers, texts, error reporting and the provider root for the [countryCode] layout.",
6
6
  "dependencies": [
7
- "@hartl-services/medusa-storefront@^0.5.0",
7
+ "@hartl-services/medusa-storefront@^0.6.0",
8
8
  "@hartl-services/medusa-contracts@^1.5.0",
9
9
  "@medusajs/framework@^2.19.0",
10
10
  "@medusajs/js-sdk@^2.19.0",
@@ -1,5 +1,5 @@
1
1
  import type { HttpTypes } from "@medusajs/types";
2
- import type { ServerContext } from "./context.js";
2
+ import type { ServerContext, StorefrontServerConfig } from "./context.js";
3
3
  import type { ServerRegion } from "./region.js";
4
4
  export interface CommerceProductListInput {
5
5
  categoryId?: string;
@@ -32,3 +32,9 @@ export declare function createCatalog(context: ServerContext, region: ServerRegi
32
32
  collectionByHandle(handle: string): Promise<HttpTypes.StoreCollection | null>;
33
33
  };
34
34
  export type ServerCatalog = ReturnType<typeof createCatalog>;
35
+ /**
36
+ * The catalog's partner-only check: the shop's own rule
37
+ * (`canSeePartnerOnlyProducts`) first, then the partner state. A failing
38
+ * shop rule counts as "no", so it never hides anything from a partner.
39
+ */
40
+ export declare function partnerOnlyVisibility(config: Pick<StorefrontServerConfig, "canSeePartnerOnlyProducts">, isActivePartner: () => Promise<boolean>): () => Promise<boolean>;
@@ -112,3 +112,15 @@ export function createCatalog(context, region, isActivePartner = async () => fal
112
112
  },
113
113
  };
114
114
  }
115
+ /**
116
+ * The catalog's partner-only check: the shop's own rule
117
+ * (`canSeePartnerOnlyProducts`) first, then the partner state. A failing
118
+ * shop rule counts as "no", so it never hides anything from a partner.
119
+ */
120
+ export function partnerOnlyVisibility(config, isActivePartner) {
121
+ const shopRule = config.canSeePartnerOnlyProducts;
122
+ if (!shopRule) {
123
+ return isActivePartner;
124
+ }
125
+ return async () => (await shopRule().catch(() => false)) || isActivePartner();
126
+ }
@@ -18,6 +18,13 @@ export interface StorefrontServerConfig {
18
18
  resolveLocale?: (countryCode: string) => string;
19
19
  /** Cookies are `Secure` in production. */
20
20
  secureCookies?: boolean;
21
+ /**
22
+ * Who else besides an active partner may see partner-only products in the
23
+ * catalog, e.g. a CMS editor in preview who checks a partner product's page.
24
+ * Display only: the backend still refuses partner-only products at checkout
25
+ * for everyone who is not a partner. Should fail closed.
26
+ */
27
+ canSeePartnerOnlyProducts?: () => Promise<boolean>;
21
28
  }
22
29
  export type MedusaServerClient = Medusa;
23
30
  export interface ServerContext {
@@ -1,7 +1,7 @@
1
1
  import "server-only";
2
2
  import { createAffiliate } from "./affiliate.js";
3
3
  import { createCart } from "./cart.js";
4
- import { createCatalog } from "./catalog.js";
4
+ import { createCatalog, partnerOnlyVisibility } from "./catalog.js";
5
5
  import { createCheckout } from "./checkout.js";
6
6
  import { createServerContext } from "./context.js";
7
7
  import { createCustomer } from "./customer.js";
@@ -41,6 +41,6 @@ export function createStorefrontServer(config) {
41
41
  affiliate,
42
42
  orders: createOrders(context),
43
43
  documents: createDocuments(context),
44
- catalog: createCatalog(context, region, affiliate.isActivePartner),
44
+ catalog: createCatalog(context, region, partnerOnlyVisibility(config, affiliate.isActivePartner)),
45
45
  };
46
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hartl-services/medusa-storefront",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Headless Medusa storefront logic, Next.js server/browser adapters and React hooks for shops built from the @hartl-services/medusa-* plugins.",
5
5
  "type": "module",
6
6
  "sideEffects": false,