diff --git a/src/types/pcm-variations.ts b/src/types/pcm-variations.ts index a7a3e8a9a..c1a1fe8d4 100644 --- a/src/types/pcm-variations.ts +++ b/src/types/pcm-variations.ts @@ -6,262 +6,290 @@ import { Identifiable, CrudQueryableResource, - RelationshipToMany, Resource, - ResourceList, ResourcePage, + ResourceList, + ResourcePage } from './core' - - /** - * Product Variations Base Interface - */ - export interface PCMVariationBase { - attributes: { - name: string - sort_order?: number | null - } +/** + * Product Variations Base Interface + */ +export interface PCMVariationBase { + attributes: { + name: string + sort_order?: number } +} - export interface PCMVariation extends Identifiable, PCMVariationBase { - type: 'product-variation' - meta?: { - options?: PCMVariationMetaOption[] - owner: 'organization' | 'store' - } +export interface PCMVariation extends Identifiable, PCMVariationBase { + type: 'product-variation' + meta?: { + options?: PCMVariationMetaOption[] + owner: 'organization' | 'store' } +} - /** - * The Product Variation Option object - * A variation option represents an option for selection for a single product-variation. - */ - export interface VariationsOption { - attributes: { - name: string - description: string - sort_order?: number | null - } +export interface UpdateVariationBody extends PCMVariationBase, Identifiable { + attributes: PCMVariationBase['attributes'] & { + sort_order?: number | null } +} - export type PCMVariationMetaOption = Identifiable & VariationsOption['attributes'] +/** + * Product variation option base interface + */ +export interface PCMVariationOptionBase { + type: 'product-variation-option' + attributes: { + name: string + description: string + sort_order?: number + } +} - export interface VariationsOptionResponse extends Identifiable { - type: 'product-variation-option' - attributes : { - name: string - description: string - } - relationships: { - modifiers: { - data: VariationsModifierTypeObj[] - } - } +export interface PCMVariationOption + extends Identifiable, + PCMVariationOptionBase { + meta: { + owner?: 'organization' | 'store' + modifiers?: VariationsModifierTypeObj[] } +} - export interface UpdateVariation extends PCMVariationBase, Identifiable {} +export interface UpdateVariationOptionBody + extends PCMVariationOptionBase, + Identifiable { + type: 'product-variation-option' + attributes: PCMVariationOptionBase['attributes'] & { + sort_order?: number | null + } +} - export interface UpdateVariationOption extends VariationsOption, Identifiable {} +/** + * Interface for options that are in a PCM Variation's meta.options field + */ +export type PCMVariationMetaOption = Identifiable & + PCMVariationOptionBase['attributes'] - /** - * Modifiers object - * Modifiers help augmenting properties of a variation of a product, price, etc., by creating an array of child products or prices. - */ - export interface VariationsModifier { - attributes: { - type: VariationsModifierType - value?: string - seek?: string - set?: string - reference_name?: string - } +/** + * Modifiers object + * Modifiers help augmenting properties of a variation of a product, price, etc., by creating an array of child products or prices. + */ +export interface VariationsModifier { + attributes: { + type: VariationsModifierType + value?: string + seek?: string + set?: string + reference_name?: string } +} - export interface VariationsModifierResponse extends Identifiable, VariationsModifier { - type: 'product-variation-modifier' - } +export interface VariationsModifierResponse + extends Identifiable, + VariationsModifier { + type: 'product-variation-modifier' +} - export type VariationsModifierTypeObj = - | { name_equals: string } - | { name_append: string } - | { name_prepend: string } - | { description_equals: string } - | { description_append: string } - | { description_prepend: string } - | { commoditytype: string } - | { slug_equals: string } - | { slug_append: string } - | { slug_prepend: string } - | { slug_builder: VariationsBuilderModifier } - | { sku_equals: string } - | { sku_append: string } - | { sku_prepend: string } - | { sku_builder: VariationsBuilderModifier } - | { status: string } +export type VariationsModifierTypeObj = + | { name_equals: string } + | { name_append: string } + | { name_prepend: string } + | { description_equals: string } + | { description_append: string } + | { description_prepend: string } + | { commoditytype: string } + | { slug_equals: string } + | { slug_append: string } + | { slug_prepend: string } + | { slug_builder: VariationsBuilderModifier } + | { sku_equals: string } + | { sku_append: string } + | { sku_prepend: string } + | { sku_builder: VariationsBuilderModifier } + | { status: string } - export type VariationsModifierType = - | 'name_equals' - | 'name_append' - | 'name_prepend' - | 'description_equals' - | 'description_append' - | 'description_prepend' - | 'commodity_type' - | 'slug_equals' - | 'slug_append' - | 'slug_prepend' - | 'slug_builder' - | 'sku_equals' - | 'sku_append' - | 'sku_prepend' - | 'sku_builder' - | 'status' - | 'price' +export type VariationsModifierType = + | 'name_equals' + | 'name_append' + | 'name_prepend' + | 'description_equals' + | 'description_append' + | 'description_prepend' + | 'commodity_type' + | 'slug_equals' + | 'slug_append' + | 'slug_prepend' + | 'slug_builder' + | 'sku_equals' + | 'sku_append' + | 'sku_prepend' + | 'sku_builder' + | 'status' + | 'price' - export interface VariationsBuilderModifier { - seek: string - set: string - } +export interface VariationsBuilderModifier { + seek: string + set: string +} - /** - * Variations Endpoints - * Get DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/get-a-product-variation.html - * Get All DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/create-a-product-variation.html - * Delete DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/delete-a-product-variation.html - */ - export interface PCMVariationsEndpoint - extends CrudQueryableResource< - PCMVariation, - PCMVariationBase, - VariationsOptionResponse, - never, - never, - never - > { - endpoint: 'pcm/variations' +/** + * Variations Endpoints + * Get DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/get-a-product-variation.html + * Get All DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/create-a-product-variation.html + * Delete DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/delete-a-product-variation.html + */ +export interface PCMVariationsEndpoint + extends CrudQueryableResource< + PCMVariation, + PCMVariationBase, + PCMVariationOption, + never, + never, + never + > { + endpoint: 'pcm/variations' - Limit(value: number): PCMVariationsEndpoint + Limit(value: number): PCMVariationsEndpoint - Offset(value: number): PCMVariationsEndpoint + Offset(value: number): PCMVariationsEndpoint - /** - * Create a product variation - * @param body - The variation object. - * @constructor - */ - CreateVariation(body: PCMVariationBase): Promise> + /** + * Create a product variation + * @param body - The base variation object. + * @constructor + */ + CreateVariation(body: PCMVariationBase): Promise> - /** - * Update a product variation - * @param id - ID of the variation. - * @param body - The variation object. - * @param token - a token to access specific data. - * @constructor - */ - UpdateVariation( - id: string, - body: UpdateVariation, - token?: string - ): Promise> + /** + * Update a product variation + * @param id - ID of the variation. + * @param body - The variation object. + * @param token - a token to access specific data. + * @constructor + */ + UpdateVariation( + id: string, + body: UpdateVariationBody, + token?: string + ): Promise> - /** - * Get a product variation option - * Description: Use this endpoint to retrieve a single variation option. - * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/options/get-a-product-variation-option.html - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @constructor - */ - VariationsOption( - variationId: string, - optionId: string - ): Promise> + /** + * Get a product variation option + * Description: Use this endpoint to retrieve a single variation option. + * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/product-variations/options/get-a-product-variation-option.html + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @constructor + */ + VariationsOption( + variationId: string, + optionId: string + ): Promise> - /** - * Get all product variation options - * @param variationId - ID of the variation. - * @constructor - */ - VariationsOptions(variationId: string): Promise> + /** + * Get all product variation options + * @param variationId - ID of the variation. + * @constructor + */ + VariationsOptions( + variationId: string + ): Promise> - /** - * Create a product variation option - * @param variationId - ID of the variation. - * @param body - The option object. - * @constructor - */ - CreateVariationsOption(variationId: string, body: VariationsOption): Promise> + /** + * Create a product variation option + * @param variationId - ID of the variation. + * @param body - The option object. + * @constructor + */ + CreateVariationsOption( + variationId: string, + body: PCMVariationOptionBase + ): Promise> - /** - * Update product variation option - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @param body - The option object. - * @constructor - */ - UpdateVariationsOption(variationId: string, optionId: string, body: UpdateVariationOption): Promise> + /** + * Update product variation option + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @param body - The option object. + * @constructor + */ + UpdateVariationsOption( + variationId: string, + optionId: string, + body: UpdateVariationOptionBody + ): Promise> - /** - * Delete product variation option - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @constructor - */ - DeleteVariationsOption(variationId: string, optionId: string): Promise<{}> + /** + * Delete product variation option + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @constructor + */ + DeleteVariationsOption(variationId: string, optionId: string): Promise<{}> - /** - * Get a product modifier - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @param modifierId - ID of the modifier. - * @constructor - */ - VariationsModifier( - variationId: string, - optionId: string, - modifierId: string - ): Promise> + /** + * Get a product modifier + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @param modifierId - ID of the modifier. + * @constructor + */ + VariationsModifier( + variationId: string, + optionId: string, + modifierId: string + ): Promise> - /** - * Get all product modifiers - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @constructor - */ - VariationsModifiers(variationId: string, optionId: string): Promise> + /** + * Get all product modifiers + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @constructor + */ + VariationsModifiers( + variationId: string, + optionId: string + ): Promise> - /** - * Create a new product modifier - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @param body - The modifier object. - * @constructor - */ - CreateVariationsModifier( - variationId: string, - optionId: string, - body: VariationsModifier - ): Promise> + /** + * Create a new product modifier + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @param body - The modifier object. + * @constructor + */ + CreateVariationsModifier( + variationId: string, + optionId: string, + body: VariationsModifier + ): Promise> - /** - * Update a product modifier - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @param modifierId - ID of the modifier. - * @param body - The modifier object. - * @constructor - */ - UpdateVariationsModifier( - variationId: string, - optionId: string, - modifierId: string, - body: VariationsModifier - ): Promise> + /** + * Update a product modifier + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @param modifierId - ID of the modifier. + * @param body - The modifier object. + * @constructor + */ + UpdateVariationsModifier( + variationId: string, + optionId: string, + modifierId: string, + body: VariationsModifier + ): Promise> - /** - * Delete a product modifier - * @param variationId - ID of the variation. - * @param optionId - ID of the option. - * @param modifierId - ID of the modifier. - * @constructor - */ - DeleteVariationsModifier(variationId: string, optionId: string, modifierId: string): Promise<{}> - } + /** + * Delete a product modifier + * @param variationId - ID of the variation. + * @param optionId - ID of the option. + * @param modifierId - ID of the modifier. + * @constructor + */ + DeleteVariationsModifier( + variationId: string, + optionId: string, + modifierId: string + ): Promise<{}> +}