@chat-ads/chatads-sdk 0.1.8 → 0.1.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 +1 -2
- package/dist/client.js +19 -13
- package/dist/index.d.ts +1 -1
- package/dist/models.d.ts +41 -50
- package/dist/models.js +2 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,6 @@ if (response.success && response.data?.Offers.length) {
|
|
|
41
41
|
```ts
|
|
42
42
|
const result = await client.analyzeMessage("Need scheduling ideas", {
|
|
43
43
|
country: "US",
|
|
44
|
-
message_analysis: "thorough",
|
|
45
44
|
});
|
|
46
45
|
```
|
|
47
46
|
|
|
@@ -90,12 +89,12 @@ try {
|
|
|
90
89
|
{
|
|
91
90
|
"success": true,
|
|
92
91
|
"data": {
|
|
92
|
+
"Status": "filled",
|
|
93
93
|
"Offers": [
|
|
94
94
|
{
|
|
95
95
|
"LinkText": "CRM tools",
|
|
96
96
|
"IntentLevel": "high",
|
|
97
97
|
"URL": "https://amazon.com/dp/example?tag=chatads-20",
|
|
98
|
-
"Status": "filled",
|
|
99
98
|
"Category": "Software"
|
|
100
99
|
}
|
|
101
100
|
],
|
package/dist/client.js
CHANGED
|
@@ -6,19 +6,11 @@ const DEFAULT_BACKOFF_FACTOR = 500; // ms
|
|
|
6
6
|
const DEFAULT_RETRYABLE_STATUSES = new Set([408, 409, 425, 429, 500, 502, 503, 504]);
|
|
7
7
|
/**
|
|
8
8
|
* Field aliases for normalizing optional field names.
|
|
9
|
-
* Only includes the
|
|
9
|
+
* Only includes the 3 optional fields from the OpenAPI spec.
|
|
10
10
|
*/
|
|
11
11
|
const FIELD_ALIASES = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
fillpriority: "fill_priority",
|
|
15
|
-
fill_priority: "fill_priority",
|
|
16
|
-
minintent: "min_intent",
|
|
17
|
-
min_intent: "min_intent",
|
|
18
|
-
skipmessageanalysis: "skip_message_analysis",
|
|
19
|
-
skip_message_analysis: "skip_message_analysis",
|
|
20
|
-
maxoffers: "max_offers",
|
|
21
|
-
max_offers: "max_offers",
|
|
12
|
+
fillpriority: "quality",
|
|
13
|
+
quality: "quality",
|
|
22
14
|
};
|
|
23
15
|
export class ChatAdsClient {
|
|
24
16
|
constructor(options) {
|
|
@@ -76,7 +68,7 @@ export class ChatAdsClient {
|
|
|
76
68
|
});
|
|
77
69
|
const parsed = await parseResponse(response);
|
|
78
70
|
const httpError = !response.ok;
|
|
79
|
-
const logicalError = this.raiseOnFailure && parsed.
|
|
71
|
+
const logicalError = this.raiseOnFailure && parsed.error != null;
|
|
80
72
|
if (!httpError && !logicalError) {
|
|
81
73
|
clearTimeout(timer);
|
|
82
74
|
return parsed;
|
|
@@ -181,7 +173,21 @@ function normalizeOptionalFields(data) {
|
|
|
181
173
|
async function parseResponse(response) {
|
|
182
174
|
const text = await response.text();
|
|
183
175
|
try {
|
|
184
|
-
|
|
176
|
+
const raw = text ? JSON.parse(text) : {};
|
|
177
|
+
// Normalize null/undefined to empty defaults so devs don't need null checks
|
|
178
|
+
const data = raw.data ?? { offers: [], requested: 0, returned: 0 };
|
|
179
|
+
return {
|
|
180
|
+
data: {
|
|
181
|
+
status: data.status,
|
|
182
|
+
offers: data.offers ?? [],
|
|
183
|
+
requested: data.requested ?? 0,
|
|
184
|
+
returned: data.returned ?? 0,
|
|
185
|
+
extraction_source: data.extraction_source,
|
|
186
|
+
extraction_debug: data.extraction_debug,
|
|
187
|
+
},
|
|
188
|
+
error: raw.error,
|
|
189
|
+
meta: raw.meta ?? { request_id: "unknown" },
|
|
190
|
+
};
|
|
185
191
|
}
|
|
186
192
|
catch (error) {
|
|
187
193
|
throw new ChatAdsSDKError("Failed to parse ChatAds response as JSON", error);
|
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,
|
|
4
|
+
export type { ChatAdsResponseEnvelope, Offer, Product, AnalyzeData, ChatAdsError, ChatAdsMeta, UsageInfo, FunctionItemPayload, FunctionItemOptionalFields, Quality, ConfidenceLevel, ResponseStatus, ResolutionSource, } from "./models.js";
|
package/dist/models.d.ts
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
export type
|
|
6
|
-
export type UrlSource = "demo" | "serper" | "amazon_paapi" | "cache";
|
|
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
|
+
/** Top-level response status indicating the outcome of the request */
|
|
5
|
+
export type ResponseStatus = "filled" | "partial_fill" | "no_offers_found" | "internal_error";
|
|
7
6
|
/**
|
|
8
7
|
* Optional fields for ChatAds API requests.
|
|
9
|
-
* Only these
|
|
8
|
+
* Only these 3 optional fields are supported (plus required `message`).
|
|
10
9
|
*/
|
|
11
10
|
export type FunctionItemOptionalFields = {
|
|
12
11
|
/** Client IP address for geo-detection (max 45 characters) */
|
|
13
12
|
ip?: string;
|
|
14
13
|
/** ISO 3166-1 alpha-2 country code for geo-targeting */
|
|
15
14
|
country?: string;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/** URL resolution fallback behavior. Default: "coverage" */
|
|
19
|
-
fill_priority?: FillPriority;
|
|
20
|
-
/** Minimum purchase intent level. Default: "low" */
|
|
21
|
-
min_intent?: MinIntent;
|
|
22
|
-
/** Skip NLP/LLM extraction and use message directly as search query. Default: false */
|
|
23
|
-
skip_message_analysis?: boolean;
|
|
24
|
-
/** Maximum number of affiliate offers to return (1-2). Default: 1 */
|
|
25
|
-
max_offers?: number;
|
|
15
|
+
/** Resolution quality level. Default: "standard" */
|
|
16
|
+
quality?: Quality;
|
|
26
17
|
};
|
|
27
18
|
export type FunctionItemPayload = {
|
|
28
19
|
message: string;
|
|
@@ -33,51 +24,52 @@ export type FunctionItemPayload = {
|
|
|
33
24
|
*/
|
|
34
25
|
export interface Product {
|
|
35
26
|
/** Product title from search result */
|
|
36
|
-
|
|
27
|
+
title?: string;
|
|
37
28
|
/** Product description/snippet from search result */
|
|
38
|
-
|
|
29
|
+
description?: string;
|
|
30
|
+
/** Product rating (e.g., 4.5 out of 5) */
|
|
31
|
+
stars?: number;
|
|
32
|
+
/** Number of product reviews */
|
|
33
|
+
reviews?: number;
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
36
|
* Single affiliate offer returned by the API.
|
|
37
|
+
* If an offer is in the array, it is guaranteed to have a URL.
|
|
42
38
|
*/
|
|
43
39
|
export interface Offer {
|
|
44
40
|
/** Text to use for the affiliate link */
|
|
45
|
-
|
|
46
|
-
/** Product search term used */
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
/** Affiliate URL */
|
|
53
|
-
|
|
54
|
-
/** Source of the URL (e.g., amazon, serper) */
|
|
55
|
-
|
|
56
|
-
/** Offer status */
|
|
57
|
-
Status: OfferStatus;
|
|
58
|
-
/** Reason for status (e.g., failure reason) */
|
|
59
|
-
Reason?: string;
|
|
41
|
+
link_text: string;
|
|
42
|
+
/** Product search term used (verbose mode only) */
|
|
43
|
+
search_term?: string;
|
|
44
|
+
/** Confidence score (0.0-1.0) (verbose mode only) */
|
|
45
|
+
confidence_score?: number | null;
|
|
46
|
+
/** Confidence level classification */
|
|
47
|
+
confidence_level: string;
|
|
48
|
+
/** Affiliate URL (always populated) */
|
|
49
|
+
url: string;
|
|
50
|
+
/** Source of the URL resolution (e.g., amazon, serper, vector) (verbose mode only) */
|
|
51
|
+
resolution_source?: string;
|
|
60
52
|
/** Detected product category */
|
|
61
|
-
|
|
53
|
+
category?: string;
|
|
62
54
|
/** Product metadata from resolution */
|
|
63
|
-
|
|
55
|
+
product?: Product;
|
|
64
56
|
}
|
|
65
57
|
/**
|
|
66
58
|
* Response data containing affiliate offers.
|
|
67
59
|
*/
|
|
68
60
|
export interface AnalyzeData {
|
|
69
|
-
/**
|
|
70
|
-
|
|
61
|
+
/** Status of the request - single source of truth for outcome */
|
|
62
|
+
status: ResponseStatus;
|
|
63
|
+
/** Array of affiliate offers (only contains filled offers with URLs, never null) */
|
|
64
|
+
offers: Offer[];
|
|
71
65
|
/** Number of offers requested */
|
|
72
|
-
|
|
73
|
-
/** Number of offers returned */
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
/** Affiliate URL lookup timing */
|
|
80
|
-
LookupMs?: number;
|
|
66
|
+
requested: number;
|
|
67
|
+
/** Number of offers returned (equals len(Offers)) */
|
|
68
|
+
returned: number;
|
|
69
|
+
/** Extraction source ("nlp", "groq_vector", "groq_resolved") (verbose mode only) */
|
|
70
|
+
extraction_source?: string;
|
|
71
|
+
/** Extraction debug information (verbose mode only) */
|
|
72
|
+
extraction_debug?: unknown[];
|
|
81
73
|
}
|
|
82
74
|
export interface ChatAdsError {
|
|
83
75
|
code: string;
|
|
@@ -102,14 +94,13 @@ export interface ChatAdsMeta {
|
|
|
102
94
|
[key: string]: unknown;
|
|
103
95
|
}
|
|
104
96
|
export interface ChatAdsResponseEnvelope {
|
|
105
|
-
|
|
106
|
-
data?: AnalyzeData | null;
|
|
97
|
+
data: AnalyzeData;
|
|
107
98
|
error?: ChatAdsError | null;
|
|
108
99
|
meta: ChatAdsMeta;
|
|
109
100
|
[key: string]: unknown;
|
|
110
101
|
}
|
|
111
102
|
/**
|
|
112
103
|
* Reserved payload keys that cannot be used in extraFields.
|
|
113
|
-
* These are the
|
|
104
|
+
* These are the 4 allowed request fields per the OpenAPI spec.
|
|
114
105
|
*/
|
|
115
106
|
export declare const RESERVED_PAYLOAD_KEYS: ReadonlySet<string>;
|
package/dist/models.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reserved payload keys that cannot be used in extraFields.
|
|
3
|
-
* These are the
|
|
3
|
+
* These are the 4 allowed request fields per the OpenAPI spec.
|
|
4
4
|
*/
|
|
5
5
|
export const RESERVED_PAYLOAD_KEYS = new Set([
|
|
6
6
|
"message",
|
|
7
7
|
"ip",
|
|
8
8
|
"country",
|
|
9
|
-
"
|
|
10
|
-
"fill_priority",
|
|
11
|
-
"min_intent",
|
|
12
|
-
"skip_message_analysis",
|
|
13
|
-
"max_offers",
|
|
9
|
+
"quality",
|
|
14
10
|
]);
|