@shopify/shop-minis-react 0.4.12 → 0.4.15
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/dist/components/atoms/product-variant-price.js +1 -1
- package/dist/components/atoms/product-variant-price.js.map +1 -1
- package/dist/components/commerce/product-card.js +1 -1
- package/dist/components/commerce/product-card.js.map +1 -1
- package/dist/components/commerce/product-link.js +1 -1
- package/dist/components/commerce/product-link.js.map +1 -1
- package/dist/hooks/storage/useImageUpload.js +32 -24
- package/dist/hooks/storage/useImageUpload.js.map +1 -1
- package/dist/index.js +48 -46
- package/dist/index.js.map +1 -1
- package/dist/mocks.js +70 -50
- package/dist/mocks.js.map +1 -1
- package/dist/utils/formatMoney.js.map +1 -0
- package/eslint/config.cjs +2 -0
- package/eslint/index.cjs +4 -0
- package/eslint/rules/asset-path-patterns.cjs +30 -0
- package/eslint/rules/no-dynamic-asset-paths.cjs +78 -0
- package/eslint/rules/no-hardcoded-asset-paths.cjs +124 -0
- package/package.json +2 -2
- package/src/components/atoms/product-variant-price.test.tsx +1 -1
- package/src/components/atoms/product-variant-price.tsx +1 -1
- package/src/components/commerce/product-card.test.tsx +1 -1
- package/src/components/commerce/product-card.tsx +1 -1
- package/src/components/commerce/product-link.test.tsx +1 -1
- package/src/components/commerce/product-link.tsx +1 -1
- package/src/hooks/storage/useImageUpload.ts +13 -0
- package/src/mocks.ts +48 -19
- package/src/utils/index.ts +1 -0
- package/dist/lib/formatMoney.js.map +0 -1
- /package/dist/{lib → utils}/formatMoney.js +0 -0
- /package/src/{lib → utils}/formatMoney.ts +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/shop-minis-react",
|
|
3
3
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.15",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typescript": ">=5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@shopify/shop-minis-platform": "0.8.
|
|
49
|
+
"@shopify/shop-minis-platform": "0.8.3",
|
|
50
50
|
"@tailwindcss/vite": "4.1.8",
|
|
51
51
|
"@tanstack/react-query": "5.86.0",
|
|
52
52
|
"@types/color": "3.0.6",
|
|
@@ -5,7 +5,7 @@ import {render, screen} from '../../test-utils'
|
|
|
5
5
|
import {ProductVariantPrice} from './product-variant-price'
|
|
6
6
|
|
|
7
7
|
// Mock formatMoney function
|
|
8
|
-
vi.mock('../../
|
|
8
|
+
vi.mock('../../utils/formatMoney', () => ({
|
|
9
9
|
formatMoney: vi.fn((amount: string, currencyCode: string) => {
|
|
10
10
|
const numAmount = parseFloat(amount)
|
|
11
11
|
return currencyCode === 'USD'
|
|
@@ -40,7 +40,7 @@ vi.mock('../../hooks/user/useSavedProductsActions', () => ({
|
|
|
40
40
|
}))
|
|
41
41
|
|
|
42
42
|
// Mock formatMoney
|
|
43
|
-
vi.mock('../../
|
|
43
|
+
vi.mock('../../utils/formatMoney', () => ({
|
|
44
44
|
formatMoney: vi.fn((amount: string, currencyCode: string) => {
|
|
45
45
|
const numAmount = parseFloat(amount)
|
|
46
46
|
return currencyCode === 'USD'
|
|
@@ -6,8 +6,8 @@ import {type Product, type ProductVariant} from '@shopify/shop-minis-platform'
|
|
|
6
6
|
import {useShopNavigation} from '../../hooks/navigation/useShopNavigation'
|
|
7
7
|
import {useSavedProductsActions} from '../../hooks/user/useSavedProductsActions'
|
|
8
8
|
import {ProductReviewStars} from '../../internal/components/product-review-stars'
|
|
9
|
-
import {formatMoney} from '../../lib/formatMoney'
|
|
10
9
|
import {cn} from '../../lib/utils'
|
|
10
|
+
import {formatMoney} from '../../utils/formatMoney'
|
|
11
11
|
import {Image} from '../atoms/image'
|
|
12
12
|
import {ProductVariantPrice} from '../atoms/product-variant-price'
|
|
13
13
|
import {Touchable} from '../atoms/touchable'
|
|
@@ -28,7 +28,7 @@ vi.mock('../../hooks/user/useSavedProductsActions', () => ({
|
|
|
28
28
|
}))
|
|
29
29
|
|
|
30
30
|
// Mock formatMoney
|
|
31
|
-
vi.mock('../../
|
|
31
|
+
vi.mock('../../utils/formatMoney', () => ({
|
|
32
32
|
formatMoney: vi.fn((amount: string, currencyCode: string) => {
|
|
33
33
|
const numAmount = parseFloat(amount)
|
|
34
34
|
return currencyCode === 'USD'
|
|
@@ -7,8 +7,8 @@ import {Slot as SlotPrimitive} from 'radix-ui'
|
|
|
7
7
|
import {useShopNavigation} from '../../hooks/navigation/useShopNavigation'
|
|
8
8
|
import {useSavedProductsActions} from '../../hooks/user/useSavedProductsActions'
|
|
9
9
|
import {ProductReviewStars} from '../../internal/components/product-review-stars'
|
|
10
|
-
import {formatMoney} from '../../lib/formatMoney'
|
|
11
10
|
import {cn} from '../../lib/utils'
|
|
11
|
+
import {formatMoney} from '../../utils/formatMoney'
|
|
12
12
|
import {Touchable} from '../atoms/touchable'
|
|
13
13
|
import {Card, CardContent, CardAction} from '../ui/card'
|
|
14
14
|
|
|
@@ -107,6 +107,19 @@ export const useImageUpload = (): UseImageUploadReturns => {
|
|
|
107
107
|
throw new Error(links.error.message)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
if (links.mocked) {
|
|
111
|
+
// Skip upload and return mock data
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
id: 'uploaded-image-id',
|
|
115
|
+
imageUrl:
|
|
116
|
+
'https://cdn.shopify.com/s/files/1/0621/0463/3599/files/Mr._Bean_2007_800x800.jpg?v=1763126175',
|
|
117
|
+
resourceUrl:
|
|
118
|
+
'https://cdn.shopify.com/s/files/1/0621/0463/3599/files/Mr._Bean_2007_800x800.jpg?v=1763126175',
|
|
119
|
+
},
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
|
|
110
123
|
// Upload single file to GCS
|
|
111
124
|
const {error: uploadError} = await uploadFileToGCS(
|
|
112
125
|
processedImageParams,
|
package/src/mocks.ts
CHANGED
|
@@ -6,28 +6,50 @@ import {
|
|
|
6
6
|
} from '@shopify/shop-minis-platform'
|
|
7
7
|
import {ShopActions} from '@shopify/shop-minis-platform/actions'
|
|
8
8
|
|
|
9
|
+
const SAMPLE_IMAGE_NAMES = [
|
|
10
|
+
'garnished.jpeg',
|
|
11
|
+
'bath.jpeg',
|
|
12
|
+
'teapot.jpg',
|
|
13
|
+
'shoes.jpeg',
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
// Simple hash function to get a deterministic index from a string
|
|
17
|
+
const hashString = (str: string): number => {
|
|
18
|
+
let hash = 0
|
|
19
|
+
for (let i = 0; i < str.length; i++) {
|
|
20
|
+
hash = (hash << 5) - hash + str.charCodeAt(i)
|
|
21
|
+
hash |= 0
|
|
22
|
+
}
|
|
23
|
+
return Math.abs(hash)
|
|
24
|
+
}
|
|
25
|
+
|
|
9
26
|
// Helper functions for common data structures
|
|
10
27
|
export const createProduct = (
|
|
11
28
|
id: string,
|
|
12
29
|
title: string,
|
|
13
30
|
price = '99.99',
|
|
14
31
|
compareAtPrice?: string
|
|
15
|
-
): Product =>
|
|
16
|
-
id
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
): Product => {
|
|
33
|
+
const imageIndex = hashString(id) % SAMPLE_IMAGE_NAMES.length
|
|
34
|
+
const imageName = SAMPLE_IMAGE_NAMES[imageIndex]
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
title,
|
|
39
|
+
price: {amount: price, currencyCode: 'USD'},
|
|
40
|
+
...(compareAtPrice && {
|
|
41
|
+
compareAtPrice: {amount: compareAtPrice, currencyCode: 'USD'},
|
|
42
|
+
}),
|
|
43
|
+
reviewAnalytics: {averageRating: 4.5, reviewCount: 10},
|
|
44
|
+
shop: createShop('shop1', 'Mock Shop'),
|
|
45
|
+
defaultVariantId: `variant-${id}`,
|
|
46
|
+
isFavorited: false,
|
|
47
|
+
featuredImage: {
|
|
48
|
+
url: `https://cdn.shopify.com/static/sample-images/${imageName}`,
|
|
49
|
+
altText: title,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
}
|
|
31
53
|
|
|
32
54
|
export const createShop = (
|
|
33
55
|
id: string,
|
|
@@ -202,7 +224,11 @@ function makeMockMethod<K extends keyof ShopActions>(
|
|
|
202
224
|
): ShopActions[K] {
|
|
203
225
|
return ((params: Parameters<ShopActions[K]>[0]) => {
|
|
204
226
|
logMockAction(String(key), params)
|
|
205
|
-
return Promise.resolve({
|
|
227
|
+
return Promise.resolve({
|
|
228
|
+
ok: true as const,
|
|
229
|
+
data: result,
|
|
230
|
+
mocked: true,
|
|
231
|
+
})
|
|
206
232
|
}) as ShopActions[K]
|
|
207
233
|
}
|
|
208
234
|
|
|
@@ -249,6 +275,7 @@ export function makeMockActions(): ShopActions {
|
|
|
249
275
|
navigateToOrder: undefined,
|
|
250
276
|
navigateToCheckout: undefined,
|
|
251
277
|
createImageUploadLink: {
|
|
278
|
+
// This action is mocked in the actual hook. See `useImageUpload` for more details.
|
|
252
279
|
targets: [
|
|
253
280
|
{
|
|
254
281
|
url: 'https://example.com/upload',
|
|
@@ -262,7 +289,9 @@ export function makeMockActions(): ShopActions {
|
|
|
262
289
|
{
|
|
263
290
|
id: 'file-123',
|
|
264
291
|
fileStatus: 'READY',
|
|
265
|
-
image: {
|
|
292
|
+
image: {
|
|
293
|
+
url: 'https://example.com/image.jpg',
|
|
294
|
+
},
|
|
266
295
|
},
|
|
267
296
|
],
|
|
268
297
|
},
|
|
@@ -556,7 +585,7 @@ export const injectMocks = ({force}: {force?: boolean} = {}) => {
|
|
|
556
585
|
window.minisSDK = makeMockActions()
|
|
557
586
|
window.minisParams = {
|
|
558
587
|
handle: 'mock-handle',
|
|
559
|
-
initialUrl: '/
|
|
588
|
+
initialUrl: '/',
|
|
560
589
|
platform: 'web',
|
|
561
590
|
}
|
|
562
591
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatMoney.js","sources":["../../src/lib/formatMoney.ts"],"sourcesContent":["/**\n * Formats money amount with appropriate currency symbol\n * Uses browser's Intl.NumberFormat for consistent currency formatting\n */\nexport function formatMoney(amount: string, currencyCode: string): string {\n try {\n // Use en-US specifically for USD to get $ instead of US$\n // For other currencies, use browser locale but fallback to en-US\n const locale =\n currencyCode === 'USD' ? 'en-US' : navigator.language || 'en-US'\n\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyCode,\n }).format(Number(amount))\n } catch (error) {\n // Fallback if currency code is invalid or not supported\n console.warn(`Invalid currency code: ${currencyCode}`, error)\n return `${currencyCode} ${amount}`\n }\n}\n"],"names":["formatMoney","amount","currencyCode","locale","error"],"mappings":"AAIgB,SAAAA,EAAYC,GAAgBC,GAA8B;AACpE,MAAA;AAGF,UAAMC,IACJD,MAAiB,QAAQ,UAAU,UAAU,YAAY;AAEpD,WAAA,IAAI,KAAK,aAAaC,GAAQ;AAAA,MACnC,OAAO;AAAA,MACP,UAAUD;AAAA,IACX,CAAA,EAAE,OAAO,OAAOD,CAAM,CAAC;AAAA,WACjBG,GAAO;AAEd,mBAAQ,KAAK,0BAA0BF,CAAY,IAAIE,CAAK,GACrD,GAAGF,CAAY,IAAID,CAAM;AAAA,EAAA;AAEpC;"}
|
|
File without changes
|
|
File without changes
|