Skip to content

Commit

Permalink
feat: 完善文档和工具类的相关单测
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjue666 committed Nov 11, 2024
1 parent ffadf28 commit ecf3be6
Show file tree
Hide file tree
Showing 15 changed files with 2,131 additions and 685 deletions.
932 changes: 892 additions & 40 deletions README.md

Large diffs are not rendered by default.

1,276 changes: 892 additions & 384 deletions README_zh.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spapi-listing-builder",
"type": "module",
"version": "0.1.7",
"version": "0.1.8",
"packageManager": "[email protected]",
"description": "_description_",
"author": "wangjue666 <[email protected]>",
Expand Down
13 changes: 13 additions & 0 deletions src/SchemaCheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ export class SchemaCheck {
}
})
}

convertRequiredSchema2FormItems() {
return this.getRequiredFields().map((field) => {
const schema = this.jsonSchema.getSchema({ pointer: field })
try {
return new ConvertSchemaItem2FormItem(field, schema, this.required).main()
}
catch (e) {
console.error(e)
return undefined
}
})
}
}
73 changes: 38 additions & 35 deletions src/feed/product/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import { ListingProduct } from '@/listing/product'
import type { ProductData } from '@/help/state'
import { FeedHeader } from '../FeedHeader'

export class FeedProduct {
sellerId: string
list: ProductData[]
marketplace_id: string
constructor(sellerId: string, marketplace_id: string, list: ProductData[]) {
this.sellerId = sellerId
this.marketplace_id = marketplace_id
this.list = list
}

main() {
return {
header: new FeedHeader(this.sellerId).main(),
messages: this.genMessage(),
}
}

genMessage() {
return this.list.map((item, idx) => {
return {
messageId: idx + 1,
sku: item.sku,
operationType: 'UPDATE',
...new ListingProduct({
marketplace_id: this.marketplace_id,
data: item,
}).main(),
}
})
}
}
import { ListingProduct } from '@/listing/product'
import type { ProductData, RenderOtherAttributesFn } from '@/help/state'
import { FeedHeader } from '../FeedHeader'

export class FeedProduct {
sellerId: string
list: ProductData[]
marketplace_id: string
renderOtherAttributesFn?: RenderOtherAttributesFn
constructor(sellerId: string, marketplace_id: string, list: ProductData[], renderOtherAttributesFn?: RenderOtherAttributesFn) {
this.sellerId = sellerId
this.marketplace_id = marketplace_id
this.list = list
this.renderOtherAttributesFn = renderOtherAttributesFn
}

main() {
return {
header: new FeedHeader(this.sellerId).main(),
messages: this.genMessage(),
}
}

genMessage() {
return this.list.map((item, idx) => {
return {
messageId: idx + 1,
sku: item.sku,
operationType: 'UPDATE',
...new ListingProduct({
marketplace_id: this.marketplace_id,
data: item,
renderOtherAttributesFn: this.renderOtherAttributesFn,
}).main(),
}
})
}
}
128 changes: 66 additions & 62 deletions src/help/state.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
export const imageTypeJsonMap = {
Main: 'main_product_image_locator',
Swatch: 'swatch_product_image_locator',
PT1: 'other_product_image_locator_1',
PT2: 'other_product_image_locator_2',
PT3: 'other_product_image_locator_3',
PT4: 'other_product_image_locator_4',
PT5: 'other_product_image_locator_5',
PT6: 'other_product_image_locator_6',
PT7: 'other_product_image_locator_7',
PT8: 'other_product_image_locator_8',
MainOfferImage: 'main_offer_image_locator',
OfferImage1: 'other_offer_image_locator_1',
OfferImage2: 'other_offer_image_locator_2',
OfferImage3: 'other_offer_image_locator_3',
OfferImage4: 'other_offer_image_locator_4',
OfferImage5: 'other_offer_image_locator_5',
EEGL: 'image_locator_eegl',
}

export function getImageType(key: string): string | undefined {
return (imageTypeJsonMap as any)[key]
}

export type Recordable<T = any> = Record<string, T>

export type ListingType = 'FOLLOW_ASIN' | 'LISTING'

export interface ListingImgData {
type: keyof typeof imageTypeJsonMap
url: string
}

export type ProductData = Partial<{
sku: string
product_type: string
title: string
product_description: string
bullet_points: string[]
brand_name: string
product_identifier_type: 'UPC' | 'EAN' | 'ISBN' | 'GTIN' | ''
product_identifier_id: string
condition: string
manufacturer: string
weight: number
height: number
length: number
width: number
recommendedBrowseNodes: string[]
batteries_required: number // 是否需要电池
manufactuer_id: string
search_terms: string
quantity: number
deal_time: number
sell_price: number
list_price: number
country_of_origin: string
item_type_keyword: string
parent_sku: string
imgs: ListingImgData[]
[key: string]: any
}>
import type { renderListingArrValue as renderListingArrValueHelp } from './index'

export const imageTypeJsonMap = {
Main: 'main_product_image_locator',
Swatch: 'swatch_product_image_locator',
PT1: 'other_product_image_locator_1',
PT2: 'other_product_image_locator_2',
PT3: 'other_product_image_locator_3',
PT4: 'other_product_image_locator_4',
PT5: 'other_product_image_locator_5',
PT6: 'other_product_image_locator_6',
PT7: 'other_product_image_locator_7',
PT8: 'other_product_image_locator_8',
MainOfferImage: 'main_offer_image_locator',
OfferImage1: 'other_offer_image_locator_1',
OfferImage2: 'other_offer_image_locator_2',
OfferImage3: 'other_offer_image_locator_3',
OfferImage4: 'other_offer_image_locator_4',
OfferImage5: 'other_offer_image_locator_5',
EEGL: 'image_locator_eegl',
}

export function getImageType(key: string): string | undefined {
return (imageTypeJsonMap as any)[key]
}

export type Recordable<T = any> = Record<string, T>

export type ListingType = 'FOLLOW_ASIN' | 'LISTING'

export interface ListingImgData {
type: keyof typeof imageTypeJsonMap
url: string
}

export type ProductData = Partial<{
sku: string
product_type: string
title: string
product_description: string
bullet_points: string[]
brand_name: string
product_identifier_type: 'UPC' | 'EAN' | 'ISBN' | 'GTIN' | ''
product_identifier_id: string
condition: string
manufacturer: string
weight: number
height: number
length: number
width: number
recommendedBrowseNodes: string[]
batteries_required: number // 是否需要电池
manufactuer_id: string
search_terms: string
quantity: number
deal_time: number
sell_price: number
list_price: number
country_of_origin: string
item_type_keyword: string
parent_sku: string
imgs: ListingImgData[]
[key: string]: any
}>

export type RenderOtherAttributesFn = (params: { attributes: Recordable, data: ProductData, renderListingArrValue: typeof renderListingArrValueHelp }) => Recordable
29 changes: 15 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export * from './feed/img'
export * from './feed/price'
export * from './feed/product'
export * from './feed/quantity'
export * from './feed/relation'

export * from './help/state'
export * from './listing/img'
export * from './listing/price'
export * from './listing/product'
export * from './listing/quantity'
export * from './listing/relation'

export * from './SchemaCheck/index'
export * from './feed/img'
export * from './feed/price'
export * from './feed/product'
export * from './feed/quantity'
export * from './feed/relation'

export * from './help/index'
export * from './help/state'
export * from './listing/img'
export * from './listing/price'
export * from './listing/product'
export * from './listing/quantity'
export * from './listing/relation'

export * from './SchemaCheck/index'
Loading

0 comments on commit ecf3be6

Please sign in to comment.