Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Run biome lint:fix across admin + admin-sdk

Damian Legawiec2178c6233b24
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index f2f854df28..f53d67fc12 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -148,8 +148,8 @@ import type {
AdminUser,
ApiKey,
Category,
- CouponCode,
Country,
+ CouponCode,
CreditCard,
Customer,
CustomerGroup,
@@ -975,11 +975,7 @@ export class AdminClient {
{ ...options, params: params ? transformListParams(params) : undefined },
),
- get: (
- promotionId: string,
- id: string,
- options?: RequestOptions,
- ): Promise<PromotionAction> =>
+ get: (promotionId: string, id: string, options?: RequestOptions): Promise<PromotionAction> =>
this.request<PromotionAction>(
'GET',
`/promotions/${promotionId}/promotion_actions/${id}`,
@@ -991,11 +987,10 @@ export class AdminClient {
params: PromotionActionCreateParams,
options?: RequestOptions,
): Promise<PromotionAction> =>
- this.request<PromotionAction>(
- 'POST',
- `/promotions/${promotionId}/promotion_actions`,
- { ...options, body: params },
- ),
+ this.request<PromotionAction>('POST', `/promotions/${promotionId}/promotion_actions`, {
+ ...options,
+ body: params,
+ }),
update: (
promotionId: string,
@@ -1010,11 +1005,7 @@ export class AdminClient {
),
delete: (promotionId: string, id: string, options?: RequestOptions): Promise<void> =>
- this.request<void>(
- 'DELETE',
- `/promotions/${promotionId}/promotion_actions/${id}`,
- options,
- ),
+ this.request<void>('DELETE', `/promotions/${promotionId}/promotion_actions/${id}`, options),
},
rules: {
@@ -1029,11 +1020,7 @@ export class AdminClient {
{ ...options, params: params ? transformListParams(params) : undefined },
),
- get: (
- promotionId: string,
- id: string,
- options?: RequestOptions,
- ): Promise<PromotionRule> =>
+ get: (promotionId: string, id: string, options?: RequestOptions): Promise<PromotionRule> =>
this.request<PromotionRule>(
'GET',
`/promotions/${promotionId}/promotion_rules/${id}`,
@@ -1045,11 +1032,10 @@ export class AdminClient {
params: PromotionRuleCreateParams,
options?: RequestOptions,
): Promise<PromotionRule> =>
- this.request<PromotionRule>(
- 'POST',
- `/promotions/${promotionId}/promotion_rules`,
- { ...options, body: params },
- ),
+ this.request<PromotionRule>('POST', `/promotions/${promotionId}/promotion_rules`, {
+ ...options,
+ body: params,
+ }),
update: (
promotionId: string,
@@ -1057,18 +1043,13 @@ export class AdminClient {
params: PromotionRuleUpdateParams,
options?: RequestOptions,
): Promise<PromotionRule> =>
- this.request<PromotionRule>(
- 'PATCH',
- `/promotions/${promotionId}/promotion_rules/${id}`,
- { ...options, body: params },
- ),
+ this.request<PromotionRule>('PATCH', `/promotions/${promotionId}/promotion_rules/${id}`, {
+ ...options,
+ body: params,
+ }),
delete: (promotionId: string, id: string, options?: RequestOptions): Promise<void> =>
- this.request<void>(
- 'DELETE',
- `/promotions/${promotionId}/promotion_rules/${id}`,
- options,
- ),
+ this.request<void>('DELETE', `/promotions/${promotionId}/promotion_rules/${id}`, options),
},
couponCodes: {
@@ -1084,40 +1065,27 @@ export class AdminClient {
),
get: (promotionId: string, id: string, options?: RequestOptions): Promise<CouponCode> =>
- this.request<CouponCode>(
- 'GET',
- `/promotions/${promotionId}/coupon_codes/${id}`,
- options,
- ),
+ this.request<CouponCode>('GET', `/promotions/${promotionId}/coupon_codes/${id}`, options),
},
}
readonly promotionActions = {
types: (options?: RequestOptions): Promise<{ data: ResourceTypeDefinition[] }> =>
- this.request<{ data: ResourceTypeDefinition[] }>(
- 'GET',
- '/promotion_actions/types',
- options,
- ),
+ this.request<{ data: ResourceTypeDefinition[] }>('GET', '/promotion_actions/types', options),
calculators: (
type: string,
options?: RequestOptions,
): Promise<{ data: PromotionActionCalculator[] }> =>
- this.request<{ data: PromotionActionCalculator[] }>(
- 'GET',
- '/promotion_actions/calculators',
- { ...options, params: { type } },
- ),
+ this.request<{ data: PromotionActionCalculator[] }>('GET', '/promotion_actions/calculators', {
+ ...options,
+ params: { type },
+ }),
}
readonly promotionRules = {
types: (options?: RequestOptions): Promise<{ data: ResourceTypeDefinition[] }> =>
- this.request<{ data: ResourceTypeDefinition[] }>(
- 'GET',
- '/promotion_rules/types',
- options,
- ),
+ this.request<{ data: ResourceTypeDefinition[] }>('GET', '/promotion_rules/types', options),
}
// ============================================
diff --git a/packages/admin-sdk/src/types/index.ts b/packages/admin-sdk/src/types/index.ts
index 7f28ef2aa8..30ff9018a2 100644
--- a/packages/admin-sdk/src/types/index.ts
+++ b/packages/admin-sdk/src/types/index.ts
@@ -15,8 +15,8 @@ export type { default as AdminUser } from './generated/AdminUser'
export type { default as AllowedOrigin } from './generated/AllowedOrigin'
export type { default as ApiKey } from './generated/ApiKey'
export type { default as Category } from './generated/Category'
-export type { default as CouponCode } from './generated/CouponCode'
export type { default as Country } from './generated/Country'
+export type { default as CouponCode } from './generated/CouponCode'
export type { default as CreditCard } from './generated/CreditCard'
export type { default as Customer } from './generated/Customer'
export type { default as CustomerGroup } from './generated/CustomerGroup'
diff --git a/packages/admin/src/components/spree/calculator-summary.tsx b/packages/admin/src/components/spree/calculator-summary.tsx
index 06d7e134b6..c1ac82887e 100644
--- a/packages/admin/src/components/spree/calculator-summary.tsx
+++ b/packages/admin/src/components/spree/calculator-summary.tsx
@@ -32,7 +32,11 @@ interface CalculatorSummaryProps {
className?: string
}
-export function CalculatorSummary({ calculator, fallback = null, className }: CalculatorSummaryProps) {
+export function CalculatorSummary({
+ calculator,
+ fallback = null,
+ className,
+}: CalculatorSummaryProps) {
const text = formatCalculatorSummary(calculator)
if (!text) return <>{fallback}</>
return <span className={className}>{text}</span>
@@ -43,7 +47,9 @@ export function CalculatorSummary({ calculator, fallback = null, className }: Ca
* inside a larger sentence (e.g. "Free shipping · {summary}") or use
* it in a non-React context.
*/
-export function formatCalculatorSummary(calculator: CalculatorPayload | null | undefined): string | null {
+export function formatCalculatorSummary(
+ calculator: CalculatorPayload | null | undefined,
+): string | null {
if (!calculator) return null
const label =
diff --git a/packages/admin/src/components/spree/preferences-form.tsx b/packages/admin/src/components/spree/preferences-form.tsx
index e4a41b084c..b5e2d590fe 100644
--- a/packages/admin/src/components/spree/preferences-form.tsx
+++ b/packages/admin/src/components/spree/preferences-form.tsx
@@ -82,11 +82,7 @@ export function PreferenceField({
return (
<Field>
<FieldLabel htmlFor={id}>{displayLabel}</FieldLabel>
- <CurrencySelect
- id={id}
- value={(value as string) || undefined}
- onChange={onChange}
- />
+ <CurrencySelect id={id} value={(value as string) || undefined} onChange={onChange} />
</Field>
)
}
diff --git a/packages/admin/src/components/spree/promotion-editors/action-adjustment.tsx b/packages/admin/src/components/spree/promotion-editors/action-adjustment.tsx
index c9cfd37444..2b9bfdec46 100644
--- a/packages/admin/src/components/spree/promotion-editors/action-adjustment.tsx
+++ b/packages/admin/src/components/spree/promotion-editors/action-adjustment.tsx
@@ -19,11 +19,7 @@ import type { PromotionActionEditorContext } from './types'
* `CreateItemAdjustments`. Both wrap a Calculator: the merchant picks
* the subclass, the form below renders that calculator's preferences.
*/
-export function AdjustmentActionEditor({
- draft,
- onSave,
- onClose,
-}: PromotionActionEditorContext) {
+export function AdjustmentActionEditor({ draft, onSave, onClose }: PromotionActionEditorContext) {
const { data: calculatorsData, isLoading: calculatorsLoading } = useQuery({
queryKey: ['promotion-action-calculators', draft.type],
queryFn: () => adminClient.promotionActions.calculators(draft.type),
@@ -31,9 +27,7 @@ export function AdjustmentActionEditor({
const calculators = calculatorsData?.data ?? []
- const [calculatorType, setCalculatorType] = useState<string>(
- () => draft.calculator?.type ?? '',
- )
+ const [calculatorType, setCalculatorType] = useState<string>(() => draft.calculator?.type ?? '')
const [preferences, setPreferences] = useState<Record<string, unknown>>(
() => draft.calculator?.preferences ?? {},
)
@@ -99,9 +93,7 @@ export function AdjustmentActionEditor({
<SelectValue
placeholder={calculatorsLoading ? 'Loading calculators…' : 'Select a calculator'}
>
- {(value) =>
- calculators.find((c) => c.type === value)?.label ?? (value as string)
- }
+ {(value) => calculators.find((c) => c.type === value)?.label ?? (value as string)}
</SelectValue>
</SelectTrigger>
<SelectContent>
@@ -142,11 +134,7 @@ function CalculatorPreferences({
return (
<FieldGroup>
<FieldLabel>Calculator settings</FieldLabel>
- <PreferencesForm
- schema={calculator.preference_schema}
- values={values}
- onChange={onChange}
- />
+ <PreferencesForm schema={calculator.preference_schema} values={values} onChange={onChange} />
</FieldGroup>
)
}
diff --git a/packages/admin/src/components/spree/promotion-editors/editor-shell.tsx b/packages/admin/src/components/spree/promotion-editors/editor-shell.tsx
index c518be467b..05834b184b 100644
--- a/packages/admin/src/components/spree/promotion-editors/editor-shell.tsx
+++ b/packages/admin/src/components/spree/promotion-editors/editor-shell.tsx
@@ -27,21 +27,10 @@ export function EditorShell({
<>
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4">{children}</div>
<SheetFooter>
- <Button
- type="button"
- variant="outline"
- size="sm"
- onClick={onCancel}
- disabled={pending}
- >
+ <Button type="button" variant="outline" size="sm" onClick={onCancel} disabled={pending}>
Cancel
</Button>
- <Button
- type="button"
- size="sm"
- onClick={() => onSave()}
- disabled={pending || saveDisabled}
- >
+ <Button type="button" size="sm" onClick={() => onSave()} disabled={pending || saveDisabled}>
{pending ? 'Saving…' : saveLabel}
</Button>
</SheetFooter>
diff --git a/packages/admin/src/components/spree/promotion-editors/rule-category.tsx b/packages/admin/src/components/spree/promotion-editors/rule-category.tsx
index 808b8f4d71..b70101bb93 100644
--- a/packages/admin/src/components/spree/promotion-editors/rule-category.tsx
+++ b/packages/admin/src/components/spree/promotion-editors/rule-category.tsx
@@ -27,7 +27,8 @@ const MATCH_POLICIES: readonly { value: MatchPolicy; label: string; description:
* ships; descendant categories match implicitly server-side.
*/
export function CategoryRuleEditor({ draft, onSave, onClose }: PromotionRuleEditorContext) {
- const initialMatchPolicy = ((draft.preferences?.match_policy as MatchPolicy) ?? 'any') as MatchPolicy
+ const initialMatchPolicy = ((draft.preferences?.match_policy as MatchPolicy) ??
+ 'any') as MatchPolicy
const [matchPolicy, setMatchPolicy] = useState<MatchPolicy>(
MATCH_POLICIES.some((p) => p.value === initialMatchPolicy) ? initialMatchPolicy : 'any',
)
diff --git a/packages/admin/src/components/spree/promotion-editors/rule-customer-group.tsx b/packages/admin/src/components/spree/promotion-editors/rule-customer-group.tsx
index 021e7490ef..a46208c84f 100644
--- a/packages/admin/src/components/spree/promotion-editors/rule-customer-group.tsx
+++ b/packages/admin/src/components/spree/promotion-editors/rule-customer-group.tsx
@@ -10,9 +10,7 @@ export function CustomerGroupRuleEditor({ draft, onSave, onClose }: PromotionRul
const [groupIds, setGroupIds] = useState<string[]>(
() => (draft.preferences?.customer_group_ids ?? []) as string[],
)
- const [customerGroups, setCustomerGroups] = useState<CustomerGroup[]>(
- draft.customer_groups ?? [],
- )
+ const [customerGroups, setCustomerGroups] = useState<CustomerGroup[]>(draft.customer_groups ?? [])
function handleSave() {
onSave({
diff --git a/packages/admin/src/components/spree/promotion-editors/rule-product.tsx b/packages/admin/src/components/spree/promotion-editors/rule-product.tsx
index a8d8839f61..c3907f13d3 100644
--- a/packages/admin/src/components/spree/promotion-editors/rule-product.tsx
+++ b/packages/admin/src/components/spree/promotion-editors/rule-product.tsx
@@ -10,7 +10,11 @@ import type { PromotionRuleEditorContext } from './types'
type MatchPolicy = 'any' | 'all' | 'none'
const MATCH_POLICIES: readonly { value: MatchPolicy; label: string; description: string }[] = [
{ value: 'any', label: 'Any of these products', description: 'Order must contain at least one.' },
- { value: 'all', label: 'All of these products', description: 'Order must contain every product.' },
+ {
+ value: 'all',
+ label: 'All of these products',
+ description: 'Order must contain every product.',
+ },
{
value: 'none',
label: 'None of these products',
@@ -19,7 +23,8 @@ const MATCH_POLICIES: readonly { value: MatchPolicy; label: string; description:
]
export function ProductRuleEditor({ draft, onSave, onClose }: PromotionRuleEditorContext) {
- const initialMatchPolicy = ((draft.preferences?.match_policy as MatchPolicy) ?? 'any') as MatchPolicy
+ const initialMatchPolicy = ((draft.preferences?.match_policy as MatchPolicy) ??
+ 'any') as MatchPolicy
const [matchPolicy, setMatchPolicy] = useState<MatchPolicy>(
MATCH_POLICIES.some((p) => p.value === initialMatchPolicy) ? initialMatchPolicy : 'any',
)
diff --git a/packages/admin/src/components/spree/promotion-editors/types.ts b/packages/admin/src/components/spree/promotion-editors/types.ts
index 8cc3807078..6e9385daa2 100644
--- a/packages/admin/src/components/spree/promotion-editors/types.ts
+++ b/packages/admin/src/components/spree/promotion-editors/types.ts
@@ -141,7 +141,12 @@ export function ruleDraftFromType(type: {
return {
_localId: newLocalId(),
type: type.type,
- key: type.type.split('::').pop()?.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase() ?? type.type,
+ key:
+ type.type
+ .split('::')
+ .pop()
+ ?.replace(/([a-z])([A-Z])/g, '$1_$2')
+ .toLowerCase() ?? type.type,
label: type.label,
preference_schema: type.preference_schema,
preferences: defaultPreferences(type.preference_schema),
@@ -156,7 +161,12 @@ export function actionDraftFromType(type: {
return {
_localId: newLocalId(),
type: type.type,
- key: type.type.split('::').pop()?.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase() ?? type.type,
+ key:
+ type.type
+ .split('::')
+ .pop()
+ ?.replace(/([a-z])([A-Z])/g, '$1_$2')
+ .toLowerCase() ?? type.type,
label: type.label,
preference_schema: type.preference_schema,
preferences: defaultPreferences(type.preference_schema),
@@ -246,7 +256,4 @@ export function actionDraftToPayload(draft: PromotionActionFormDraft): Promotion
}
// Re-exports for convenience (editors only need to import from one place).
-export type {
- PromotionActionCalculatorParams,
- PromotionActionLineItemParams,
-}
+export type { PromotionActionCalculatorParams, PromotionActionLineItemParams }
diff --git a/packages/admin/src/components/spree/resource-multi-autocomplete.tsx b/packages/admin/src/components/spree/resource-multi-autocomplete.tsx
index 8760f91778..efb09ebe80 100644
--- a/packages/admin/src/components/spree/resource-multi-autocomplete.tsx
+++ b/packages/admin/src/components/spree/resource-multi-autocomplete.tsx
@@ -118,10 +118,7 @@ export function ResourceMultiAutocomplete<T extends AutocompleteOption>({
// Hydrate any selected ID not yet in the cache. Recomputed when
// `value` or `cache` changes; the query key only contains the
// missing ids so re-toggling a known id doesn't refetch.
- const idsToHydrate = useMemo(
- () => value.filter((id) => !cache.has(id)),
- [value, cache],
- )
+ const idsToHydrate = useMemo(() => value.filter((id) => !cache.has(id)), [value, cache])
useQuery({
queryKey: [queryKey, 'hydrate', idsToHydrate],
@@ -199,9 +196,7 @@ export function ResourceMultiAutocomplete<T extends AutocompleteOption>({
<ComboboxChips ref={anchorRef}>
<ComboboxValue>
{(selected: T[]) =>
- selected.map((opt) => (
- <ComboboxChip key={opt.id}>{getOptionLabel(opt)}</ComboboxChip>
- ))
+ selected.map((opt) => <ComboboxChip key={opt.id}>{getOptionLabel(opt)}</ComboboxChip>)
}
</ComboboxValue>
<ComboboxChipsInput
diff --git a/packages/admin/src/routes/_authenticated/$storeId/promotions/$promotionId.tsx b/packages/admin/src/routes/_authenticated/$storeId/promotions/$promotionId.tsx
index b39a889b4c..1d739ce4d1 100644
--- a/packages/admin/src/routes/_authenticated/$storeId/promotions/$promotionId.tsx
+++ b/packages/admin/src/routes/_authenticated/$storeId/promotions/$promotionId.tsx
@@ -3,8 +3,8 @@ import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { DownloadIcon, PlusIcon, TrashIcon } from 'lucide-react'
import { useEffect, useState } from 'react'
import { Controller, useFieldArray, useForm } from 'react-hook-form'
-import { Can } from '@/components/spree/can'
import { formatCalculatorSummary } from '@/components/spree/calculator-summary'
+import { Can } from '@/components/spree/can'
import { useConfirm } from '@/components/spree/confirm-dialog'
import { PageHeader } from '@/components/spree/page-header'
import { PreferencesForm } from '@/components/spree/preferences-form'
@@ -323,7 +323,6 @@ function PromotionBasicsCard({ form, promotion }: PromotionBasicsCardProps) {
)}
/>
</Field>
-
</FieldGroup>
</CardContent>
</Card>
@@ -491,7 +490,10 @@ function RuleSummary({ draft }: { draft: PromotionRuleFormDraft }) {
* when the list is missing or empty so the caller can fall back to a
* count-based summary built from `*_ids`.
*/
-function nameList<T>(items: T[] | undefined, getLabel: (item: T) => string = defaultLabel): string | null {
+function nameList<T>(
+ items: T[] | undefined,
+ getLabel: (item: T) => string = defaultLabel,
+): string | null {
if (!items?.length) return null
const labels = items.map(getLabel).filter(Boolean)
if (labels.length === 0) return null
@@ -500,7 +502,12 @@ function nameList<T>(items: T[] | undefined, getLabel: (item: T) => string = def
}
function defaultLabel(o: unknown): string {
- if (o && typeof o === 'object' && 'name' in o && typeof (o as { name: unknown }).name === 'string') {
+ if (
+ o &&
+ typeof o === 'object' &&
+ 'name' in o &&
+ typeof (o as { name: unknown }).name === 'string'
+ ) {
return (o as { name: string }).name
}
return ''
@@ -837,11 +844,7 @@ function DefaultActionEditor({ draft, onSave, onClose }: PromotionActionEditorCo
saveDisabled={!hasPreferences}
>
{hasPreferences ? (
- <PreferencesForm
- schema={draft.preference_schema}
- values={values}
- onChange={setValues}
- />
+ <PreferencesForm schema={draft.preference_schema} values={values} onChange={setValues} />
) : (
<p className="text-sm text-muted-foreground">This action has no configurable options.</p>
)}
diff --git a/packages/admin/src/routes/_authenticated/$storeId/promotions/new.tsx b/packages/admin/src/routes/_authenticated/$storeId/promotions/new.tsx
index a2c708cb05..5d9daae392 100644
--- a/packages/admin/src/routes/_authenticated/$storeId/promotions/new.tsx
+++ b/packages/admin/src/routes/_authenticated/$storeId/promotions/new.tsx
@@ -381,7 +381,6 @@ function NewPromotionPage() {
)}
/>
</Field>
-
</FieldGroup>
</CardContent>
</Card>
diff --git a/packages/admin/src/tables/payment-methods.tsx b/packages/admin/src/tables/payment-methods.tsx
index c98ca0eec4..0cd09e7289 100644
--- a/packages/admin/src/tables/payment-methods.tsx
+++ b/packages/admin/src/tables/payment-methods.tsx
@@ -61,7 +61,9 @@ defineTable<PaymentMethod>('payment-methods', {
filterable: true,
default: true,
filterType: 'boolean',
- render: (pm) => <ActiveBadge active={pm.active} activeLabel="Active" inactiveLabel="Disabled" />,
+ render: (pm) => (
+ <ActiveBadge active={pm.active} activeLabel="Active" inactiveLabel="Disabled" />
+ ),
},
],
})