@akinon/projectzero 2.0.79-rc.0 → 2.0.79

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 (29) hide show
  1. package/CHANGELOG.md +6 -4
  2. package/app-template/.env.example +10 -1
  3. package/app-template/AGENTS.md +0 -8
  4. package/app-template/CHANGELOG.md +38 -81
  5. package/app-template/README.md +1 -25
  6. package/app-template/next.config.mjs +1 -7
  7. package/app-template/package.json +41 -41
  8. package/app-template/src/app/[pz]/layout.tsx +20 -0
  9. package/app-template/src/app/api/preview/link/route.ts +115 -0
  10. package/app-template/src/app/api/preview/route.ts +96 -0
  11. package/app-template/src/hooks/index.ts +0 -2
  12. package/app-template/src/hooks/use-fav-button.tsx +13 -35
  13. package/app-template/src/plugins.js +0 -1
  14. package/app-template/src/proxy.ts +47 -4
  15. package/app-template/src/settings.js +17 -0
  16. package/app-template/src/utils/__tests__/preview-contract.test.ts +223 -0
  17. package/app-template/src/views/category/category-info.tsx +17 -25
  18. package/app-template/src/views/header/search/index.tsx +5 -13
  19. package/app-template/src/views/product/slider.tsx +38 -85
  20. package/app-template/src/views/product-item/index.tsx +1 -1
  21. package/app-template/tailwind.config.js +2 -0
  22. package/commands/plugins.ts +0 -4
  23. package/dist/commands/plugins.js +0 -4
  24. package/package.json +1 -1
  25. package/app-template/src/app/api/client-env/route.ts +0 -5
  26. package/app-template/src/app/global-error.tsx +0 -22
  27. package/app-template/src/hooks/favourite-product-ids-context.tsx +0 -104
  28. package/app-template/src/utils/__tests__/favourite-product-ids-fallback.test.ts +0 -42
  29. package/app-template/src/utils/favourite-product-ids-fallback.ts +0 -51
@@ -36,100 +36,53 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
36
36
  carouselRef.current?.next();
37
37
  };
38
38
 
39
- const handleThumbnailClick = (index: number) => {
39
+ const handleThumbnailClick = (index) => {
40
40
  setActiveIndex(index);
41
41
  carouselRef.current?.goToSlide(index);
42
42
  };
43
43
 
44
44
  return (
45
- <>
46
- <div className="lg:grid lg:grid-cols-6">
47
- <div className="lg:col-span-1">
48
- <div className="flex flex-col items-center justify-center md:mr-[6px]">
49
- <button
50
- onClick={goToPrev}
51
- className={twMerge(
52
- 'hidden justify-center p-2 mb-3 border border-gray-100 rounded-full cursor-pointer lg:block',
53
- [activeIndex === 0 && 'cursor-not-allowed opacity-45']
54
- )}
55
- disabled={activeIndex === 0}
56
- >
57
- <Icon name="chevron-up" size={15} className="fill-[#000000]" />
58
- </button>
59
- <div className="hidden flex-col items-center overflow-scroll w-[80px] max-h-[620px] lg:block">
60
- {product?.productimage_set?.map((item, index) => (
61
- <Image
62
- key={index}
63
- src={item.image}
64
- alt={`Thumbnail ${index}`}
65
- width={80}
66
- height={128}
67
- aspectRatio={80 / 128}
68
- className={twMerge('cursor-pointer', [
69
- activeIndex === index && 'border-2 border-primary'
70
- ])}
71
- onClick={() => handleThumbnailClick(index)}
72
- />
73
- ))}
74
- </div>
75
- <button
76
- onClick={goToNext}
77
- className={twMerge(
78
- 'hidden justify-center p-2 mt-3 border border-gray-100 rounded-full cursor-pointer lg:block',
79
- [
80
- activeIndex === product.productimage_set.length - 1 &&
81
- 'cursor-not-allowed opacity-45'
82
- ]
83
- )}
84
- disabled={activeIndex === product.productimage_set.length - 1}
85
- >
86
- <Icon name="chevron-down" size={15} className="fill-[#000000]" />
87
- </button>
88
- </div>
89
- </div>
90
-
91
- <div className="relative lg:col-span-5">
92
- <FavButton className="absolute right-8 top-6 z-[20] sm:hidden" />
93
-
94
- <PluginModule
95
- component={Component.ProductImageSearchFeature}
96
- props={{
97
- product,
98
- activeIndex,
99
- showResetButton: true
100
- }}
101
- />
102
-
103
- <CarouselCore
104
- responsive={{
105
- all: {
106
- breakpoint: { max: 5000, min: 0 },
107
- items: 1
108
- }
109
- }}
110
- arrows={false}
111
- swipeable={true}
112
- ref={carouselRef}
113
- afterChange={(previousSlide, { currentSlide }) => {
114
- setActiveIndex(currentSlide);
115
- }}
116
- containerAspectRatio={{ mobile: 520 / 798, desktop: 484 / 726 }}
45
+ <div className="lg:grid lg:grid-cols-6">
46
+ <div className="lg:col-span-1">
47
+ <div className="flex flex-col items-center justify-center md:mr-[6px]">
48
+ <button
49
+ onClick={goToPrev}
50
+ className={twMerge(
51
+ 'hidden justify-center p-2 mb-3 border border-gray-100 rounded-full cursor-pointer lg:block',
52
+ [activeIndex === 0 && 'cursor-not-allowed opacity-45']
53
+ )}
54
+ disabled={activeIndex === 0}
117
55
  >
118
- {product?.productimage_set?.map((item, i) => (
56
+ <Icon name="chevron-up" size={15} className="fill-[#000000]" />
57
+ </button>
58
+ <div className="hidden flex-col items-center overflow-scroll w-[80px] max-h-[620px] lg:block">
59
+ {product?.productimage_set?.map((item, index) => (
119
60
  <Image
120
- key={i}
61
+ key={index}
121
62
  src={item.image}
122
- alt={product?.name || 'Product image'}
123
- draggable={false}
124
- aspectRatio={484 / 726}
125
- sizes="(min-width: 425px) 512px,
126
- (min-width: 601px) 576px,
127
- (min-width: 768px) 336px,
128
- (min-width: 1024px) 484px, 368px"
129
- fill
63
+ alt={`Thumbnail ${index}`}
64
+ width={80}
65
+ height={128}
66
+ className={twMerge('cursor-pointer', [
67
+ activeIndex === index && 'border-2 border-primary'
68
+ ])}
69
+ onClick={() => handleThumbnailClick(index)}
130
70
  />
131
71
  ))}
132
- </CarouselCore>
72
+ </div>
73
+ <button
74
+ onClick={goToNext}
75
+ className={twMerge(
76
+ 'hidden justify-center p-2 mt-3 border border-gray-100 rounded-full cursor-pointer lg:block',
77
+ [
78
+ activeIndex === product.productimage_set.length - 1 &&
79
+ 'cursor-not-allowed opacity-45'
80
+ ]
81
+ )}
82
+ disabled={activeIndex === product.productimage_set.length - 1}
83
+ >
84
+ <Icon name="chevron-down" size={15} className="fill-[#000000]" />
85
+ </button>
133
86
  </div>
134
87
  </div>
135
88
 
@@ -187,6 +140,6 @@ export default function ProductInfoSlider({ product }: ProductSliderItem) {
187
140
  ))}
188
141
  </CarouselCore>
189
142
  </div>
190
- </>
143
+ </div>
191
144
  );
192
145
  }
@@ -22,7 +22,7 @@ export const ProductItem = (props: Props) => {
22
22
  // TODO: Static image will change (TR)
23
23
  const { product, width, height, index } = props;
24
24
  const [viewed, setViewed] = useState(false);
25
- const { FavButton } = useFavButton(product.pk, product);
25
+ const { FavButton } = useFavButton(product.pk);
26
26
  const { ref, inView } = useInView();
27
27
 
28
28
  const image_url = product.productimage_set[0]?.image;
@@ -22,6 +22,8 @@ const defaultConfig = {
22
22
  content: [
23
23
  './node_modules/@akinon/next/**/*.{js,ts,jsx,tsx}',
24
24
  '../../node_modules/@akinon/next/**/*.{js,ts,jsx,tsx}',
25
+ './node_modules/@akinon/pz-theme/src/**/*.{js,ts,jsx,tsx}',
26
+ '../../node_modules/@akinon/pz-theme/src/**/*.{js,ts,jsx,tsx}',
25
27
  './src/app/**/*.{js,ts,jsx,tsx}',
26
28
  './src/pages/**/*.{js,ts,jsx,tsx}',
27
29
  './src/components/**/*.{js,ts,jsx,tsx}',
@@ -164,10 +164,6 @@ export default async () => {
164
164
  name: 'Tamara Payment Extension',
165
165
  value: 'pz-tamara-extension'
166
166
  },
167
- {
168
- name: 'Similar Products',
169
- value: 'pz-similar-products'
170
- },
171
167
  {
172
168
  name: 'Hepsipay',
173
169
  value: 'pz-hepsipay'
@@ -183,10 +183,6 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
183
183
  name: 'Tamara Payment Extension',
184
184
  value: 'pz-tamara-extension'
185
185
  },
186
- {
187
- name: 'Similar Products',
188
- value: 'pz-similar-products'
189
- },
190
186
  {
191
187
  name: 'Hepsipay',
192
188
  value: 'pz-hepsipay'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "2.0.79-rc.0",
3
+ "version": "2.0.79",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {
@@ -1,5 +0,0 @@
1
- export { GET } from '@akinon/next/api/client-env';
2
-
3
- // NEXT_PUBLIC_* values are read from the server runtime, not the build. Force
4
- // dynamic so Next never statically caches an (empty) build-time response.
5
- export const dynamic = 'force-dynamic';
@@ -1,22 +0,0 @@
1
- 'use client';
2
-
3
- import { useSentryUncaughtErrors } from '@akinon/next/hooks';
4
-
5
- export default function GlobalError({
6
- error,
7
- reset
8
- }: {
9
- error: Error & { digest?: string };
10
- reset: () => void;
11
- }) {
12
- useSentryUncaughtErrors(error);
13
-
14
- return (
15
- <html>
16
- <body>
17
- <h2>Something went wrong!</h2>
18
- <button onClick={() => reset()}>Try again</button>
19
- </body>
20
- </html>
21
- );
22
- }
@@ -1,104 +0,0 @@
1
- 'use client';
2
-
3
- import {
4
- createContext,
5
- ReactNode,
6
- useContext,
7
- useEffect,
8
- useMemo,
9
- useState
10
- } from 'react';
11
- import { useSession } from 'next-auth/react';
12
- import { useGetFavouriteProductIdsQuery } from '@akinon/next/data/client/wishlist';
13
- import {
14
- isFavouriteProductIdsSuspended,
15
- suspendFavouriteProductIds
16
- } from '@theme/utils/favourite-product-ids-fallback';
17
-
18
- interface FavouriteProductIdsContextValue {
19
- // False while the batch flow is unavailable (endpoint 404'd or errored), so
20
- // consumers can fall back to the legacy favourites-list request.
21
- isActive: boolean;
22
- getFavouriteId: (productPk: number) => number | undefined;
23
- }
24
-
25
- const FavouriteProductIdsContext =
26
- createContext<FavouriteProductIdsContextValue | null>(null);
27
-
28
- export const useFavouriteProductIds = () =>
29
- useContext(FavouriteProductIdsContext);
30
-
31
- type Phase = 'init' | 'batch' | 'fallback';
32
-
33
- interface FavouriteProductIdsProviderProps {
34
- productIds: Array<number | string>;
35
- children: ReactNode;
36
- }
37
-
38
- export function FavouriteProductIdsProvider({
39
- productIds,
40
- children
41
- }: FavouriteProductIdsProviderProps) {
42
- const { status } = useSession();
43
-
44
- // Storage can only be read on the client, so the first render stays neutral
45
- // to keep SSR and hydration output identical.
46
- const [phase, setPhase] = useState<Phase>('init');
47
-
48
- useEffect(() => {
49
- setPhase(isFavouriteProductIdsSuspended() ? 'fallback' : 'batch');
50
- }, []);
51
-
52
- const sortedProductIds = useMemo(() => {
53
- const unique = Array.from(
54
- new Set(productIds.map(Number).filter((id) => Number.isFinite(id)))
55
- );
56
- // Stable order keeps the RTK Query cache key deterministic for the page.
57
- return unique.sort((a, b) => a - b);
58
- }, [productIds]);
59
-
60
- const { data, error } = useGetFavouriteProductIdsQuery(
61
- { productIds: sortedProductIds },
62
- {
63
- skip:
64
- status !== 'authenticated' ||
65
- phase !== 'batch' ||
66
- sortedProductIds.length === 0
67
- }
68
- );
69
-
70
- useEffect(() => {
71
- if (!error) return;
72
-
73
- if ('status' in error && error.status === 404) {
74
- suspendFavouriteProductIds();
75
- }
76
-
77
- setPhase('fallback');
78
- }, [error]);
79
-
80
- const favouriteIdByProductPk = useMemo(() => {
81
- const map = new Map<number, number>();
82
-
83
- data?.favourite_products?.forEach((item) => {
84
- map.set(Number(item.product_id), item.favourite_id);
85
- });
86
-
87
- return map;
88
- }, [data]);
89
-
90
- const value = useMemo<FavouriteProductIdsContextValue>(
91
- () => ({
92
- isActive: phase !== 'fallback',
93
- getFavouriteId: (productPk: number) =>
94
- favouriteIdByProductPk.get(Number(productPk))
95
- }),
96
- [phase, favouriteIdByProductPk]
97
- );
98
-
99
- return (
100
- <FavouriteProductIdsContext.Provider value={value}>
101
- {children}
102
- </FavouriteProductIdsContext.Provider>
103
- );
104
- }
@@ -1,42 +0,0 @@
1
- import {
2
- FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS,
3
- isFavouriteProductIdsSuspended,
4
- suspendFavouriteProductIds
5
- } from '../favourite-product-ids-fallback';
6
-
7
- const STORAGE_KEY = 'pz-favourite-product-ids-unavailable-until';
8
-
9
- describe('favourite-product-ids-fallback', () => {
10
- beforeEach(() => {
11
- window.localStorage.clear();
12
- });
13
-
14
- it('is not suspended by default', () => {
15
- expect(isFavouriteProductIdsSuspended()).toBe(false);
16
- });
17
-
18
- it('suspends after a 404 marker is written', () => {
19
- suspendFavouriteProductIds();
20
-
21
- expect(isFavouriteProductIdsSuspended()).toBe(true);
22
-
23
- const until = Number(window.localStorage.getItem(STORAGE_KEY));
24
- expect(until).toBeGreaterThan(Date.now());
25
- expect(until).toBeLessThanOrEqual(
26
- Date.now() + FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS
27
- );
28
- });
29
-
30
- it('expires the suspension and clears the marker', () => {
31
- window.localStorage.setItem(STORAGE_KEY, String(Date.now() - 1000));
32
-
33
- expect(isFavouriteProductIdsSuspended()).toBe(false);
34
- expect(window.localStorage.getItem(STORAGE_KEY)).toBeNull();
35
- });
36
-
37
- it('treats a corrupt marker as not suspended', () => {
38
- window.localStorage.setItem(STORAGE_KEY, 'not-a-number');
39
-
40
- expect(isFavouriteProductIdsSuspended()).toBe(false);
41
- });
42
- });
@@ -1,51 +0,0 @@
1
- const STORAGE_KEY = 'pz-favourite-product-ids-unavailable-until';
2
-
3
- // Not every brand's backend ships the favourite-product-ids endpoint at the
4
- // same time, so a 404 suspends the new flow for this long before probing again.
5
- export const FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS = 6 * 60 * 60 * 1000;
6
-
7
- const getStorage = (): Storage | null => {
8
- try {
9
- // The property access itself is what throws when storage is blocked, so it
10
- // has to be inside the try rather than guarded by a typeof check.
11
- return typeof window === 'undefined' ? null : window.localStorage ?? null;
12
- } catch {
13
- return null;
14
- }
15
- };
16
-
17
- // Fails open: when storage is unavailable the endpoint is probed again, which
18
- // at worst costs one extra 404 per page view.
19
- export const isFavouriteProductIdsSuspended = (): boolean => {
20
- const storage = getStorage();
21
- if (!storage) return false;
22
-
23
- try {
24
- const raw = storage.getItem(STORAGE_KEY);
25
- if (!raw) return false;
26
-
27
- const until = Number(raw);
28
- if (!Number.isFinite(until) || Date.now() >= until) {
29
- storage.removeItem(STORAGE_KEY);
30
- return false;
31
- }
32
-
33
- return true;
34
- } catch {
35
- return false;
36
- }
37
- };
38
-
39
- export const suspendFavouriteProductIds = (): void => {
40
- const storage = getStorage();
41
- if (!storage) return;
42
-
43
- try {
44
- storage.setItem(
45
- STORAGE_KEY,
46
- String(Date.now() + FAVOURITE_PRODUCT_IDS_RETRY_AFTER_MS)
47
- );
48
- } catch {
49
- // Fail open; see isFavouriteProductIdsSuspended.
50
- }
51
- };