@trustrails/sdk 0.4.2 → 0.4.3
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 +5 -3
- package/dist/index.d.mts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ new TrustRails({ apiKey: string, baseUrl?: string })
|
|
|
59
59
|
|
|
60
60
|
##### `search(options?: SearchOptions): Promise<SearchResponse>`
|
|
61
61
|
|
|
62
|
-
Search for products.
|
|
62
|
+
Search for products. Returns summary data (title, price, availability, category). For full technical specs, call `product(id)` with the product ID.
|
|
63
63
|
|
|
64
64
|
**Parameters:**
|
|
65
65
|
- `options.query?: string` - Search query string (searches title, brand, category)
|
|
@@ -95,12 +95,12 @@ const results = await trustrails.search({
|
|
|
95
95
|
|
|
96
96
|
##### `product(id: string): Promise<Product>`
|
|
97
97
|
|
|
98
|
-
Get a
|
|
98
|
+
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.
|
|
99
99
|
|
|
100
100
|
**Parameters:**
|
|
101
101
|
- `id: string` - The product ID
|
|
102
102
|
|
|
103
|
-
**Returns:** Promise resolving to `Product` object
|
|
103
|
+
**Returns:** Promise resolving to `Product` object with all fields populated
|
|
104
104
|
|
|
105
105
|
**Example:**
|
|
106
106
|
```typescript
|
|
@@ -122,6 +122,8 @@ interface Product {
|
|
|
122
122
|
stock: number;
|
|
123
123
|
delivery_time: string;
|
|
124
124
|
image_url?: string;
|
|
125
|
+
category: string;
|
|
126
|
+
product_type: "product" | "accessory";
|
|
125
127
|
specs: {
|
|
126
128
|
[key: string]: any;
|
|
127
129
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -15,11 +15,12 @@ interface Product {
|
|
|
15
15
|
stock: number;
|
|
16
16
|
delivery_time: string;
|
|
17
17
|
image_url?: string;
|
|
18
|
+
category: string;
|
|
19
|
+
product_type: 'product' | 'accessory';
|
|
18
20
|
specs: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
pd_version?: string;
|
|
21
|
+
raw_category?: string;
|
|
22
|
+
model_number?: string;
|
|
23
|
+
dimensions?: string;
|
|
23
24
|
[key: string]: any;
|
|
24
25
|
};
|
|
25
26
|
provenance: {
|
|
@@ -82,7 +83,8 @@ declare class TrustRails {
|
|
|
82
83
|
*/
|
|
83
84
|
constructor(config: TrustRailsConfig);
|
|
84
85
|
/**
|
|
85
|
-
* Search for products
|
|
86
|
+
* Search for products. Returns summary data (title, price, availability, category).
|
|
87
|
+
* For full technical specs, call product(id) with the product ID.
|
|
86
88
|
*
|
|
87
89
|
* @param options - Search parameters
|
|
88
90
|
* @returns Promise resolving to search results
|
|
@@ -100,10 +102,12 @@ declare class TrustRails {
|
|
|
100
102
|
*/
|
|
101
103
|
search(options?: SearchOptions): Promise<SearchResponse>;
|
|
102
104
|
/**
|
|
103
|
-
* Get a
|
|
105
|
+
* Get full details for a single product. Returns complete specs, description,
|
|
106
|
+
* stock level, delivery time, and retailer source. Use after search() for
|
|
107
|
+
* detailed comparison or recommendations.
|
|
104
108
|
*
|
|
105
109
|
* @param id - The product ID
|
|
106
|
-
* @returns Promise resolving to product details
|
|
110
|
+
* @returns Promise resolving to complete product details
|
|
107
111
|
*
|
|
108
112
|
* @example
|
|
109
113
|
* ```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -15,11 +15,12 @@ interface Product {
|
|
|
15
15
|
stock: number;
|
|
16
16
|
delivery_time: string;
|
|
17
17
|
image_url?: string;
|
|
18
|
+
category: string;
|
|
19
|
+
product_type: 'product' | 'accessory';
|
|
18
20
|
specs: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
pd_version?: string;
|
|
21
|
+
raw_category?: string;
|
|
22
|
+
model_number?: string;
|
|
23
|
+
dimensions?: string;
|
|
23
24
|
[key: string]: any;
|
|
24
25
|
};
|
|
25
26
|
provenance: {
|
|
@@ -82,7 +83,8 @@ declare class TrustRails {
|
|
|
82
83
|
*/
|
|
83
84
|
constructor(config: TrustRailsConfig);
|
|
84
85
|
/**
|
|
85
|
-
* Search for products
|
|
86
|
+
* Search for products. Returns summary data (title, price, availability, category).
|
|
87
|
+
* For full technical specs, call product(id) with the product ID.
|
|
86
88
|
*
|
|
87
89
|
* @param options - Search parameters
|
|
88
90
|
* @returns Promise resolving to search results
|
|
@@ -100,10 +102,12 @@ declare class TrustRails {
|
|
|
100
102
|
*/
|
|
101
103
|
search(options?: SearchOptions): Promise<SearchResponse>;
|
|
102
104
|
/**
|
|
103
|
-
* Get a
|
|
105
|
+
* Get full details for a single product. Returns complete specs, description,
|
|
106
|
+
* stock level, delivery time, and retailer source. Use after search() for
|
|
107
|
+
* detailed comparison or recommendations.
|
|
104
108
|
*
|
|
105
109
|
* @param id - The product ID
|
|
106
|
-
* @returns Promise resolving to product details
|
|
110
|
+
* @returns Promise resolving to complete product details
|
|
107
111
|
*
|
|
108
112
|
* @example
|
|
109
113
|
* ```typescript
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,8 @@ var TrustRails = class {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Search for products
|
|
37
|
+
* Search for products. Returns summary data (title, price, availability, category).
|
|
38
|
+
* For full technical specs, call product(id) with the product ID.
|
|
38
39
|
*
|
|
39
40
|
* @param options - Search parameters
|
|
40
41
|
* @returns Promise resolving to search results
|
|
@@ -100,10 +101,12 @@ var TrustRails = class {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
103
|
-
* Get a
|
|
104
|
+
* Get full details for a single product. Returns complete specs, description,
|
|
105
|
+
* stock level, delivery time, and retailer source. Use after search() for
|
|
106
|
+
* detailed comparison or recommendations.
|
|
104
107
|
*
|
|
105
108
|
* @param id - The product ID
|
|
106
|
-
* @returns Promise resolving to product details
|
|
109
|
+
* @returns Promise resolving to complete product details
|
|
107
110
|
*
|
|
108
111
|
* @example
|
|
109
112
|
* ```typescript
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"names":[],"mappings":";;;;;AAGO,IAAM,eAAA,GAAN,MAAM,gBAAA,SAAwB,KAAA,CAAM;AAAA,EACzC,WAAA,CACE,OAAA,EACO,UAAA,EACA,QAAA,EACP;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHN,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAGP,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AAGZ,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,MAAA,KAAA,CAAM,iBAAA,CAAkB,MAAM,gBAAe,CAAA;AAAA,IAC/C;AAAA,EACF;AACF;;;ACdA,IAAM,gBAAA,GAAmB,wBAAA;AAWlB,IAAM,aAAN,MAAiB;AAAA,EAgBtB,YAAY,cAAA,EAA2C;AACrD,IAAA,IAAI,OAAO,mBAAmB,QAAA,EAAU;AACtC,MAAA,IAAA,CAAK,MAAA,GAAS,cAAA;AACd,MAAA,IAAA,CAAK,OAAA,GAAU,gBAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,SAAS,cAAA,CAAe,MAAA;AAC7B,MAAA,IAAA,CAAK,OAAA,GAAU,eAAe,OAAA,IAAW,gBAAA;AAAA,IAC3C;AAGA,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,QAAA,CAAS,GAAG,CAAA,EAAG;AAC9B,MAAA,IAAA,CAAK,OAAA,GAAU,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,GAAG,EAAE,CAAA;AAAA,IACzC;AAEA,IAAA,IAAI,CAAC,KAAK,MAAA,EAAQ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,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,QAChC,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,MAAM,CAAA,CAAA;AAAA,UACtC,cAAA,EAAgB;AAAA;AAClB,OACD,CAAA;AAED,MAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,QAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAC3B,UAAA,MAAM,IAAI,eAAA,CAAgB,CAAA,mBAAA,EAAsB,EAAE,IAAI,GAAG,CAAA;AAAA,QAC3D;AACA,QAAA,MAAM,IAAI,eAAA;AAAA,UACR,CAAA,oBAAA,EAAuB,SAAS,UAAU,CAAA,CAAA;AAAA,UAC1C,QAAA,CAAS,MAAA;AAAA,UACT,MAAM,SAAS,IAAA;AAAK,SACtB;AAAA,MACF;AAEA,MAAA,MAAM,OAAA,GAAU,MAAM,QAAA,CAAS,IAAA,EAAK;AACpC,MAAA,OAAO,OAAA;AAAA,IACT,SAAS,KAAA,EAAO;AACd,MAAA,IAAI,iBAAiB,eAAA,EAAiB;AACpC,QAAA,MAAM,KAAA;AAAA,MACR;AACA,MAAA,MAAM,IAAI,eAAA;AAAA,QACR,CAAA,eAAA,EAAkB,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,UAAU,eAAe,CAAA;AAAA,OAC5E;AAAA,IACF;AAAA,EACF;AACF","file":"index.js","sourcesContent":["/**\n * Custom error class for TrustRails API errors\n */\nexport class TrustRailsError extends Error {\n constructor(\n message: string,\n public statusCode?: number,\n public response?: any\n ) {\n super(message);\n this.name = 'TrustRailsError';\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, TrustRailsError);\n }\n }\n}\n","import { TrustRailsError } from './errors';\nimport type { Product, SearchOptions, SearchResponse, TrustRailsConfig } from './types';\n\nconst DEFAULT_BASE_URL = 'https://trustrails.app';\n\n/**\n * TrustRails SDK\n *\n * @example\n * ```typescript\n * const trustrails = new TrustRails('your-api-key');\n * const results = await trustrails.search({ query: 'laptop', maxPrice: 1000 });\n * ```\n */\nexport class TrustRails {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n /**\n * Creates a new TrustRails SDK instance\n *\n * @param apiKey - Your TrustRails API key\n */\n constructor(apiKey: string);\n /**\n * Creates a new TrustRails SDK instance with custom configuration\n *\n * @param config - Configuration object with apiKey and optional baseUrl\n */\n constructor(config: TrustRailsConfig);\n constructor(apiKeyOrConfig: string | TrustRailsConfig) {\n if (typeof apiKeyOrConfig === 'string') {\n this.apiKey = apiKeyOrConfig;\n this.baseUrl = DEFAULT_BASE_URL;\n } else {\n this.apiKey = apiKeyOrConfig.apiKey;\n this.baseUrl = apiKeyOrConfig.baseUrl || DEFAULT_BASE_URL;\n }\n\n // Clean up baseUrl - remove trailing slash\n if (this.baseUrl.endsWith('/')) {\n this.baseUrl = this.baseUrl.slice(0, -1);\n }\n\n if (!this.apiKey) {\n throw new Error('apiKey is required');\n }\n }\n\n /**\n * Search for products. Returns summary data (title, price, availability, category).\n * For full technical specs, call product(id) with the product ID.\n *\n * @param options - Search parameters\n * @returns Promise resolving to search results\n *\n * @example\n * ```typescript\n * const results = await client.search({\n * query: 'USB-C charger',\n * brand: 'Anker',\n * minPrice: 20,\n * maxPrice: 50,\n * category: 'Chargers'\n * });\n * ```\n */\n async search(options: SearchOptions = {}): Promise<SearchResponse> {\n const url = new URL(`${this.baseUrl}/api/search`);\n\n if (options.query) {\n url.searchParams.set('query', options.query);\n }\n\n if (options.minPrice) {\n url.searchParams.set('min_price', options.minPrice.toString());\n }\n\n if (options.maxPrice) {\n url.searchParams.set('max_price', options.maxPrice.toString());\n }\n\n if (options.brand) {\n url.searchParams.set('brand', options.brand);\n }\n\n if (options.category) {\n url.searchParams.set('category', options.category);\n }\n\n if (options.lite) {\n url.searchParams.set('lite', 'true');\n }\n\n if (options.limit) {\n url.searchParams.set('limit', options.limit.toString());\n }\n\n try {\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new TrustRailsError(\n `Search failed: ${response.statusText}`,\n response.status,\n await response.text()\n );\n }\n\n const data = await response.json() as SearchResponse;\n return data;\n } catch (error) {\n if (error instanceof TrustRailsError) {\n throw error;\n }\n throw new TrustRailsError(\n `Network error: ${error instanceof Error ? error.message : 'Unknown error'}`\n );\n }\n }\n\n /**\n * Get full details for a single product. Returns complete specs, description,\n * stock level, delivery time, and retailer source. Use after search() for\n * detailed comparison or recommendations.\n *\n * @param id - The product ID\n * @returns Promise resolving to complete product details\n *\n * @example\n * ```typescript\n * const product = await client.product('prod_123');\n * ```\n */\n async product(id: string): Promise<Product> {\n if (!id) {\n throw new Error('Product ID is required');\n }\n\n const url = `${this.baseUrl}/api/product/${encodeURIComponent(id)}`;\n\n try {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n if (response.status === 404) {\n throw new TrustRailsError(`Product not found: ${id}`, 404);\n }\n throw new TrustRailsError(\n `Get product failed: ${response.statusText}`,\n response.status,\n await response.text()\n );\n }\n\n const product = await response.json() as Product;\n return product;\n } catch (error) {\n if (error instanceof TrustRailsError) {\n throw error;\n }\n throw new TrustRailsError(\n `Network error: ${error instanceof Error ? error.message : 'Unknown error'}`\n );\n }\n }\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,8 @@ var TrustRails = class {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Search for products
|
|
33
|
+
* Search for products. Returns summary data (title, price, availability, category).
|
|
34
|
+
* For full technical specs, call product(id) with the product ID.
|
|
34
35
|
*
|
|
35
36
|
* @param options - Search parameters
|
|
36
37
|
* @returns Promise resolving to search results
|
|
@@ -96,10 +97,12 @@ var TrustRails = class {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
|
-
* Get a
|
|
100
|
+
* Get full details for a single product. Returns complete specs, description,
|
|
101
|
+
* stock level, delivery time, and retailer source. Use after search() for
|
|
102
|
+
* detailed comparison or recommendations.
|
|
100
103
|
*
|
|
101
104
|
* @param id - The product ID
|
|
102
|
-
* @returns Promise resolving to product details
|
|
105
|
+
* @returns Promise resolving to complete product details
|
|
103
106
|
*
|
|
104
107
|
* @example
|
|
105
108
|
* ```typescript
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAN,MAAM,gBAAA,SAAwB,KAAA,CAAM;AAAA,EACzC,WAAA,CACE,OAAA,EACO,UAAA,EACA,QAAA,EACP;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHN,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAGP,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AAGZ,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,MAAA,KAAA,CAAM,iBAAA,CAAkB,MAAM,gBAAe,CAAA;AAAA,IAC/C;AAAA,EACF;AACF;;;ACdA,IAAM,gBAAA,GAAmB,wBAAA;AAWlB,IAAM,aAAN,MAAiB;AAAA,EAgBtB,YAAY,cAAA,EAA2C;AACrD,IAAA,IAAI,OAAO,mBAAmB,QAAA,EAAU;AACtC,MAAA,IAAA,CAAK,MAAA,GAAS,cAAA;AACd,MAAA,IAAA,CAAK,OAAA,GAAU,gBAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,SAAS,cAAA,CAAe,MAAA;AAC7B,MAAA,IAAA,CAAK,OAAA,GAAU,eAAe,OAAA,IAAW,gBAAA;AA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AC,EAAA,EAAI;AACP,MAAA,MAAM,IAAI,MAAM,wBAAwB,CAAA;AAAA,IAC1C;AAEA,IAAA,MAAM,MAAM,CAAA,EAAG,IAAA,CAAK,OAAO,CAAA,aAAA,EAAgB,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA;AAEjE,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,QAChC,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACP,eAAA,EAAiB,CAAA,OAAA,EAAU,IAAA,CAAK,MAAM,CAAA,CAAA;AAAA,UACtC,cAAA,EAAgB;AAAA;AAClB,OACD,CAAA;AAED,MAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,QAAA,IAAI,QAAA,CAAS,WAAW,GAAA,EAAK;AAC3B,UAAA,MAAM,IAAI,eAAA,CAAgB,CAAA,mBAAA,EAAsB,EAAE,IAAI,GAAG,CAAA;AAAA,QAC3D;AACA,QAAA,MAAM,IAAI,eAAA;AAAA,UACR,CAAA,oBAAA,EAAuB,SAAS,UAAU,CAAA,CAAA;AAAA,UAC1C,QAAA,CAAS,MAAA;AAAA,UACT,MAAM,SAAS,IAAA;AAAK,SACtB;AAAA,MACF;AAEA,MAAA,MAAM,OAAA,GAAU,MAAM,QAAA,CAAS,IAAA,EAAK;AACpC,MAAA,OAAO,OAAA;AAAA,IACT,SAAS,KAAA,EAAO;AACd,MAAA,IAAI,iBAAiB,eAAA,EAAiB;AACpC,QAAA,MAAM,KAAA;AAAA,MACR;AACA,MAAA,MAAM,IAAI,eAAA;AAAA,QACR,CAAA,eAAA,EAAkB,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,UAAU,eAAe,CAAA;AAAA,OAC5E;AAAA,IACF;AAAA,EACF;AACF","file":"index.mjs","sourcesContent":["/**\n * Custom error class for TrustRails API errors\n */\nexport class TrustRailsError extends Error {\n constructor(\n message: string,\n public statusCode?: number,\n public response?: any\n ) {\n super(message);\n this.name = 'TrustRailsError';\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, TrustRailsError);\n }\n }\n}\n","import { TrustRailsError } from './errors';\nimport type { Product, SearchOptions, SearchResponse, TrustRailsConfig } from './types';\n\nconst DEFAULT_BASE_URL = 'https://trustrails.app';\n\n/**\n * TrustRails SDK\n *\n * @example\n * ```typescript\n * const trustrails = new TrustRails('your-api-key');\n * const results = await trustrails.search({ query: 'laptop', maxPrice: 1000 });\n * ```\n */\nexport class TrustRails {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n /**\n * Creates a new TrustRails SDK instance\n *\n * @param apiKey - Your TrustRails API key\n */\n constructor(apiKey: string);\n /**\n * Creates a new TrustRails SDK instance with custom configuration\n *\n * @param config - Configuration object with apiKey and optional baseUrl\n */\n constructor(config: TrustRailsConfig);\n constructor(apiKeyOrConfig: string | TrustRailsConfig) {\n if (typeof apiKeyOrConfig === 'string') {\n this.apiKey = apiKeyOrConfig;\n this.baseUrl = DEFAULT_BASE_URL;\n } else {\n this.apiKey = apiKeyOrConfig.apiKey;\n this.baseUrl = apiKeyOrConfig.baseUrl || DEFAULT_BASE_URL;\n }\n\n // Clean up baseUrl - remove trailing slash\n if (this.baseUrl.endsWith('/')) {\n this.baseUrl = this.baseUrl.slice(0, -1);\n }\n\n if (!this.apiKey) {\n throw new Error('apiKey is required');\n }\n }\n\n /**\n * Search for products. Returns summary data (title, price, availability, category).\n * For full technical specs, call product(id) with the product ID.\n *\n * @param options - Search parameters\n * @returns Promise resolving to search results\n *\n * @example\n * ```typescript\n * const results = await client.search({\n * query: 'USB-C charger',\n * brand: 'Anker',\n * minPrice: 20,\n * maxPrice: 50,\n * category: 'Chargers'\n * });\n * ```\n */\n async search(options: SearchOptions = {}): Promise<SearchResponse> {\n const url = new URL(`${this.baseUrl}/api/search`);\n\n if (options.query) {\n url.searchParams.set('query', options.query);\n }\n\n if (options.minPrice) {\n url.searchParams.set('min_price', options.minPrice.toString());\n }\n\n if (options.maxPrice) {\n url.searchParams.set('max_price', options.maxPrice.toString());\n }\n\n if (options.brand) {\n url.searchParams.set('brand', options.brand);\n }\n\n if (options.category) {\n url.searchParams.set('category', options.category);\n }\n\n if (options.lite) {\n url.searchParams.set('lite', 'true');\n }\n\n if (options.limit) {\n url.searchParams.set('limit', options.limit.toString());\n }\n\n try {\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new TrustRailsError(\n `Search failed: ${response.statusText}`,\n response.status,\n await response.text()\n );\n }\n\n const data = await response.json() as SearchResponse;\n return data;\n } catch (error) {\n if (error instanceof TrustRailsError) {\n throw error;\n }\n throw new TrustRailsError(\n `Network error: ${error instanceof Error ? error.message : 'Unknown error'}`\n );\n }\n }\n\n /**\n * Get full details for a single product. Returns complete specs, description,\n * stock level, delivery time, and retailer source. Use after search() for\n * detailed comparison or recommendations.\n *\n * @param id - The product ID\n * @returns Promise resolving to complete product details\n *\n * @example\n * ```typescript\n * const product = await client.product('prod_123');\n * ```\n */\n async product(id: string): Promise<Product> {\n if (!id) {\n throw new Error('Product ID is required');\n }\n\n const url = `${this.baseUrl}/api/product/${encodeURIComponent(id)}`;\n\n try {\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n if (response.status === 404) {\n throw new TrustRailsError(`Product not found: ${id}`, 404);\n }\n throw new TrustRailsError(\n `Get product failed: ${response.statusText}`,\n response.status,\n await response.text()\n );\n }\n\n const product = await response.json() as Product;\n return product;\n } catch (error) {\n if (error instanceof TrustRailsError) {\n throw error;\n }\n throw new TrustRailsError(\n `Network error: ${error instanceof Error ? error.message : 'Unknown error'}`\n );\n }\n }\n}\n"]}
|