google-retail-api-client
Version:
Official TypeScript client for Google Retail API
276 lines (275 loc) • 6.96 kB
TypeScript
/**
* Configuration options for the RetailClient
*/
export interface RetailClientConfig {
credentials: any;
/** Google Cloud Project ID */
projectId: string;
/** Location of the retail service (default: "global") */
location?: string;
/** Catalog ID (default: "default_catalog") */
catalogId?: string;
/** Request timeout in milliseconds (default: 10000) */
timeout?: number;
}
/**
* Parameters for search requests
*/
export interface SearchParams {
/** Search query string */
query?: string;
/** Filter string in retail API format */
filter?: string;
/** Number of results per page */
pageSize?: number;
/** Offset for pagination */
offset?: number;
/** Order by field and direction */
orderBy?: string;
/** Facets to return */
facets?: string[];
/** Visitor ID */
visitorId?: string;
}
/**
* Search response structure
*/
export interface SearchResponse {
/** Array of search results */
results: RetailProduct[];
/** Total number of results */
totalSize: number;
/** Facet results */
facets?: FacetResult[];
/** Token for next page */
nextPageToken?: string;
visitorId?: string;
}
/**
* Parameters for prediction/recommendation requests
*/
export interface PredictionParams {
/** User event information */
userEvent: {
/** Type of event (e.g., "home-page-view", "detail-page-view") */
eventType: string;
/** Unique visitor identifier */
visitorId: string;
/** Product details for the event */
productDetails?: {
product: {
id: string;
};
}[];
};
/** Number of predictions to return */
pageSize: number;
/** Filter for predictions */
filter?: string;
/** Additional parameters */
params?: {
/** Whether to return full product details */
returnProduct?: boolean;
/** Whether to return prediction scores */
returnScore?: boolean;
/** Validation only mode */
validateOnly?: boolean;
/** Use V2 filter syntax */
filterSyntaxV2?: boolean;
/** Types to include */
includedTypes?: string[];
};
}
/**
* Prediction/recommendation response
*/
export interface PredictionResponse {
/** Array of prediction results */
results: {
/** Product ID */
id: string;
/** Product details */
product: RetailProduct;
/** Prediction score */
score: number;
}[];
/** Additional metadata */
metadata: {
/** Token for this recommendation */
recommendationToken: string;
/** Out of stock products */
outOfStockProducts: string[];
/** Missing products */
missingProducts: string[];
};
}
/**
* Retail product structure
*/
export interface RetailProduct {
metadata: any;
/** Product ID */
id: string;
/** Product type */
type?: string;
/** Primary product title */
title: string;
/** Additional titles in different languages */
titles?: Record<string, string>;
/** Primary product description */
description?: string;
/** Additional descriptions in different languages */
descriptions?: Record<string, string>;
/** Product language */
language?: string;
/** Product attributes */
attributes?: Record<string, any>;
/** Product tags */
tags?: string[];
/** Product price info */
priceInfo?: {
/** Currency code (e.g., "USD") */
currencyCode: string;
/** Current price */
price: number;
/** Original price */
originalPrice?: number;
/** Cost of goods */
cost?: number;
/** Price effective time */
priceEffectiveTime?: string;
/** Price expire time */
priceExpireTime?: string;
};
/** Rating information */
rating?: {
/** Average rating (1-5) */
averageRating: number;
/** Rating count */
ratingCount: number;
/** Rating histogram */
ratingHistogram?: number[];
};
/** Available quantity */
availableQuantity?: number;
/** Fulfillment info */
fulfillmentInfo?: {
/** Type of fulfillment */
type: string;
/** Place IDs */
placeIds?: string[];
}[];
/** Available time */
availableTime?: string;
/** Availability */
availability?: 'IN_STOCK' | 'OUT_OF_STOCK' | 'PREORDER' | 'BACKORDER';
/** Product URL */
uri?: string;
/** Product images */
images?: {
/** Image URI */
uri: string;
/** Height in pixels */
height?: number;
/** Width in pixels */
width?: number;
}[];
/** Product categories */
categories?: string[];
/** Brand name */
brands?: string[];
/** Product variants */
variants?: RetailProduct[];
/** Publishing time */
publishTime?: string;
/** Retrieved time */
retrieveTime?: string;
/** Promotion IDs */
promotions?: string[];
}
/**
* Facet result structure
*/
export interface FacetResult {
/** Facet key */
key: string;
/** Facet values */
values: {
/** Value */
value: string;
/** Count */
count: number;
}[];
/** Dynamic facet ranking score */
dynamicFacetScore?: number;
}
/**
* Error response from the API
*/
export interface RetailApiErrorResponse {
/** Error code */
code: number;
/** Error message */
message: string;
/** Error details */
details?: any;
}
/**
* Recommendation parameters
*/
export interface RecommendationParams {
/** Product key to base recommendations on */
productKey: string;
/** Distribution channel */
distributionChannel: string;
/** Currency code */
currency: string;
/** Number of recommendations to return */
limit: number;
}
/**
* Product collection in catalog
*/
export interface ProductCollection {
/** Collection ID */
id: string;
/** Collection name */
displayName: string;
/** Products in collection */
products: RetailProduct[];
}
/**
* User event for tracking
*/
export interface UserEvent {
/** Event type */
eventType: string;
/** Visitor ID */
visitorId: string;
/** Event time */
eventTime?: string;
/** Product details */
productDetails?: {
product: {
id: string;
};
quantity?: number;
}[];
/** Cart ID */
cartId?: string;
/** Purchase transaction */
purchaseTransaction?: {
/** Transaction ID */
id: string;
/** Revenue */
revenue: number;
/** Tax */
tax?: number;
/** Shipping cost */
shipping?: number;
/** Currency code */
currencyCode: string;
};
/** Attribution token */
attributionToken?: string;
}