UNPKG

spapi-listing-builder

Version:

It is a simple npm package for generating compliant Amazon SP-API listing JSON quickly and efficiently.

457 lines (441 loc) 12 kB
import Draft from 'json-schema-library'; interface FeedImgData { sku: string; imgs: { type: string; url: string; }[]; } declare class FeedImg { sellerId: string; list: FeedImgData[]; constructor(sellerId: string, list: FeedImgData[]); main(): { header: { sellerId: string; version: string; issueLocale: string; }; messages: { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { media_location: string; }[]; }[]; }[]; }; genMessage(): { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { media_location: string; }[]; }[]; }[]; genPatches(imgs: FeedImgData['imgs']): { op: string; path: string; value: { media_location: string; }[]; }[]; } interface FeedPriceData { country_code: string; sku: string; sell_price: number; shipping_price?: number; } declare class FeedPrice { sellerId: string; list: FeedPriceData[]; constructor(sellerId: string, list: FeedPriceData[]); main(): { header: { sellerId: string; version: string; issueLocale: string; }; messages: { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { audience: string; our_price: { schedule: { value_with_tax: number; }[]; }[]; }[]; }[]; }[]; }; genMessage(): { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { audience: string; our_price: { schedule: { value_with_tax: number; }[]; }[]; }[]; }[]; }[]; } declare function combineObjAttr(bool: boolean | number | undefined, obj: any, key: string, attr: any): any; declare function filterUndefinedKeys(obj: any): any; /** * @desc 返回格式为 [{value: params}] 的数组 */ declare function renderListingArrValue(value: any): any[] | undefined; declare const imageTypeJsonMap: { Main: string; Swatch: string; PT1: string; PT2: string; PT3: string; PT4: string; PT5: string; PT6: string; PT7: string; PT8: string; MainOfferImage: string; OfferImage1: string; OfferImage2: string; OfferImage3: string; OfferImage4: string; OfferImage5: string; EEGL: string; PS01: string; PS02: string; PS03: string; PS04: string; PS05: string; PS06: string; }; declare function getImageType(key: string): string | undefined; type Recordable<T = any> = Record<string, T>; type ListingType = 'FOLLOW_ASIN' | 'LISTING'; interface ListingImgData { type: keyof typeof imageTypeJsonMap; url: string; } 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; }>; type RenderOtherAttributesFn = (params: { attributes: Recordable; data: ProductData; renderListingArrValue: typeof renderListingArrValue; }) => Recordable; declare class FeedProduct { sellerId: string; list: ProductData[]; marketplace_id: string; renderOtherAttributesFn?: RenderOtherAttributesFn; constructor(sellerId: string, marketplace_id: string, list: ProductData[], renderOtherAttributesFn?: RenderOtherAttributesFn); main(type?: ListingType): { header: { sellerId: string; version: string; issueLocale: string; }; messages: { productType: string | undefined; requirements: string; attributes: any; messageId: number; sku: string | undefined; operationType: string; }[]; }; genMessage(type?: ListingType): { productType: string | undefined; requirements: string; attributes: any; messageId: number; sku: string | undefined; operationType: string; }[]; } /** * @param {string} sku - SKU of the product * @param {number} deal_time - 预处理时间 默认2天 * @param {number} quantity - 数量 */ interface FeedQuantityData { sku: string; quantity: number; deal_time: number; } declare class FeedQuantity { sellerId: string; list: FeedQuantityData[]; constructor(sellerId: string, list: FeedQuantityData[]); main(): { header: { sellerId: string; version: string; issueLocale: string; }; messages: { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { fulfillment_channel_code: string; quantity: number; lead_time_to_ship_max_days: number; }[]; }[]; }[]; }; genMessage(): { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { fulfillment_channel_code: string; quantity: number; lead_time_to_ship_max_days: number; }[]; }[]; }[]; } interface FeedRelationData { sku: string; parent_sku: string; } declare class FeedRelation { sellerId: string; list: FeedRelationData[]; constructor(sellerId: string, list: FeedRelationData[]); main(): { header: { sellerId: string; version: string; issueLocale: string; }; messages: { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { child_relationship_type: string; parent_sku: string; }[]; }[]; }[]; }; genMessage(): { messageId: number; sku: string; operationType: string; productType: string; patches: { op: string; path: string; value: { child_relationship_type: string; parent_sku: string; }[]; }[]; }[]; } declare class ListingImg { imgData: ListingImgData[]; constructor(imgData: ListingImgData[]); main(): { productType: string; patches: { op: string; path: string; value: { media_location: string; }[]; }[]; }; genPatches(): { op: string; path: string; value: { media_location: string; }[]; }[]; genValuesMap(): Recordable; genValue(value: string): { media_location: string; }[]; } interface ListingPriceData { sell_price: number; low_price?: number; max_price?: number; } declare class ListingPrice { priceData: ListingPriceData; constructor(priceData: ListingPriceData); main(): { productType: string; patches: { op: string; path: string; value: any[]; }[]; }; genPatche(): any; genValue(): any[] | undefined; } interface ListingProductConstructor { marketplace_id: string; data: ProductData; type?: ListingType; renderOtherAttributesFn?: (RenderOtherAttributesFn); } /** * @desc FOLLOW_ASIN - 跟卖ASIN * @desc LISTING - 刊登 */ declare class ListingProduct { data: ProductData; marketplace_id: string; type: ListingType; renderOtherAttributesFn?: RenderOtherAttributesFn; constructor({ marketplace_id, data, type, renderOtherAttributesFn }: ListingProductConstructor); main(): { productType: string | undefined; requirements: string; attributes: any; }; renderFollowAsin(): { productType: string | undefined; requirements: string; attributes: any; }; renderListing(): { productType: string | undefined; requirements: string; attributes: any; }; callRenderOtherAttributesFn(attributes: Recordable): Recordable<any>; } interface ListingQuantityData { quantity: number; deal_time?: number; fulfillment_channel_code?: string; } declare class ListingQuantity { quantityData: ListingQuantityData; constructor(quantityData: ListingQuantityData); main(): { productType: string; patches: { op: string; path: string; value: any[]; }[]; }; genPatche(): any; genValue(): any[] | undefined; } declare class ListingRelation { parent_sku: string; constructor(parent_sku: string); main(): { productType: string; patches: { op: string; path: string; value: { child_relationship_type: string; parent_sku: string; }[]; }[]; }; } declare class ConvertSchemaItem2FormItem { field: string; schemaItem: Recordable; required: string[]; constructor(field: string, schemaItem: any, required: string[]); main(): any; convert(key: string): any; predictComponentData(properties: Recordable): any; parserSchemaPropertiesKey(): string | string[]; } declare class SchemaCheck { jsonSchema: Draft.Draft2019; data: object; schema: Recordable; required: string[]; constructor(schema: Recordable, data: object); validate(): Draft.JsonError[]; getRequiredFields(): string[]; getRequiredSchema(): (Draft.JsonSchema | Draft.JsonError | undefined)[]; getProperties(key: string): any; getAllPropertiesKeys(): string[]; convert2FormItems(): any[]; convertRequiredSchema2FormItems(): any[]; } export { ConvertSchemaItem2FormItem, FeedImg, type FeedImgData, FeedPrice, type FeedPriceData, FeedProduct, FeedQuantity, type FeedQuantityData, FeedRelation, type FeedRelationData, ListingImg, type ListingImgData, ListingPrice, type ListingPriceData, ListingProduct, ListingQuantity, type ListingQuantityData, ListingRelation, type ListingType, type ProductData, type Recordable, type RenderOtherAttributesFn, SchemaCheck, combineObjAttr, filterUndefinedKeys, getImageType, imageTypeJsonMap, renderListingArrValue };