@chat-ads/chatads-sdk 0.1.10 → 0.1.12
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 +12 -15
- package/dist/client.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/models.d.ts +4 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,8 +29,8 @@ const response = await client.analyze({
|
|
|
29
29
|
ip: "8.8.8.8",
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
if (response.
|
|
33
|
-
console.log(response.data.
|
|
32
|
+
if (response.data?.offers?.length) {
|
|
33
|
+
console.log(response.data.offers[0]);
|
|
34
34
|
} else {
|
|
35
35
|
console.error(response.error);
|
|
36
36
|
}
|
|
@@ -45,7 +45,7 @@ const result = await client.analyzeMessage("Need scheduling ideas", {
|
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
- Reserved payload keys (like `message`, `country`, etc.) cannot be overwritten inside `extraFields`; the client throws if it detects a collision.
|
|
48
|
-
- Pass `raiseOnFailure: true` to throw `ChatAdsAPIError` when the API returns
|
|
48
|
+
- Pass `raiseOnFailure: true` to throw `ChatAdsAPIError` when the API returns an error with HTTP 200 responses.
|
|
49
49
|
- Retries honor `Retry-After` headers and exponential backoff (`maxRetries` + `retryBackoffFactorMs`).
|
|
50
50
|
|
|
51
51
|
## Error handling
|
|
@@ -66,7 +66,7 @@ try {
|
|
|
66
66
|
}
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
`ChatAdsAPIError` wraps non-2xx API responses (and optionally
|
|
69
|
+
`ChatAdsAPIError` wraps non-2xx API responses (and optionally error responses). `ChatAdsSDKError` covers local issues like invalid payloads, timeouts, or missing `fetch`.
|
|
70
70
|
|
|
71
71
|
## Configuration options
|
|
72
72
|
|
|
@@ -77,9 +77,9 @@ try {
|
|
|
77
77
|
| `endpoint` | Defaults to `/v1/chatads/messages`. Override if you host multiple versions. |
|
|
78
78
|
| `timeoutMs` | Request timeout (default 10s). |
|
|
79
79
|
| `maxRetries` | How many automatic retries to attempt for retryable HTTP statuses. |
|
|
80
|
-
| `retryStatuses` | Array of status codes treated as retryable (defaults to `408, 429,
|
|
80
|
+
| `retryStatuses` | Array of status codes treated as retryable (defaults to `408, 429, 500, 502, 503, 504`). |
|
|
81
81
|
| `retryBackoffFactorMs` | Base backoff delay in milliseconds (default 500). |
|
|
82
|
-
| `raiseOnFailure` | Throw when the API returns
|
|
82
|
+
| `raiseOnFailure` | Throw when the API returns an error even if HTTP 200. |
|
|
83
83
|
| `fetchImplementation` | Provide a custom `fetch` for Node < 18 or custom runtimes. |
|
|
84
84
|
| `logger` | Optional logger (any object with `debug`). Useful for redacted request logs. |
|
|
85
85
|
|
|
@@ -87,19 +87,16 @@ try {
|
|
|
87
87
|
|
|
88
88
|
```json
|
|
89
89
|
{
|
|
90
|
-
"success": true,
|
|
91
90
|
"data": {
|
|
92
|
-
"
|
|
93
|
-
"
|
|
91
|
+
"status": "filled",
|
|
92
|
+
"offers": [
|
|
94
93
|
{
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"URL": "https://amazon.com/dp/example?tag=chatads-20",
|
|
98
|
-
"Category": "Software"
|
|
94
|
+
"link_text": "CRM tools",
|
|
95
|
+
"url": "https://amazon.com/dp/example?tag=chatads-20"
|
|
99
96
|
}
|
|
100
97
|
],
|
|
101
|
-
"
|
|
102
|
-
"
|
|
98
|
+
"requested": 1,
|
|
99
|
+
"returned": 1
|
|
103
100
|
},
|
|
104
101
|
"error": null,
|
|
105
102
|
"meta": {
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { RESERVED_PAYLOAD_KEYS } from "./models.js";
|
|
|
3
3
|
const DEFAULT_ENDPOINT = "/v1/chatads/messages";
|
|
4
4
|
const DEFAULT_TIMEOUT_MS = 10000;
|
|
5
5
|
const DEFAULT_BACKOFF_FACTOR = 500; // ms
|
|
6
|
-
const DEFAULT_RETRYABLE_STATUSES = new Set([408,
|
|
6
|
+
const DEFAULT_RETRYABLE_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
|
|
7
7
|
/**
|
|
8
8
|
* Field aliases for normalizing optional field names.
|
|
9
9
|
* Only includes the 3 optional fields from the OpenAPI spec.
|
|
@@ -48,9 +48,9 @@ export class ChatAdsClient {
|
|
|
48
48
|
async post(body, options) {
|
|
49
49
|
const url = `${this.baseUrl}${this.endpoint}`;
|
|
50
50
|
const headers = {
|
|
51
|
+
...lowercaseHeaders(options?.headers),
|
|
51
52
|
"content-type": "application/json",
|
|
52
53
|
"x-api-key": this.apiKey,
|
|
53
|
-
...lowercaseHeaders(options?.headers),
|
|
54
54
|
};
|
|
55
55
|
let attempt = 0;
|
|
56
56
|
// eslint-disable-next-line no-constant-condition
|
|
@@ -127,6 +127,8 @@ function normalizeBaseUrl(raw) {
|
|
|
127
127
|
return url.toString().replace(/\/$/, "");
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
|
+
if (error instanceof ChatAdsSDKError)
|
|
131
|
+
throw error;
|
|
130
132
|
throw new ChatAdsSDKError(`Invalid baseUrl: ${raw}`, error);
|
|
131
133
|
}
|
|
132
134
|
}
|
|
@@ -184,6 +186,7 @@ async function parseResponse(response) {
|
|
|
184
186
|
returned: data.returned ?? 0,
|
|
185
187
|
extraction_source: data.extraction_source,
|
|
186
188
|
extraction_debug: data.extraction_debug,
|
|
189
|
+
resolution_debug: data.resolution_debug,
|
|
187
190
|
},
|
|
188
191
|
error: raw.error,
|
|
189
192
|
meta: raw.meta ?? { request_id: "unknown" },
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ChatAdsClient } from "./client.js";
|
|
2
2
|
export { ChatAdsAPIError, ChatAdsSDKError } from "./errors.js";
|
|
3
3
|
export type { ChatAdsClientOptions, AnalyzeOptions, AnalyzeMessageOptions, } from "./client.js";
|
|
4
|
-
export type { ChatAdsResponseEnvelope, Offer, Product, AnalyzeData, ChatAdsError, ChatAdsMeta, UsageInfo, FunctionItemPayload, FunctionItemOptionalFields, Quality,
|
|
4
|
+
export type { ChatAdsResponseEnvelope, Offer, Product, AnalyzeData, ChatAdsError, ChatAdsMeta, UsageInfo, FunctionItemPayload, FunctionItemOptionalFields, Quality, ResponseStatus, } from "./models.js";
|
package/dist/models.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export type Quality = "fast" | "standard" | "best";
|
|
2
|
-
export type ConfidenceLevel = "high" | "medium" | "low" | "very_low";
|
|
3
|
-
export type ResolutionSource = "demo" | "serper" | "amazon_paapi" | "cache" | "vector";
|
|
4
2
|
/** Top-level response status indicating the outcome of the request */
|
|
5
3
|
export type ResponseStatus = "filled" | "partial_fill" | "no_offers_found" | "internal_error";
|
|
6
4
|
/**
|
|
@@ -43,14 +41,12 @@ export interface Offer {
|
|
|
43
41
|
search_term?: string;
|
|
44
42
|
/** Confidence score (0.0-1.0) (verbose mode only) */
|
|
45
43
|
confidence_score?: number | null;
|
|
46
|
-
/** Confidence level classification */
|
|
47
|
-
confidence_level
|
|
44
|
+
/** Confidence level classification (verbose mode only) */
|
|
45
|
+
confidence_level?: string;
|
|
48
46
|
/** Affiliate URL (always populated) */
|
|
49
47
|
url: string;
|
|
50
48
|
/** Source of the URL resolution (e.g., amazon, serper, vector) (verbose mode only) */
|
|
51
49
|
resolution_source?: string;
|
|
52
|
-
/** Detected product category */
|
|
53
|
-
category?: string;
|
|
54
50
|
/** Product metadata from resolution */
|
|
55
51
|
product?: Product;
|
|
56
52
|
}
|
|
@@ -70,6 +66,8 @@ export interface AnalyzeData {
|
|
|
70
66
|
extraction_source?: string;
|
|
71
67
|
/** Extraction debug information (verbose mode only) */
|
|
72
68
|
extraction_debug?: unknown[];
|
|
69
|
+
/** Resolution debug information (verbose mode only) */
|
|
70
|
+
resolution_debug?: unknown[];
|
|
73
71
|
}
|
|
74
72
|
export interface ChatAdsError {
|
|
75
73
|
code: string;
|