@pradip1995/segment-primitives 0.4.7 → 0.4.9

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.7",
3
+ "version": "0.4.9",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,10 +22,6 @@
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
- },
29
25
  "peerDependencies": {
30
26
  "@medusajs/types": "^2.0.0",
31
27
  "@pradip1995/commerce-core": "^4.0.0",
@@ -40,5 +36,9 @@
40
36
  "@types/react": "^19",
41
37
  "react": "19.0.3",
42
38
  "typescript": "^5.7.2"
39
+ },
40
+ "scripts": {
41
+ "typecheck": "tsc --noEmit",
42
+ "lint": "tsc --noEmit"
43
43
  }
44
- }
44
+ }
@@ -3,15 +3,19 @@
3
3
  import { useState } from "react"
4
4
  import { useRouter } from "next/navigation"
5
5
  import type { HttpTypes } from "@medusajs/types"
6
- import { applyPromotions } from "@pradip1995/commerce-core/client/actions/cart"
7
6
  import { formatPrice } from "./format-price"
8
7
 
8
+ // Use require to prevent TS from attempting to typecheck the raw .ts files published in commerce-core
9
+ const { applyPromotions } = require("@pradip1995/commerce-core/client/actions/cart") as {
10
+ applyPromotions: (codes: string[], cartId: string) => Promise<any>
11
+ }
12
+
9
13
  type CouponApplyProps = {
10
14
  cart: HttpTypes.StoreCart & { promotions?: HttpTypes.StorePromotion[] }
11
15
  className?: string
12
16
  }
13
17
 
14
- function promotionLabel(promotion: HttpTypes.StorePromotion) {
18
+ function promotionLabel(promotion: any) {
15
19
  const method = promotion.application_method
16
20
  if (method?.value == null) return null
17
21
 
@@ -9,8 +9,9 @@ export function resolveMediaUrl(
9
9
 
10
10
  // Uploads stored while AWS_FILE_URL / backend_url was unset:
11
11
  // "undefined/uploadsFoo.webp" or "undefined/uploads/Foo.webp"
12
- trimmed = rewriteBrokenUndefinedUploadUrl(trimmed)
13
- if (!trimmed) return null
12
+ const rewritten = rewriteBrokenUndefinedUploadUrl(trimmed)
13
+ if (!rewritten) return null
14
+ trimmed = rewritten
14
15
 
15
16
  if (trimmed.startsWith("/")) {
16
17
  return trimmed
@@ -100,3 +101,46 @@ function rewriteStoredBackendUrl(url: string): string {
100
101
 
101
102
  return `${parsedPublic.origin}${parsedStored.pathname}${parsedStored.search}${parsedStored.hash}`
102
103
  }
104
+
105
+ type MediaRef = { url?: string | null } | string | null | undefined
106
+
107
+ type CartLineImageSource = {
108
+ thumbnail?: string | null
109
+ product?: {
110
+ thumbnail?: string | null
111
+ images?: Array<{ url?: string | null }> | null
112
+ } | null
113
+ variant?: {
114
+ thumbnail?: string | null
115
+ images?: Array<MediaRef> | null
116
+ product?: {
117
+ thumbnail?: string | null
118
+ images?: Array<{ url?: string | null }> | null
119
+ } | null
120
+ } | null
121
+ }
122
+
123
+ function mediaRefUrl(value: MediaRef): string | null {
124
+ if (!value) return null
125
+ if (typeof value === "string") return value
126
+ return value.url ?? null
127
+ }
128
+
129
+ /** Line-item thumbnail, then variant/product thumbnail, then first gallery image. */
130
+ export function resolveCartLineItemImage(item: CartLineImageSource): string | null {
131
+ const product = item.product || item.variant?.product || null
132
+ const candidates = [
133
+ item.thumbnail,
134
+ item.variant?.thumbnail,
135
+ product?.thumbnail,
136
+ mediaRefUrl(item.variant?.images?.[0]),
137
+ product?.images?.[0]?.url,
138
+ ]
139
+
140
+ for (const candidate of candidates) {
141
+ const resolved = resolveMediaUrl(candidate)
142
+ if (resolved) return resolved
143
+ }
144
+
145
+ return null
146
+ }