@pradip1995/segment-primitives 0.4.6 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/segment-primitives",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,6 +22,10 @@
22
22
  "./product-selection-context": "./src/product-selection-context.tsx",
23
23
  "./is-next-redirect": "./src/is-next-redirect.ts"
24
24
  },
25
+ "scripts": {
26
+ "typecheck": "tsc --noEmit",
27
+ "lint": "tsc --noEmit"
28
+ },
25
29
  "peerDependencies": {
26
30
  "@medusajs/types": "^2.0.0",
27
31
  "@pradip1995/commerce-core": "^4.0.0",
@@ -36,9 +40,5 @@
36
40
  "@types/react": "^19",
37
41
  "react": "19.0.3",
38
42
  "typescript": "^5.7.2"
39
- },
40
- "scripts": {
41
- "typecheck": "tsc --noEmit",
42
- "lint": "tsc --noEmit"
43
43
  }
44
- }
44
+ }
@@ -64,3 +64,23 @@ export function safeErrorMessage(err: unknown, fallback: string): string {
64
64
  export function isNextRedirectMessage(value: unknown): boolean {
65
65
  return typeof value === "string" && textLooksLikeControlFlow(value)
66
66
  }
67
+
68
+ const SHIPPING_PROFILE_RE = /shipping profiles that are not satisfied/i
69
+ const RSC_DIGEST_RE =
70
+ /Server Components render|digest property is included on this error/i
71
+
72
+ /**
73
+ * Maps checkout/payment failures to an actionable message.
74
+ * Production Next.js often replaces the Medusa shipping-profile error with an RSC digest.
75
+ */
76
+ export function checkoutPaymentErrorMessage(err: unknown): string {
77
+ const fallback = "Payment could not be started."
78
+ const msg = safeErrorMessage(err, fallback)
79
+ if (SHIPPING_PROFILE_RE.test(msg)) {
80
+ return "This product has no shipping profile, so checkout cannot complete. In Medusa Admin, open the product and assign the Default shipping profile (the same one used by Express/Standard shipping)."
81
+ }
82
+ if (RSC_DIGEST_RE.test(msg)) {
83
+ return "Checkout could not complete. If this happens only for one product, assign it a shipping profile in Medusa Admin (same profile as your shipping methods) and try again."
84
+ }
85
+ return msg
86
+ }
@@ -13,12 +13,6 @@ export function resolveMediaUrl(
13
13
  if (!trimmed) return null
14
14
 
15
15
  if (trimmed.startsWith("/")) {
16
- const isBackendUpload =
17
- trimmed.startsWith("/static/") || trimmed.startsWith("/uploads/")
18
- if (isBackendUpload) {
19
- const base = mediaBackendBase()
20
- if (base) return `${base.replace(/\/$/, "")}${trimmed}`
21
- }
22
16
  return trimmed
23
17
  }
24
18
 
@@ -106,47 +100,3 @@ function rewriteStoredBackendUrl(url: string): string {
106
100
 
107
101
  return `${parsedPublic.origin}${parsedStored.pathname}${parsedStored.search}${parsedStored.hash}`
108
102
  }
109
-
110
- type MediaRef = { url?: string | null } | string | null | undefined
111
-
112
- type CartLineImageSource = {
113
- thumbnail?: string | null
114
- product?: {
115
- thumbnail?: string | null
116
- images?: Array<{ url?: string | null }> | null
117
- } | null
118
- variant?: {
119
- thumbnail?: string | null
120
- images?: Array<MediaRef> | null
121
- product?: {
122
- thumbnail?: string | null
123
- images?: Array<{ url?: string | null }> | null
124
- } | null
125
- } | null
126
- }
127
-
128
- function mediaRefUrl(value: MediaRef): string | null {
129
- if (!value) return null
130
- if (typeof value === "string") return value
131
- return value.url ?? null
132
- }
133
-
134
- /** Line-item thumbnail, then variant/product thumbnail, then first gallery image. */
135
- export function resolveCartLineItemImage(item: CartLineImageSource): string | null {
136
- const product = item.product || item.variant?.product || null
137
- const candidates = [
138
- item.thumbnail,
139
- item.variant?.thumbnail,
140
- product?.thumbnail,
141
- mediaRefUrl(item.variant?.images?.[0]),
142
- product?.images?.[0]?.url,
143
- ]
144
-
145
- for (const candidate of candidates) {
146
- const resolved = resolveMediaUrl(candidate)
147
- if (resolved) return resolved
148
- }
149
-
150
- return null
151
- }
152
-