Skip to content

Commit 6445f0b

Browse files
committed
feat(docs): add Storefront Data SKILL
1 parent b48a642 commit 6445f0b

12 files changed

Lines changed: 645 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: storefront-data-auth
3+
description: Customer authentication integration for @techsio/storefront-data. Use when implementing auth state, login/register/logout mutations, customer profile updates, and auth-related cache invalidation with Medusa.
4+
---
5+
6+
# Storefront Data Auth
7+
8+
Implement auth through the auth module to keep session and cache invalidation coherent.
9+
10+
## Workflow
11+
12+
1. Create service with `createMedusaAuthService(sdk)`.
13+
2. Create hooks with `createAuthHooks` and shared namespace.
14+
3. Optionally define `invalidateOnAuthChange` for custom cross-domain keys.
15+
4. Use `useAuth` for session state and mutation hooks for auth actions.
16+
17+
## Example
18+
19+
```ts
20+
import {
21+
createAuthHooks,
22+
createAuthQueryKeys,
23+
createMedusaAuthService,
24+
} from "@techsio/storefront-data"
25+
import { cacheConfig, sdk, STOREFRONT_NAMESPACE } from "@/lib/storefront-data/shared"
26+
27+
const authService = createMedusaAuthService(sdk)
28+
const authQueryKeys = createAuthQueryKeys(STOREFRONT_NAMESPACE)
29+
30+
export const authHooks = createAuthHooks({
31+
service: authService,
32+
queryKeys: authQueryKeys,
33+
cacheConfig,
34+
invalidateOnAuthChange: {
35+
includeDefaults: true,
36+
},
37+
})
38+
```
39+
40+
## Returned Hooks
41+
42+
- `useAuth`, `useSuspenseAuth`
43+
- `useLogin`, `useRegister`, `useLogout`
44+
- `useCreateCustomer`, `useUpdateCustomer`, `useRefreshAuth`
45+
46+
## Rules
47+
48+
- Prefer `createMedusaAuthService` registration flow: register -> login -> customer create -> refresh.
49+
- Keep `useAuth` query `retry: false` behavior for auth-state checks.
50+
- On logout, assume auth cache is removed; refresh dependent modules after logout redirect.
51+
- Use `userData` cache strategy for auth profile data.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: storefront-data-cart
3+
description: Cart lifecycle integration for @techsio/storefront-data. Use when implementing cart retrieval/creation, line item mutations, address updates, cart transfer/complete flow, and cart storage persistence in storefront apps.
4+
---
5+
6+
# Storefront Data Cart
7+
8+
Implement cart behavior with the cart factory to preserve auto-create, region sync, and cache semantics.
9+
10+
## Workflow
11+
12+
1. Create `cartStorage` for persistent cart id.
13+
2. Create service with `createMedusaCartService(sdk)`.
14+
3. Create hooks with `createCartHooks` and pass `cartStorage`.
15+
4. Use `useCart` as cart source of truth in UI.
16+
5. Use provided mutations (`useAddLineItem`, `useUpdateCartAddress`, etc.) for all writes.
17+
18+
## Example
19+
20+
```ts
21+
import {
22+
createCartHooks,
23+
createCartQueryKeys,
24+
createMedusaCartService,
25+
} from "@techsio/storefront-data"
26+
import { cacheConfig, sdk, STOREFRONT_NAMESPACE } from "@/lib/storefront-data/shared"
27+
28+
const cartStorage = {
29+
getCartId: () => localStorage.getItem("cart_id"),
30+
setCartId: (id: string) => localStorage.setItem("cart_id", id),
31+
clearCartId: () => localStorage.removeItem("cart_id"),
32+
}
33+
34+
const cartService = createMedusaCartService(sdk)
35+
const cartQueryKeys = createCartQueryKeys(STOREFRONT_NAMESPACE)
36+
37+
export const cartHooks = createCartHooks({
38+
service: cartService,
39+
queryKeys: cartQueryKeys,
40+
cacheConfig,
41+
cartStorage,
42+
requireRegion: true,
43+
})
44+
```
45+
46+
## Returned Hooks
47+
48+
- `useCart`, `useSuspenseCart`
49+
- `useCreateCart`, `useUpdateCart`, `useUpdateCartAddress`
50+
- `useAddLineItem`, `useUpdateLineItem`, `useRemoveLineItem`
51+
- `useTransferCart`, `useCompleteCart`
52+
- `usePrefetchCart`
53+
54+
## Rules
55+
56+
- Keep `autoCreate` enabled unless app explicitly requires manual cart creation.
57+
- Pass region (`region_id`) or provide `RegionProvider` when `requireRegion` is true.
58+
- Use address normalization/validation callbacks for checkout-safe payloads.
59+
- Decide explicitly whether to clear storage after completion via `clearCartOnSuccess` option.
60+
- Use `realtime` cache strategy for cart data.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: storefront-data-categories
3+
description: Category list/detail integration for @techsio/storefront-data. Use when implementing product category hooks, Medusa category service mapping, and category query key strategy in storefront apps.
4+
---
5+
6+
# Storefront Data Categories
7+
8+
Implement category data through the module factory to preserve pagination and cache behavior.
9+
10+
## Workflow
11+
12+
1. Create service with `createMedusaCategoryService`.
13+
2. Configure optional list/detail query normalization and transforms.
14+
3. Create hooks with `createCategoryHooks` and shared namespace.
15+
4. Use built-in prefetch hooks for menu/navigation UX.
16+
17+
## Example
18+
19+
```ts
20+
import {
21+
createCategoryHooks,
22+
createCategoryQueryKeys,
23+
createMedusaCategoryService,
24+
} from "@techsio/storefront-data"
25+
import { cacheConfig, sdk, STOREFRONT_NAMESPACE } from "@/lib/storefront-data/shared"
26+
27+
const categoryService = createMedusaCategoryService(sdk, {
28+
defaultListFields: "id,name,handle,parent_category_id",
29+
defaultDetailFields: "id,name,handle,parent_category_id",
30+
})
31+
32+
const categoryQueryKeys = createCategoryQueryKeys(STOREFRONT_NAMESPACE)
33+
34+
export const categoryHooks = createCategoryHooks({
35+
service: categoryService,
36+
queryKeys: categoryQueryKeys,
37+
cacheConfig,
38+
})
39+
```
40+
41+
## Returned Hooks
42+
43+
- `useCategories`, `useSuspenseCategories`
44+
- `useCategory`, `useSuspenseCategory`
45+
- `usePrefetchCategories`, `usePrefetchCategory`
46+
47+
## Rules
48+
49+
- Keep category cache `static` unless business rules require quicker refresh.
50+
- Throw early for missing `id` in suspense detail usage.
51+
- Keep query-key params normalized and deterministic.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: storefront-data-checkout
3+
description: Checkout shipping/payment integration for @techsio/storefront-data. Use when implementing shipping option selection, calculated shipping prices, payment provider loading, and payment session initiation tied to cart state.
4+
---
5+
6+
# Storefront Data Checkout
7+
8+
Wire checkout with cart hooks so shipping/payment mutations keep cart cache consistent.
9+
10+
## Workflow
11+
12+
1. Create checkout service with `createMedusaCheckoutService(sdk)`.
13+
2. Create hooks with `createCheckoutHooks`.
14+
3. Pass `cartQueryKeys` from cart module to sync/refresh cart cache after mutations.
15+
4. Use shipping hook first, then payment hook.
16+
17+
## Example
18+
19+
```ts
20+
import {
21+
createCheckoutHooks,
22+
createCheckoutQueryKeys,
23+
createMedusaCheckoutService,
24+
} from "@techsio/storefront-data"
25+
import { cartQueryKeys } from "@/lib/storefront-data/cart"
26+
import { cacheConfig, sdk, STOREFRONT_NAMESPACE } from "@/lib/storefront-data/shared"
27+
28+
const checkoutService = createMedusaCheckoutService(sdk)
29+
const checkoutQueryKeys = createCheckoutQueryKeys(STOREFRONT_NAMESPACE)
30+
31+
export const checkoutHooks = createCheckoutHooks({
32+
service: checkoutService,
33+
queryKeys: checkoutQueryKeys,
34+
cartQueryKeys,
35+
cacheConfig,
36+
})
37+
```
38+
39+
## Returned Hooks
40+
41+
- `useCheckoutShipping`, `useSuspenseCheckoutShipping`
42+
- `useCheckoutPayment`, `useSuspenseCheckoutPayment`
43+
- `getPaymentProvidersQueryOptions`, `fetchPaymentProviders`
44+
45+
## Rules
46+
47+
- Require `cartId` for shipping mutation and payment initiation.
48+
- Use shipping method before payment session; `canInitiatePayment` depends on it.
49+
- Use `cacheKey` in shipping queries when option visibility depends on external checkout state.
50+
- Keep payment providers on `semiStatic` cache; shipping options/prices on `realtime` cache.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: storefront-data-client
3+
description: Client-side setup for @techsio/storefront-data. Use when adding StorefrontDataProvider, browser QueryClient lifecycle, or client hydration boundaries in a React/Next.js storefront app.
4+
---
5+
6+
# Storefront Data Client
7+
8+
Implement the client provider once and reuse it in all routes.
9+
10+
## Workflow
11+
12+
1. Create `providers.tsx` client component in app.
13+
2. Wrap tree with `StorefrontDataProvider`.
14+
3. Optionally pass `clientConfig` only on first initialization.
15+
4. Keep provider in client boundary (`"use client"`).
16+
17+
## Example
18+
19+
```tsx
20+
"use client"
21+
22+
import type { ReactNode } from "react"
23+
import { StorefrontDataProvider } from "@techsio/storefront-data/client"
24+
25+
export function Providers({ children }: { children: ReactNode }) {
26+
return <StorefrontDataProvider>{children}</StorefrontDataProvider>
27+
}
28+
```
29+
30+
## Advanced
31+
32+
Use custom query client config only when needed:
33+
34+
```tsx
35+
<StorefrontDataProvider
36+
clientConfig={{
37+
defaultOptions: {
38+
queries: { retry: false },
39+
},
40+
}}
41+
>
42+
{children}
43+
</StorefrontDataProvider>
44+
```
45+
46+
## Rules
47+
48+
- Do not create multiple browser singletons manually; prefer `StorefrontDataProvider`.
49+
- Do not place `StorefrontDataProvider` in server component files.
50+
- If you need isolated cache (tests/storybook), pass explicit `client` prop.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: storefront-data-collections
3+
description: Collection list/detail integration for @techsio/storefront-data. Use when wiring collection hooks, Medusa collection service transforms, and collection prefetch behavior in a storefront app.
4+
---
5+
6+
# Storefront Data Collections
7+
8+
Use the collection factory to keep list/detail behavior and cache policies consistent.
9+
10+
## Workflow
11+
12+
1. Create service with `createMedusaCollectionService`.
13+
2. Optionally normalize list/detail queries and map Medusa payload to app entity.
14+
3. Create hooks via `createCollectionHooks`.
15+
4. Use prefetch hooks for list/detail route transitions.
16+
17+
## Example
18+
19+
```ts
20+
import {
21+
createCollectionHooks,
22+
createCollectionQueryKeys,
23+
createMedusaCollectionService,
24+
} from "@techsio/storefront-data"
25+
import { cacheConfig, sdk, STOREFRONT_NAMESPACE } from "@/lib/storefront-data/shared"
26+
27+
const collectionService = createMedusaCollectionService(sdk, {
28+
defaultListFields: "id,title,handle",
29+
defaultDetailFields: "id,title,handle,metadata",
30+
})
31+
32+
const collectionQueryKeys = createCollectionQueryKeys(
33+
STOREFRONT_NAMESPACE
34+
)
35+
36+
export const collectionHooks = createCollectionHooks({
37+
service: collectionService,
38+
queryKeys: collectionQueryKeys,
39+
cacheConfig,
40+
})
41+
```
42+
43+
## Returned Hooks
44+
45+
- `useCollections`, `useSuspenseCollections`
46+
- `useCollection`, `useSuspenseCollection`
47+
- `usePrefetchCollections`, `usePrefetchCollection`
48+
49+
## Rules
50+
51+
- Use `static` cache strategy as default for collections.
52+
- Require `id` for detail suspense hook.
53+
- Keep `enabled` and UI flags out of API payload/query keys.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: storefront-data-customers
3+
description: Customer profile/address integration for @techsio/storefront-data. Use when implementing customer address CRUD, profile updates, address input normalization/validation, and auth profile cache synchronization.
4+
---
5+
6+
# Storefront Data Customers
7+
8+
Use customer hooks for account profile + address book operations.
9+
10+
## Workflow
11+
12+
1. Create service with `createMedusaCustomerService(sdk)`.
13+
2. Create hooks with `createCustomerHooks`.
14+
3. Pass `authQueryKeys.customer` when custom auth keys are used.
15+
4. Add input normalization and validation callbacks for address write safety.
16+
17+
## Example
18+
19+
```ts
20+
import {
21+
createCustomerHooks,
22+
createCustomerQueryKeys,
23+
createMedusaCustomerService,
24+
} from "@techsio/storefront-data"
25+
import { authQueryKeys } from "@/lib/storefront-data/auth"
26+
import { cacheConfig, sdk, STOREFRONT_NAMESPACE } from "@/lib/storefront-data/shared"
27+
28+
const customerService = createMedusaCustomerService(sdk)
29+
const customerQueryKeys = createCustomerQueryKeys(STOREFRONT_NAMESPACE)
30+
31+
export const customerHooks = createCustomerHooks({
32+
service: customerService,
33+
queryKeys: customerQueryKeys,
34+
authQueryKeys,
35+
cacheConfig,
36+
validateCreateAddressInput: (input) => {
37+
if (!input.first_name || !input.address_1 || !input.country_code) {
38+
return "Missing required address fields"
39+
}
40+
return null
41+
},
42+
})
43+
```
44+
45+
## Returned Hooks
46+
47+
- `useCustomerAddresses`, `useSuspenseCustomerAddresses`
48+
- `useCreateCustomerAddress`, `useUpdateCustomerAddress`, `useDeleteCustomerAddress`
49+
- `useUpdateCustomer`
50+
51+
## Rules
52+
53+
- In `useUpdateCustomerAddress`, provide `addressId` and remove it from payload mapper.
54+
- Keep profile/address data on `userData` cache strategy.
55+
- Invalidate both customer profile and auth customer keys after profile updates.

0 commit comments

Comments
 (0)