@chat-ads/chatads-sdk 0.1.6 → 0.1.8
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 +16 -20
- package/dist/client.js +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/models.d.ts +61 -25
- package/dist/models.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ import { ChatAdsClient } from "@chat-ads/chatads-sdk";
|
|
|
19
19
|
|
|
20
20
|
const client = new ChatAdsClient({
|
|
21
21
|
apiKey: process.env.CHATADS_API_KEY!,
|
|
22
|
-
baseUrl: "https://
|
|
22
|
+
baseUrl: "https://api.getchatads.com",
|
|
23
23
|
maxRetries: 2,
|
|
24
24
|
raiseOnFailure: true,
|
|
25
25
|
});
|
|
@@ -29,8 +29,8 @@ const response = await client.analyze({
|
|
|
29
29
|
ip: "8.8.8.8",
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
if (response.success && response.data?.
|
|
33
|
-
console.log(response.data.
|
|
32
|
+
if (response.success && response.data?.Offers.length) {
|
|
33
|
+
console.log(response.data.Offers[0]);
|
|
34
34
|
} else {
|
|
35
35
|
console.error(response.error);
|
|
36
36
|
}
|
|
@@ -90,26 +90,22 @@ try {
|
|
|
90
90
|
{
|
|
91
91
|
"success": true,
|
|
92
92
|
"data": {
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"
|
|
103
|
-
"
|
|
93
|
+
"Offers": [
|
|
94
|
+
{
|
|
95
|
+
"LinkText": "CRM tools",
|
|
96
|
+
"IntentLevel": "high",
|
|
97
|
+
"URL": "https://amazon.com/dp/example?tag=chatads-20",
|
|
98
|
+
"Status": "filled",
|
|
99
|
+
"Category": "Software"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"Requested": 1,
|
|
103
|
+
"Returned": 1
|
|
104
104
|
},
|
|
105
105
|
"error": null,
|
|
106
106
|
"meta": {
|
|
107
107
|
"request_id": "req_123",
|
|
108
|
-
"
|
|
109
|
-
"message_analysis_used": "thorough",
|
|
110
|
-
"fill_priority_used": "coverage",
|
|
111
|
-
"min_intent_used": "low",
|
|
112
|
-
"processing_time_ms": 42.3,
|
|
108
|
+
"country": "US",
|
|
113
109
|
"usage": {
|
|
114
110
|
"monthly_requests": 120,
|
|
115
111
|
"free_tier_limit": 1000,
|
|
@@ -128,7 +124,7 @@ TypeScript projects can import `ChatAdsResponseEnvelope` and related interfaces
|
|
|
128
124
|
|
|
129
125
|
```bash
|
|
130
126
|
npm run build
|
|
131
|
-
CHATADS_API_KEY=... CHATADS_BASE_URL=https://
|
|
127
|
+
CHATADS_API_KEY=... CHATADS_BASE_URL=https://api.getchatads.com \
|
|
132
128
|
node dist/examples/basic.js
|
|
133
129
|
```
|
|
134
130
|
|
package/dist/client.js
CHANGED
|
@@ -6,7 +6,7 @@ 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 7 optional fields from the OpenAPI spec.
|
|
10
10
|
*/
|
|
11
11
|
const FIELD_ALIASES = {
|
|
12
12
|
messageanalysis: "message_analysis",
|
|
@@ -17,6 +17,8 @@ const FIELD_ALIASES = {
|
|
|
17
17
|
min_intent: "min_intent",
|
|
18
18
|
skipmessageanalysis: "skip_message_analysis",
|
|
19
19
|
skip_message_analysis: "skip_message_analysis",
|
|
20
|
+
maxoffers: "max_offers",
|
|
21
|
+
max_offers: "max_offers",
|
|
20
22
|
};
|
|
21
23
|
export class ChatAdsClient {
|
|
22
24
|
constructor(options) {
|
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,
|
|
4
|
+
export type { ChatAdsResponseEnvelope, Offer, Product, AnalyzeData, ChatAdsError, ChatAdsMeta, UsageInfo, FunctionItemPayload, FunctionItemOptionalFields, MessageAnalysis, FillPriority, MinIntent, IntentLevel, OfferStatus, UrlSource, } from "./models.js";
|
package/dist/models.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export type MessageAnalysis = "fast" | "thorough";
|
|
2
2
|
export type FillPriority = "speed" | "coverage";
|
|
3
3
|
export type MinIntent = "any" | "low" | "medium" | "high";
|
|
4
|
+
export type IntentLevel = "high" | "medium" | "low" | "very_low";
|
|
5
|
+
export type OfferStatus = "filled" | "scored" | "failed";
|
|
6
|
+
export type UrlSource = "demo" | "serper" | "amazon_paapi" | "cache";
|
|
4
7
|
/**
|
|
5
8
|
* Optional fields for ChatAds API requests.
|
|
6
|
-
* Only these
|
|
9
|
+
* Only these 7 optional fields are supported (plus required `message`).
|
|
7
10
|
*/
|
|
8
11
|
export type FunctionItemOptionalFields = {
|
|
9
|
-
/** Client IP address for geo-detection (max
|
|
12
|
+
/** Client IP address for geo-detection (max 45 characters) */
|
|
10
13
|
ip?: string;
|
|
11
14
|
/** ISO 3166-1 alpha-2 country code for geo-targeting */
|
|
12
15
|
country?: string;
|
|
@@ -18,26 +21,63 @@ export type FunctionItemOptionalFields = {
|
|
|
18
21
|
min_intent?: MinIntent;
|
|
19
22
|
/** Skip NLP/LLM extraction and use message directly as search query. Default: false */
|
|
20
23
|
skip_message_analysis?: boolean;
|
|
24
|
+
/** Maximum number of affiliate offers to return (1-2). Default: 1 */
|
|
25
|
+
max_offers?: number;
|
|
21
26
|
};
|
|
22
27
|
export type FunctionItemPayload = {
|
|
23
28
|
message: string;
|
|
24
29
|
extraFields?: Record<string, unknown>;
|
|
25
30
|
} & FunctionItemOptionalFields;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Product metadata from resolution.
|
|
33
|
+
*/
|
|
34
|
+
export interface Product {
|
|
35
|
+
/** Product title from search result */
|
|
36
|
+
Title?: string;
|
|
37
|
+
/** Product description/snippet from search result */
|
|
38
|
+
Description?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Single affiliate offer returned by the API.
|
|
42
|
+
*/
|
|
43
|
+
export interface Offer {
|
|
44
|
+
/** Text to use for the affiliate link */
|
|
45
|
+
LinkText: string;
|
|
46
|
+
/** Product search term used */
|
|
47
|
+
SearchTerm?: string;
|
|
48
|
+
/** Intent score (0.0-1.0) */
|
|
49
|
+
IntentScore?: number | null;
|
|
50
|
+
/** Intent level classification */
|
|
51
|
+
IntentLevel: string;
|
|
52
|
+
/** Affiliate URL */
|
|
53
|
+
URL: string;
|
|
54
|
+
/** Source of the URL (e.g., amazon, serper) */
|
|
55
|
+
URLSource?: string;
|
|
56
|
+
/** Offer status */
|
|
57
|
+
Status: OfferStatus;
|
|
58
|
+
/** Reason for status (e.g., failure reason) */
|
|
59
|
+
Reason?: string;
|
|
60
|
+
/** Detected product category */
|
|
61
|
+
Category?: string;
|
|
62
|
+
/** Product metadata from resolution */
|
|
63
|
+
Product?: Product;
|
|
31
64
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Response data containing affiliate offers.
|
|
67
|
+
*/
|
|
68
|
+
export interface AnalyzeData {
|
|
69
|
+
/** Array of affiliate offers */
|
|
70
|
+
Offers: Offer[];
|
|
71
|
+
/** Number of offers requested */
|
|
72
|
+
Requested: number;
|
|
73
|
+
/** Number of offers returned */
|
|
74
|
+
Returned: number;
|
|
75
|
+
/** Total processing latency in milliseconds */
|
|
76
|
+
LatencyMs?: number;
|
|
77
|
+
/** LLM extraction step timing */
|
|
78
|
+
ExtractionMs?: number;
|
|
79
|
+
/** Affiliate URL lookup timing */
|
|
80
|
+
LookupMs?: number;
|
|
41
81
|
}
|
|
42
82
|
export interface ChatAdsError {
|
|
43
83
|
code: string;
|
|
@@ -54,26 +94,22 @@ export interface UsageInfo {
|
|
|
54
94
|
}
|
|
55
95
|
export interface ChatAdsMeta {
|
|
56
96
|
request_id: string;
|
|
57
|
-
|
|
97
|
+
timestamp?: string;
|
|
98
|
+
version?: string;
|
|
58
99
|
country?: string | null;
|
|
59
|
-
language?: string | null;
|
|
60
|
-
extraction_method?: "llm" | "nlp" | "skip" | null;
|
|
61
|
-
message_analysis_used?: "fast" | "thorough" | "skip" | null;
|
|
62
|
-
fill_priority_used?: "speed" | "coverage" | "skip" | null;
|
|
63
|
-
min_intent_used?: "any" | "low" | "medium" | "high" | null;
|
|
64
|
-
processing_time_ms?: number | null;
|
|
65
100
|
usage?: UsageInfo | null;
|
|
101
|
+
timing_ms?: Record<string, number>;
|
|
66
102
|
[key: string]: unknown;
|
|
67
103
|
}
|
|
68
104
|
export interface ChatAdsResponseEnvelope {
|
|
69
105
|
success: boolean;
|
|
70
|
-
data?:
|
|
106
|
+
data?: AnalyzeData | null;
|
|
71
107
|
error?: ChatAdsError | null;
|
|
72
108
|
meta: ChatAdsMeta;
|
|
73
109
|
[key: string]: unknown;
|
|
74
110
|
}
|
|
75
111
|
/**
|
|
76
112
|
* Reserved payload keys that cannot be used in extraFields.
|
|
77
|
-
* These are the
|
|
113
|
+
* These are the 8 allowed request fields per the OpenAPI spec.
|
|
78
114
|
*/
|
|
79
115
|
export declare const RESERVED_PAYLOAD_KEYS: ReadonlySet<string>;
|
package/dist/models.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reserved payload keys that cannot be used in extraFields.
|
|
3
|
-
* These are the
|
|
3
|
+
* These are the 8 allowed request fields per the OpenAPI spec.
|
|
4
4
|
*/
|
|
5
5
|
export const RESERVED_PAYLOAD_KEYS = new Set([
|
|
6
6
|
"message",
|
|
@@ -10,4 +10,5 @@ export const RESERVED_PAYLOAD_KEYS = new Set([
|
|
|
10
10
|
"fill_priority",
|
|
11
11
|
"min_intent",
|
|
12
12
|
"skip_message_analysis",
|
|
13
|
+
"max_offers",
|
|
13
14
|
]);
|