Skip to content

Commit 9a314ae

Browse files
feat!: Custom relationship type updates (#29)
BREAKING CHANGE: Updated to pcm custom relationship type
1 parent 10424c5 commit 9a314ae

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

src/types/core.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,11 @@ export interface CrudQueryableResource<R, C, U, F, S, I>
115115

116116
Link(url: string): Promise<Resource<R>>
117117
}
118+
119+
export interface SimpleResourcePageResponse<T> extends ResourceList<T> {
120+
meta: {
121+
results: {
122+
total: number
123+
}
124+
}
125+
}

src/types/pcm-custom-relationship.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Product Custom Relationships
33
*/
4-
import { Identifiable, Resource, ResourceList } from './core'
4+
import { Identifiable, SimpleResourcePageResponse } from './core'
55
import {
66
CustomRelationship,
77
CustomRelationshipsListResponse
@@ -17,22 +17,14 @@ export interface CustomRelationshipEntry {
1717
slug: string
1818
}
1919

20-
export interface PcmRelatedProductResponse<T> extends ResourceList<T> {
21-
meta: {
22-
results: {
23-
total: number
24-
}
25-
}
26-
}
27-
2820
export interface NonAssociatedProductEntry extends Identifiable {
2921
details: string
3022
}
3123

3224
export interface ProductAssociationResponse {
3325
meta: {
34-
associated_products: string[]
35-
products_not_associated: NonAssociatedProductEntry[]
26+
associated_products?: string[]
27+
products_not_associated?: NonAssociatedProductEntry[]
3628
owner: 'organization' | 'store'
3729
timestamps: {
3830
created_at: string
@@ -61,8 +53,8 @@ export interface PcmCustomRelationshipEndpoint {
6153
*/
6254
AttachCustomRelationship(
6355
productId: string,
64-
body: CustomRelationshipEntry
65-
): Promise<Resource<CustomRelationship>>
56+
body: CustomRelationshipEntry[]
57+
): Promise<SimpleResourcePageResponse<CustomRelationship>>
6658

6759
/**
6860
* Detach one or multiple custom relationships from a product
@@ -107,7 +99,7 @@ export interface PcmCustomRelationshipEndpoint {
10799
GetProductsForCustomRelationship(
108100
productId: string,
109101
customRelationshipSlug: string
110-
): Promise<PcmRelatedProductResponse<PcmProduct>>
102+
): Promise<SimpleResourcePageResponse<PcmProduct>>
111103

112104
/**
113105
* Get all IDs of a product's related products under a custom relationship
@@ -118,5 +110,5 @@ export interface PcmCustomRelationshipEndpoint {
118110
GetProductIdsForCustomRelationship(
119111
productId: string,
120112
customRelationshipSlug: string
121-
): Promise<PcmRelatedProductResponse<PcmProductEntry>>
113+
): Promise<SimpleResourcePageResponse<PcmProductEntry>>
122114
}

src/types/pcm.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ type productType = 'standard' | 'parent' | 'child'| 'bundle'
9999

100100
export interface PcmProduct extends Identifiable, PcmProductBase {
101101
meta: {
102+
created_at: string
103+
updated_at: string
102104
variation_matrix: { [key: string]: string } | {}
103105
owner?: 'organization' | 'store'
104106
product_types?: productType[]
107+
custom_relationships?: string[]
105108
}
106109
}
107110

@@ -120,6 +123,13 @@ export interface PcmProductRelationships {
120123
id: string
121124
}
122125
}
126+
custom_relationships?: {
127+
data?: Array<unknown> | null
128+
links?: {
129+
[key: string]: string
130+
self: string
131+
}
132+
}
123133
}
124134
}
125135

0 commit comments

Comments
 (0)