Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/endpoints/catalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,20 @@ class Rules extends CRUDExtend {
token
)
}

Validate(body, token = null) {
const { limit, offset } = this

return this.request.send(
buildURL(`catalogs/${this.endpoint}/validate`, {
limit,
offset
}),
'POST',
body,
token
)
}
}

class CatalogsEndpoint extends CRUDExtend {
Expand Down
9 changes: 7 additions & 2 deletions src/endpoints/pcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ class PCMEndpoint extends CRUDExtend {
return this.request.send(`${this.endpoint}/detach_nodes`, 'POST', body)
}

ExportProducts(filter, useTemplateSlugs) {
ExportProducts(filter, useTemplateSlugs, columns) {
const body = columns
? { data: { type: 'product', attributes: { columns } } }
: undefined

return this.request.send(
buildURL(`${this.endpoint}/export`, {
filter,
useTemplateSlugs
}),
'POST'
'POST',
body
)
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/types/catalogs-products.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ export interface CatalogsProductVariation
options: Omit<Option, 'modifiers'>[]
}

export interface PriceTier {
minimum_quantity: number
amount: {
[currency: string]: {
amount: number
includes_tax: boolean
}
}
}

export interface AvailablePrice {
pricebook_id: string
shopper_attributes?: { [key: string]: string }
sale_id?: string
sale_expires?: string
price?: {
[currency: string]: {
amount: number
includes_tax: boolean
}
}
tiers?: { [tier: string]: PriceTier }
}

export interface AlternativePrice extends AvailablePrice {
name: string
display_price?: {
without_tax?: FormattedPrice
with_tax?: FormattedPrice
}
original_price?: {
[currency: string]: {
amount: number
includes_tax: boolean
}
}
}

export interface ProductResponse extends Identifiable {
type: 'product'
attributes: {
Expand Down Expand Up @@ -38,6 +76,9 @@ export interface ProductResponse extends Identifiable {
weight: string
manufacturer_part_num?: string
extensions?: Extensions
available_prices?: AvailablePrice[]
alternative_prices?: { [name: string]: AlternativePrice }
available_pricebook_ids?: string[]
}
meta: {
catalog_id?: string
Expand Down Expand Up @@ -76,6 +117,7 @@ export interface ProductResponse extends Identifiable {
}
}
pricebook_id: string
alternative_prices?: { [name: string]: AlternativePrice }
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/types/catalogs-releases.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export interface ReleaseBodyBase {
export_full_delta?: boolean
}

export type ReleaseIndexingStatus = 'succeeded' | 'failed'

export interface ReleaseIndexingCompleteData {
data: {
status: ReleaseIndexingStatus
}
}

export interface CatalogsReleasesEndpoint {
endpoint: 'releases'

Expand Down
65 changes: 61 additions & 4 deletions src/types/catalogs-rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
*/
import {
Identifiable,
CrudQueryableResource
CrudQueryableResource,
Resource,
ResourcePage
} from './core'

/**
Expand All @@ -21,6 +23,7 @@ export interface RuleBase {
customer_ids?: string[]
channels?: string[]
tags?: string[]
pricebook_ids?: string[]
schedules?: {valid_from: string, valid_to: string}[]
}
}
Expand All @@ -33,8 +36,19 @@ export interface Rule extends Identifiable, RuleBase {

// Do Not have any relationships yet //TODO

export interface RuleFilterAttributes {
id?: string
catalog_id?: string
account_ids?: string
customer_ids?: string
channels?: string
tags?: string
pricebook_ids?: string
}

export interface RuleFilter {
// TODO
eq?: RuleFilterAttributes
in?: Pick<RuleFilterAttributes, 'pricebook_ids'>
}

type RuleSort = // TODO
Expand All @@ -47,10 +61,53 @@ export interface RuleUpdateBody extends RuleBase {
id: string
}

export type RuleValidationMatchType =
| 'filter'
| 'similarity'
| 'conflict'
| 'resolve_for_shopper'

export interface RuleValidationCriteria {
channels?: string[]
tags?: string[]
account_ids?: string[]
account_tag_ids?: string[]
customer_ids?: string[]
}

export interface CatalogRuleValidatorRequest {
data: {
type: 'catalog_rule_validator'
match_type: RuleValidationMatchType
catalog_id?: string
pricebook_ids?: string[]
schedules?: { valid_from: string; valid_to: string }[]
attributes?: RuleValidationCriteria
}
}

export interface RuleMeta {
similarity_score?: number
active?: boolean
resolved_for_shopper?: boolean
release_id?: string
}

export interface ValidatedRule extends Rule {
meta?: RuleMeta
}

export type ValidateRulesResponse = ResourcePage<ValidatedRule>

export interface CatalogsRulesEndpoint
extends CrudQueryableResource<Rule, RuleBase, RuleUpdateBody, RuleFilter, RuleSort, RuleInclude> {
endpoint: 'rules'
id: string
}


/**
* Validate Catalog Rules
* @param body - validation request describing the match_type and rule criteria.
* @param token - optional customer token.
*/
Validate(body: CatalogRuleValidatorRequest, token?: string): Promise<ValidateRulesResponse>
}
18 changes: 17 additions & 1 deletion src/types/pcm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface PcmProductBase extends PcmProductRelationships {
components?: ProductComponents
custom_inputs?: CustomInputs
tags?: string[]
admin_attributes?: { [key: string]: string }
shopper_attributes?: { [key: string]: string }
}
}

Expand Down Expand Up @@ -86,6 +88,8 @@ export interface ProductComponentOption {
id: string
quantity: number
type: string
min?: number | null
max?: number | null
sort_order?: number | null
default?: boolean
meta: {
Expand Down Expand Up @@ -255,7 +259,19 @@ export interface PcmProductsEndpoint
/**
* Export products
* @param filter - products filters
* @param useTemplateSlugs - use template slugs instead of template IDs
* @param columns - select which columns to include in the exported CSV. Supports
* individual keys (e.g. `admin_attributes.cost_of_goods`) and wildcards
* (e.g. `admin_attributes.*`).
* @constructor
*/
ExportProducts(filter?: PcmProductFilter, useTemplateSlugs?: boolean): Promise<Resource<PcmJob>>
ExportProducts(
filter?: PcmProductFilter,
useTemplateSlugs?: boolean,
columns?: PcmProductExportColumns
): Promise<Resource<PcmJob>>
}

export interface PcmProductExportColumns {
include: string[]
}
Loading