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.

Added Admin SDK support for Categories

Damian Legawiec77bd9f59ac30
diff --git a/packages/admin-sdk/src/admin-client.ts b/packages/admin-sdk/src/admin-client.ts
index ef89a13761..4d88c748b4 100644
--- a/packages/admin-sdk/src/admin-client.ts
+++ b/packages/admin-sdk/src/admin-client.ts
@@ -74,6 +74,10 @@ import type {
AllowedOriginUpdateParams,
ApiKeyCreateParams,
ApiKeyUpdateParams,
+ CategoryCreateParams,
+ CategoryProductRepositionParams,
+ CategoryRepositionParams,
+ CategoryUpdateParams,
ChannelCreateParams,
ChannelUpdateParams,
CustomerAddressParams,
@@ -1728,7 +1732,73 @@ export class AdminClient {
params: params ? transformListParams(params) : undefined,
}),
+ get: (
+ id: string,
+ params?: { expand?: string[] },
+ options?: RequestOptions,
+ ): Promise<Category> =>
+ this.request<Category>('GET', `/categories/${id}`, {
+ ...options,
+ params: getParams(params),
+ }),
+
+ create: (params: CategoryCreateParams, options?: RequestOptions): Promise<Category> =>
+ this.request<Category>('POST', '/categories', { ...options, body: params }),
+
+ update: (
+ id: string,
+ params: CategoryUpdateParams,
+ options?: RequestOptions,
+ ): Promise<Category> =>
+ this.request<Category>('PATCH', `/categories/${id}`, { ...options, body: params }),
+
+ delete: (id: string, options?: RequestOptions): Promise<void> =>
+ this.request<void>('DELETE', `/categories/${id}`, options),
+
+ /** Move a category to a new parent and/or index within the tree. */
+ reposition: (
+ id: string,
+ params: CategoryRepositionParams,
+ options?: RequestOptions,
+ ): Promise<Category> =>
+ this.request<Category>('PATCH', `/categories/${id}/reposition`, { ...options, body: params }),
+
+ /** Manual product membership + ordering within a category. */
+ products: {
+ list: (
+ categoryId: string,
+ params?: ListParams & Record<string, unknown>,
+ options?: RequestOptions,
+ ): Promise<PaginatedResponse<Product>> =>
+ this.request<PaginatedResponse<Product>>('GET', `/categories/${categoryId}/products`, {
+ ...options,
+ params: params ? transformListParams(params) : undefined,
+ }),
+
+ add: (categoryId: string, productId: string, options?: RequestOptions): Promise<Product> =>
+ this.request<Product>('POST', `/categories/${categoryId}/products`, {
+ ...options,
+ body: { product_id: productId },
+ }),
+
+ remove: (categoryId: string, productId: string, options?: RequestOptions): Promise<void> =>
+ this.request<void>('DELETE', `/categories/${categoryId}/products/${productId}`, options),
+
+ reposition: (
+ categoryId: string,
+ productId: string,
+ params: CategoryProductRepositionParams,
+ options?: RequestOptions,
+ ): Promise<void> =>
+ this.request<void>('PATCH', `/categories/${categoryId}/products/${productId}/reposition`, {
+ ...options,
+ body: params,
+ }),
+ },
+
customFields: this.parentScopedCustomFields(CUSTOM_FIELD_OWNER_PATHS['Spree::Category']),
+
+ translations: this.parentScopedTranslations('/categories'),
}
// ============================================
diff --git a/packages/admin-sdk/src/params.ts b/packages/admin-sdk/src/params.ts
index 89c686240f..3068285565 100644
--- a/packages/admin-sdk/src/params.ts
+++ b/packages/admin-sdk/src/params.ts
@@ -371,28 +371,46 @@ export interface ProductVariantInput {
export interface CategoryCreateParams {
name: string
+ /** Prefixed ID of the parent category. Omit for a top-level category. */
parent_id?: string
- position?: number
description?: string
permalink?: string
meta_title?: string
meta_description?: string
meta_keywords?: string
hide_from_nav?: boolean
- sort_order?: string
+ /** ActiveStorage signed_id of a directly-uploaded landscape image. */
+ image?: string
+ /** ActiveStorage signed_id of a directly-uploaded square image. */
+ square_image?: string
}
export interface CategoryUpdateParams {
name?: string
+ /** Prefixed ID of the parent category (moves the category in the tree). */
parent_id?: string
- position?: number
description?: string
permalink?: string
meta_title?: string
meta_description?: string
meta_keywords?: string
hide_from_nav?: boolean
- sort_order?: string
+ /** ActiveStorage signed_id of a directly-uploaded landscape image. */
+ image?: string
+ /** ActiveStorage signed_id of a directly-uploaded square image. */
+ square_image?: string
+}
+
+export interface CategoryRepositionParams {
+ /** Prefixed ID of the new parent. Omit/null to move to the top level. */
+ new_parent_id?: string | null
+ /** 0-based index among the new parent's children. */
+ new_position: number
+}
+
+export interface CategoryProductRepositionParams {
+ /** 0-based index among the category's products. */
+ new_position: number
}
export interface VariantOptionPair {