Skip to content

Commit

Permalink
feat!: Custom relationship type updates (#29)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Updated to pcm custom relationship type
  • Loading branch information
GeorgeBotzakis authored Oct 3, 2024
1 parent 10424c5 commit 9a314ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ export interface CrudQueryableResource<R, C, U, F, S, I>

Link(url: string): Promise<Resource<R>>
}

export interface SimpleResourcePageResponse<T> extends ResourceList<T> {
meta: {
results: {
total: number
}
}
}
22 changes: 7 additions & 15 deletions src/types/pcm-custom-relationship.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Product Custom Relationships
*/
import { Identifiable, Resource, ResourceList } from './core'
import { Identifiable, SimpleResourcePageResponse } from './core'
import {
CustomRelationship,
CustomRelationshipsListResponse
Expand All @@ -17,22 +17,14 @@ export interface CustomRelationshipEntry {
slug: string
}

export interface PcmRelatedProductResponse<T> extends ResourceList<T> {
meta: {
results: {
total: number
}
}
}

export interface NonAssociatedProductEntry extends Identifiable {
details: string
}

export interface ProductAssociationResponse {
meta: {
associated_products: string[]
products_not_associated: NonAssociatedProductEntry[]
associated_products?: string[]
products_not_associated?: NonAssociatedProductEntry[]
owner: 'organization' | 'store'
timestamps: {
created_at: string
Expand Down Expand Up @@ -61,8 +53,8 @@ export interface PcmCustomRelationshipEndpoint {
*/
AttachCustomRelationship(
productId: string,
body: CustomRelationshipEntry
): Promise<Resource<CustomRelationship>>
body: CustomRelationshipEntry[]
): Promise<SimpleResourcePageResponse<CustomRelationship>>

/**
* Detach one or multiple custom relationships from a product
Expand Down Expand Up @@ -107,7 +99,7 @@ export interface PcmCustomRelationshipEndpoint {
GetProductsForCustomRelationship(
productId: string,
customRelationshipSlug: string
): Promise<PcmRelatedProductResponse<PcmProduct>>
): Promise<SimpleResourcePageResponse<PcmProduct>>

/**
* Get all IDs of a product's related products under a custom relationship
Expand All @@ -118,5 +110,5 @@ export interface PcmCustomRelationshipEndpoint {
GetProductIdsForCustomRelationship(
productId: string,
customRelationshipSlug: string
): Promise<PcmRelatedProductResponse<PcmProductEntry>>
): Promise<SimpleResourcePageResponse<PcmProductEntry>>
}
10 changes: 10 additions & 0 deletions src/types/pcm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ type productType = 'standard' | 'parent' | 'child'| 'bundle'

export interface PcmProduct extends Identifiable, PcmProductBase {
meta: {
created_at: string
updated_at: string
variation_matrix: { [key: string]: string } | {}
owner?: 'organization' | 'store'
product_types?: productType[]
custom_relationships?: string[]
}
}

Expand All @@ -120,6 +123,13 @@ export interface PcmProductRelationships {
id: string
}
}
custom_relationships?: {
data?: Array<unknown> | null
links?: {
[key: string]: string
self: string
}
}
}
}

Expand Down

0 comments on commit 9a314ae

Please sign in to comment.