@trustrails/sdk 0.4.6 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,11 +18,10 @@ const trustrails = new TrustRails('your-api-key');
18
18
 
19
19
  // Search for products with filters
20
20
  const results = await trustrails.search({
21
- query: 'laptop',
22
21
  brand: 'HP',
22
+ category: 'Laptops',
23
23
  minPrice: 400,
24
24
  maxPrice: 600,
25
- category: 'Laptops'
26
25
  });
27
26
 
28
27
  console.log(`Found ${results.total} products`);
@@ -62,41 +61,50 @@ new TrustRails({ apiKey: string, baseUrl?: string })
62
61
  Search for products. Returns summary data (title, price, availability, category). For full technical specs, call `product(id)` with the product ID.
63
62
 
64
63
  **Parameters:**
65
- - `options.query?: string` - Search query string (searches title, brand, category)
64
+ - `options.query?: string` - Refinement terms after brand and category are extracted: model lines, series names, variants, or model numbers (e.g. `'neo'`, `'ultra'`, `'oled'`, `'WH-1000XM5'`). Omit entirely if brand + category fully describe what you want. Never put brand names or prices here — use filters.
66
65
  - `options.brand?: string` - Filter by brand name (e.g., 'Sony', 'HP', 'Anker')
67
66
  - `options.category?: string` - Filter by product category (e.g., 'Laptops', 'Headphones')
68
67
  - `options.minPrice?: number` - Minimum price filter in GBP
69
68
  - `options.maxPrice?: number` - Maximum price filter in GBP
70
- - `options.lite?: boolean` - Return trimmed product objects with only essential fields (reduces payload by ~80%)
69
+ - `options.lite?: boolean` - Return trimmed product objects with only essential fields including `offer_count` (reduces payload by ~80%)
71
70
  - `options.limit?: number` - Maximum number of results (default: 50, max: 100)
72
71
  - `options.sort?: string` - Sort order: `'relevance'` (default), `'price_asc'` (cheapest first), `'price_desc'` (most expensive first)
73
72
 
74
73
  **Returns:** Promise resolving to `SearchResponse` containing `products` array and `total` count.
75
74
 
76
- **Example:**
75
+ **Example — brand + category only (query omitted):**
77
76
  ```typescript
78
77
  const results = await trustrails.search({
79
- query: 'laptop',
80
78
  brand: 'HP',
79
+ category: 'Laptops',
81
80
  minPrice: 400,
82
81
  maxPrice: 1000,
83
- category: 'Laptops',
84
82
  sort: 'price_asc'
85
83
  });
86
84
  ```
87
85
 
86
+ **Example — with model line in query:**
87
+ ```typescript
88
+ // 'neo', 'ultra', 'oled' etc. go in query — they refine within brand/category
89
+ const results = await trustrails.search({
90
+ brand: 'Samsung',
91
+ category: 'TVs',
92
+ query: 'qled',
93
+ });
94
+ ```
95
+
88
96
  **Lite mode (faster responses, smaller payloads):**
89
97
  ```typescript
90
98
  const results = await trustrails.search({
91
- query: 'wireless mouse',
92
- maxPrice: 50,
99
+ brand: 'Anker',
100
+ category: 'Cables & Chargers',
93
101
  lite: true // Returns only: id, title, brand, price, availability, image_url, purchase_url
94
102
  });
95
103
  ```
96
104
 
97
105
  ##### `product(id: string): Promise<Product>`
98
106
 
99
- Get full details for a single product. Returns complete technical specifications, full description, stock level, delivery time, and retailer source. Use this after `search()` to get detailed specs for comparison or recommendations.
107
+ Get full details for a single product. Returns complete technical specifications including `specs.description` (full prose spec text with processor, RAM, storage, display, etc.), stock level, delivery time, and all retailer offers with per-retailer pricing. Accepts canonical product IDs or original retailer offer IDs. Use this after `search()` to get detailed specs for comparison or recommendations.
100
108
 
101
109
  **Parameters:**
102
110
  - `id: string` - The product ID
@@ -115,8 +123,8 @@ const product = await trustrails.product('prod_123');
115
123
  ```typescript
116
124
  interface Product {
117
125
  id: string;
126
+ ean?: string;
118
127
  title: string;
119
- description?: string;
120
128
  brand?: string;
121
129
  price: number;
122
130
  currency: string;
@@ -127,13 +135,31 @@ interface Product {
127
135
  category: string;
128
136
  product_type: "product" | "accessory";
129
137
  specs: {
130
- [key: string]: any;
138
+ description?: string; // Full prose spec text — always check this for technical details
139
+ model_number?: string;
140
+ dimensions?: string;
131
141
  };
132
142
  provenance: {
133
143
  source: string;
134
144
  last_updated: string;
135
145
  };
136
146
  purchase_url: string;
147
+ offer_count?: number; // number of retailer offers (when >1, call product() to compare prices)
148
+ offers?: Offer[]; // per-retailer offers sorted by price (returned by product())
149
+ }
150
+
151
+ interface Offer {
152
+ id: string;
153
+ source: string;
154
+ title: string;
155
+ price: number;
156
+ currency: string;
157
+ availability: "in_stock" | "low_stock" | "out_of_stock";
158
+ stock: number;
159
+ delivery_time: string;
160
+ purchase_url: string;
161
+ image_url?: string;
162
+ last_updated: string;
137
163
  }
138
164
  ```
139
165
 
package/dist/index.d.mts CHANGED
@@ -2,13 +2,29 @@
2
2
  * Product availability status
3
3
  */
4
4
  type Availability = "in_stock" | "low_stock" | "out_of_stock";
5
+ /**
6
+ * Per-retailer offer for a product
7
+ */
8
+ interface Offer {
9
+ id: string;
10
+ source: string;
11
+ title: string;
12
+ price: number;
13
+ currency: string;
14
+ availability: Availability;
15
+ stock: number;
16
+ delivery_time: string;
17
+ purchase_url: string;
18
+ image_url?: string;
19
+ last_updated: string;
20
+ }
5
21
  /**
6
22
  * Product information returned by TrustRails API
7
23
  */
8
24
  interface Product {
9
25
  id: string;
26
+ ean?: string;
10
27
  title: string;
11
- description?: string;
12
28
  brand?: string;
13
29
  price: number;
14
30
  currency: string;
@@ -19,16 +35,19 @@ interface Product {
19
35
  category: string;
20
36
  product_type: 'product' | 'accessory';
21
37
  specs: {
22
- raw_category?: string;
38
+ description?: string;
23
39
  model_number?: string;
24
40
  dimensions?: string;
25
- [key: string]: any;
26
41
  };
27
42
  provenance: {
28
43
  source: string;
29
44
  last_updated: string;
30
45
  };
31
46
  purchase_url: string;
47
+ /** Number of retailer offers available for this product */
48
+ offer_count?: number;
49
+ /** Per-retailer offers sorted by price (full mode / getProduct only) */
50
+ offers?: Offer[];
32
51
  }
33
52
  /**
34
53
  * Options for searching products
package/dist/index.d.ts CHANGED
@@ -2,13 +2,29 @@
2
2
  * Product availability status
3
3
  */
4
4
  type Availability = "in_stock" | "low_stock" | "out_of_stock";
5
+ /**
6
+ * Per-retailer offer for a product
7
+ */
8
+ interface Offer {
9
+ id: string;
10
+ source: string;
11
+ title: string;
12
+ price: number;
13
+ currency: string;
14
+ availability: Availability;
15
+ stock: number;
16
+ delivery_time: string;
17
+ purchase_url: string;
18
+ image_url?: string;
19
+ last_updated: string;
20
+ }
5
21
  /**
6
22
  * Product information returned by TrustRails API
7
23
  */
8
24
  interface Product {
9
25
  id: string;
26
+ ean?: string;
10
27
  title: string;
11
- description?: string;
12
28
  brand?: string;
13
29
  price: number;
14
30
  currency: string;
@@ -19,16 +35,19 @@ interface Product {
19
35
  category: string;
20
36
  product_type: 'product' | 'accessory';
21
37
  specs: {
22
- raw_category?: string;
38
+ description?: string;
23
39
  model_number?: string;
24
40
  dimensions?: string;
25
- [key: string]: any;
26
41
  };
27
42
  provenance: {
28
43
  source: string;
29
44
  last_updated: string;
30
45
  };
31
46
  purchase_url: string;
47
+ /** Number of retailer offers available for this product */
48
+ offer_count?: number;
49
+ /** Per-retailer offers sorted by price (full mode / getProduct only) */
50
+ offers?: Offer[];
32
51
  }
33
52
  /**
34
53
  * Options for searching products
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustrails/sdk",
3
- "version": "0.4.6",
3
+ "version": "0.4.9",
4
4
  "description": "Official TypeScript SDK for TrustRails API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",