@gravity-ai/api 1.4.0 → 1.6.0
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 +45 -0
- package/dist/index.d.mts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +515 -46
- package/dist/index.mjs +510 -46
- package/dist/opentui.js +1 -1
- package/dist/opentui.mjs +1 -1
- package/dist/{types-C20oXLJd.d.mts → types-DlHD2n-z.d.mts} +351 -5
- package/dist/{types-C20oXLJd.d.ts → types-DlHD2n-z.d.ts} +351 -5
- package/package.json +1 -1
|
@@ -1,3 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript definitions for the Gravity Index search APIs.
|
|
3
|
+
*/
|
|
4
|
+
type IndexVertical = 'auto' | 'developer' | 'consumer';
|
|
5
|
+
type IndexGender = 'men' | 'women' | 'kids';
|
|
6
|
+
interface IndexMonetization {
|
|
7
|
+
/**
|
|
8
|
+
* 0 = sponsored only, 1 = highest relevance. Overrides saved dashboard
|
|
9
|
+
* default for this request only. Omit or pass `null` to use saved default.
|
|
10
|
+
*/
|
|
11
|
+
relevance?: number | null;
|
|
12
|
+
/** Legacy mode control: `'boost_cpa'` or `'off'`. */
|
|
13
|
+
mode?: 'boost_cpa' | 'off' | (string & {});
|
|
14
|
+
}
|
|
15
|
+
interface IndexShopFilters {
|
|
16
|
+
price_min?: number;
|
|
17
|
+
price_max?: number;
|
|
18
|
+
currency?: string;
|
|
19
|
+
brands?: string[];
|
|
20
|
+
merchants?: string[];
|
|
21
|
+
colors?: string[];
|
|
22
|
+
sizes?: string[];
|
|
23
|
+
gender?: IndexGender;
|
|
24
|
+
categories?: string[];
|
|
25
|
+
on_sale_only?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface IndexContextMessage {
|
|
28
|
+
role: string;
|
|
29
|
+
content: string;
|
|
30
|
+
}
|
|
31
|
+
interface IndexSearchContext {
|
|
32
|
+
messages?: IndexContextMessage[];
|
|
33
|
+
style?: string;
|
|
34
|
+
vibe?: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/** Configuration for `GravityIndex`. */
|
|
38
|
+
interface GravityIndexOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Gravity publisher API key.
|
|
41
|
+
* Defaults to `process.env.GRAVITY_PUBLISHER_KEY || process.env.GRAVITY_API_KEY`.
|
|
42
|
+
*/
|
|
43
|
+
apiKey?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Base URL for the Gravity Index API.
|
|
46
|
+
* Defaults to `process.env.GRAVITY_INDEX_URL || 'https://index.trygravity.com'`.
|
|
47
|
+
*/
|
|
48
|
+
indexUrl?: string;
|
|
49
|
+
/** Request timeout in milliseconds. Defaults to `30000` (30s). */
|
|
50
|
+
timeoutMs?: number;
|
|
51
|
+
}
|
|
52
|
+
/** Per-call overrides for any `GravityIndex` method. */
|
|
53
|
+
interface IndexRequestOptions {
|
|
54
|
+
/** Override API key for this call. */
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
/** Override timeout in milliseconds for this call. */
|
|
57
|
+
timeoutMs?: number;
|
|
58
|
+
/** Optional caller AbortSignal combined with the request timeout. */
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
}
|
|
61
|
+
/** Envelope returned by all `GravityIndex` methods. Never throws. */
|
|
62
|
+
interface IndexResult<T> {
|
|
63
|
+
/** `true` when the HTTP request succeeded (2xx) and parsed cleanly. */
|
|
64
|
+
ok: boolean;
|
|
65
|
+
/** Parsed response payload, or `null` on error. */
|
|
66
|
+
data: T | null;
|
|
67
|
+
/** HTTP status code, or `0` on missing config, timeout, or network error. */
|
|
68
|
+
status: number;
|
|
69
|
+
/** Round-trip time in milliseconds (string, matching `GravityAdsResult.elapsed`). */
|
|
70
|
+
elapsed: string;
|
|
71
|
+
/** Human-readable error detail when `ok` is `false`. */
|
|
72
|
+
error?: string;
|
|
73
|
+
/** Parsed `Retry-After` header in seconds when present (e.g. HTTP 429). */
|
|
74
|
+
retryAfterSeconds?: number;
|
|
75
|
+
}
|
|
76
|
+
interface IndexMcpConnect {
|
|
77
|
+
type: 'mcp';
|
|
78
|
+
id: string;
|
|
79
|
+
server_url: string;
|
|
80
|
+
name: string;
|
|
81
|
+
icon_url: string | null;
|
|
82
|
+
cta: string | null;
|
|
83
|
+
headline: string | null;
|
|
84
|
+
body: string | null;
|
|
85
|
+
connect_line: string | null;
|
|
86
|
+
authorize_params: {
|
|
87
|
+
utm_source: string;
|
|
88
|
+
utm_medium: string;
|
|
89
|
+
utm_campaign: string;
|
|
90
|
+
grclid?: string;
|
|
91
|
+
[key: string]: string | undefined;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
interface IndexMppCheckout {
|
|
95
|
+
protocol: 'mpp';
|
|
96
|
+
endpoint: string;
|
|
97
|
+
network_id: string | null;
|
|
98
|
+
attribution: {
|
|
99
|
+
click_id_tag: string;
|
|
100
|
+
click_id_value: string;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
interface IndexUcpCheckout {
|
|
104
|
+
protocol: 'ucp';
|
|
105
|
+
endpoint: string;
|
|
106
|
+
continue_url: string | null;
|
|
107
|
+
item_id: string;
|
|
108
|
+
agent_profile: string;
|
|
109
|
+
attribution: {
|
|
110
|
+
referring_domain: string;
|
|
111
|
+
click_id_tag: string;
|
|
112
|
+
click_id_value: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
interface IndexInstallStep {
|
|
116
|
+
step?: number;
|
|
117
|
+
action?: string;
|
|
118
|
+
command?: string;
|
|
119
|
+
file?: string;
|
|
120
|
+
code?: string;
|
|
121
|
+
user_action?: string;
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
}
|
|
124
|
+
interface IndexInstallInstructions {
|
|
125
|
+
summary?: string;
|
|
126
|
+
steps?: IndexInstallStep[];
|
|
127
|
+
env_vars?: string[];
|
|
128
|
+
notes?: string;
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
131
|
+
interface IndexCredentialRequest {
|
|
132
|
+
setup_url: string;
|
|
133
|
+
grclid: string | null;
|
|
134
|
+
required_env_vars: string[];
|
|
135
|
+
user_message: string;
|
|
136
|
+
agent_instruction: string;
|
|
137
|
+
}
|
|
138
|
+
interface IndexRecommendation {
|
|
139
|
+
service_id: string | null;
|
|
140
|
+
slug: string;
|
|
141
|
+
name: string;
|
|
142
|
+
category: string;
|
|
143
|
+
description: string | null;
|
|
144
|
+
website_url: string | null;
|
|
145
|
+
docs_url: string | null;
|
|
146
|
+
click_url: string | null;
|
|
147
|
+
grclid: string | null;
|
|
148
|
+
checkout: IndexMppCheckout | null;
|
|
149
|
+
sponsored: boolean;
|
|
150
|
+
connect: IndexMcpConnect | null;
|
|
151
|
+
}
|
|
152
|
+
interface IndexSearchOption {
|
|
153
|
+
service_id: string | null;
|
|
154
|
+
slug: string;
|
|
155
|
+
name: string;
|
|
156
|
+
category: string;
|
|
157
|
+
description: string | null;
|
|
158
|
+
website_url: string | null;
|
|
159
|
+
docs_url: string | null;
|
|
160
|
+
best_for: string | null;
|
|
161
|
+
tradeoff: string | null;
|
|
162
|
+
click_url: string | null;
|
|
163
|
+
grclid: string | null;
|
|
164
|
+
sponsored?: boolean;
|
|
165
|
+
connect?: IndexMcpConnect | null;
|
|
166
|
+
}
|
|
167
|
+
interface IndexAlternative {
|
|
168
|
+
slug: string;
|
|
169
|
+
reason?: string;
|
|
170
|
+
[key: string]: unknown;
|
|
171
|
+
}
|
|
172
|
+
interface IndexSearchParams {
|
|
173
|
+
/** Natural-language need (up to 1,000 chars). Optional if `context.messages` is set. */
|
|
174
|
+
query?: string;
|
|
175
|
+
/**
|
|
176
|
+
* End user's IPv4/IPv6 address, or `'caller'` when running on the user's device.
|
|
177
|
+
* Hosted servers should always pass the real end-user IP for CPM payouts and
|
|
178
|
+
* geo targeting. Falls back to `process.env.GRAVITY_INDEX_USER_IP`, else `'caller'`.
|
|
179
|
+
*/
|
|
180
|
+
user_ip?: string;
|
|
181
|
+
/** Optional ISO 3166-1 alpha-2 country code fallback. */
|
|
182
|
+
country?: string;
|
|
183
|
+
/** End user's browser or client user agent (automatically capped at 1,024 chars). */
|
|
184
|
+
user_agent?: string;
|
|
185
|
+
/** Previous `search_id` UUID for follow-up questions. */
|
|
186
|
+
search_id?: string;
|
|
187
|
+
/** Project/stack context or `messages` transcript. */
|
|
188
|
+
context?: IndexSearchContext;
|
|
189
|
+
/** Upper limit for `options` (1-10, default 5). */
|
|
190
|
+
max_options?: number;
|
|
191
|
+
/** Catalog selection: `'auto'` (default), `'developer'`, or `'consumer'`. */
|
|
192
|
+
vertical?: IndexVertical;
|
|
193
|
+
/** Consumer catalog filters (implies consumer search when supplied). */
|
|
194
|
+
filters?: IndexShopFilters;
|
|
195
|
+
/** Stable conversation/session ID (up to 256 chars). */
|
|
196
|
+
session_id?: string;
|
|
197
|
+
/** Legacy alias for `session_id`. */
|
|
198
|
+
external_session_id?: string;
|
|
199
|
+
/** Raw user ID (stored only as SHA-256 hash). */
|
|
200
|
+
external_user_id?: string;
|
|
201
|
+
/** Pre-hashed user ID. */
|
|
202
|
+
external_user_id_hash?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Raw user email. Trimmed, lowercased, and SHA-256 hashed client-side into
|
|
205
|
+
* `hashed_email`; never sent raw over the wire. Ignored when `hashed_email`
|
|
206
|
+
* is already provided.
|
|
207
|
+
*/
|
|
208
|
+
email?: string;
|
|
209
|
+
/** SHA-256 hex hash of normalized email. Takes precedence over `email`. */
|
|
210
|
+
hashed_email?: string;
|
|
211
|
+
/** Legacy alias for `hashed_email`. */
|
|
212
|
+
email_hash?: string;
|
|
213
|
+
/** SHA-256 hex hash of digits-only phone number. */
|
|
214
|
+
phone_hash?: string;
|
|
215
|
+
/** Non-sensitive publisher metadata (max 20,000 chars serialized JSON). */
|
|
216
|
+
metadata?: Record<string, unknown>;
|
|
217
|
+
/** Optional relevance / sponsorship balance controls. */
|
|
218
|
+
monetization?: IndexMonetization;
|
|
219
|
+
}
|
|
220
|
+
interface IndexDeveloperSearchResponse {
|
|
221
|
+
api_version: string;
|
|
222
|
+
vertical: 'developer';
|
|
223
|
+
search_id: string;
|
|
224
|
+
query: string;
|
|
225
|
+
recommendation: IndexRecommendation | null;
|
|
226
|
+
options: IndexSearchOption[];
|
|
227
|
+
reasoning: string;
|
|
228
|
+
install: IndexInstallInstructions | null;
|
|
229
|
+
install_v2?: Record<string, unknown> | null;
|
|
230
|
+
credential_request: IndexCredentialRequest | null;
|
|
231
|
+
click_url: string | null;
|
|
232
|
+
grclid: string | null;
|
|
233
|
+
alternatives: IndexAlternative[];
|
|
234
|
+
unmatched_slug: string | null;
|
|
235
|
+
}
|
|
236
|
+
interface IndexShopSearchParams extends IndexShopFilters {
|
|
237
|
+
/** Product description (up to 1,000 chars). Optional if `context.messages` is set. */
|
|
238
|
+
query?: string;
|
|
239
|
+
/** Optional hints (`style` / `vibe`, `messages`). */
|
|
240
|
+
context?: IndexSearchContext;
|
|
241
|
+
/** Number of products to return (1-25, default 5). */
|
|
242
|
+
max_results?: number;
|
|
243
|
+
/** Whether to run LLM reranking (default `true`). */
|
|
244
|
+
rerank?: boolean;
|
|
245
|
+
/** Stable session ID (up to 200 chars). */
|
|
246
|
+
session_id?: string;
|
|
247
|
+
/** Legacy alias for `session_id`. */
|
|
248
|
+
external_session_id?: string;
|
|
249
|
+
/** Raw user ID (stored only as SHA-256 hash). */
|
|
250
|
+
external_user_id?: string;
|
|
251
|
+
/** Pre-hashed user ID. */
|
|
252
|
+
external_user_id_hash?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Raw user email. Trimmed, lowercased, and SHA-256 hashed client-side into
|
|
255
|
+
* `hashed_email`; never sent raw over the wire. Ignored when `hashed_email`
|
|
256
|
+
* is already provided.
|
|
257
|
+
*/
|
|
258
|
+
email?: string;
|
|
259
|
+
/** SHA-256 hex hash of normalized email. Takes precedence over `email`. */
|
|
260
|
+
hashed_email?: string;
|
|
261
|
+
/** Legacy alias for `hashed_email`. */
|
|
262
|
+
email_hash?: string;
|
|
263
|
+
/** SHA-256 hex hash of digits-only phone number. */
|
|
264
|
+
phone_hash?: string;
|
|
265
|
+
/**
|
|
266
|
+
* End user's IPv4/IPv6 address, or `'caller'` when running on the user's device.
|
|
267
|
+
* Hosted servers should always pass the real end-user IP for CPM payouts and
|
|
268
|
+
* geo targeting. Falls back to `process.env.GRAVITY_INDEX_USER_IP`, else `'caller'`.
|
|
269
|
+
*/
|
|
270
|
+
user_ip?: string;
|
|
271
|
+
/** End user's browser or client user agent (automatically capped at 1,024 chars). */
|
|
272
|
+
user_agent?: string;
|
|
273
|
+
/** Non-sensitive publisher metadata (max 20,000 chars serialized JSON). */
|
|
274
|
+
metadata?: Record<string, unknown>;
|
|
275
|
+
}
|
|
276
|
+
interface IndexProduct {
|
|
277
|
+
product_id: string;
|
|
278
|
+
name: string;
|
|
279
|
+
brand: string | null;
|
|
280
|
+
merchant: string | null;
|
|
281
|
+
category: string | null;
|
|
282
|
+
description: string | null;
|
|
283
|
+
currency: string;
|
|
284
|
+
price: number | null;
|
|
285
|
+
regular_price: number | null;
|
|
286
|
+
on_sale: boolean;
|
|
287
|
+
image_url: string | null;
|
|
288
|
+
click_url: string;
|
|
289
|
+
grclid: string | null;
|
|
290
|
+
checkout: IndexUcpCheckout | null;
|
|
291
|
+
}
|
|
292
|
+
interface IndexWebResult {
|
|
293
|
+
name: string;
|
|
294
|
+
brand: string | null;
|
|
295
|
+
price: number | null;
|
|
296
|
+
currency: string | null;
|
|
297
|
+
description: string | null;
|
|
298
|
+
image_url: string | null;
|
|
299
|
+
url: string;
|
|
300
|
+
site: string;
|
|
301
|
+
}
|
|
302
|
+
interface IndexPriceRange {
|
|
303
|
+
min: number;
|
|
304
|
+
max: number;
|
|
305
|
+
}
|
|
306
|
+
interface IndexShopFacets {
|
|
307
|
+
brands: string[];
|
|
308
|
+
merchants: string[];
|
|
309
|
+
categories: string[];
|
|
310
|
+
price_range: IndexPriceRange | null;
|
|
311
|
+
}
|
|
312
|
+
interface IndexShopSearchResponse {
|
|
313
|
+
api_version: string;
|
|
314
|
+
vertical: 'consumer';
|
|
315
|
+
search_id: string;
|
|
316
|
+
query: string;
|
|
317
|
+
recommendation: IndexProduct | null;
|
|
318
|
+
reasoning: string;
|
|
319
|
+
products: IndexProduct[];
|
|
320
|
+
count: number;
|
|
321
|
+
web_results: IndexWebResult[];
|
|
322
|
+
ranking: string;
|
|
323
|
+
facets: IndexShopFacets;
|
|
324
|
+
disclosure?: string;
|
|
325
|
+
}
|
|
326
|
+
type IndexSearchResponse = IndexDeveloperSearchResponse | IndexShopSearchResponse;
|
|
327
|
+
|
|
1
328
|
/**
|
|
2
329
|
* Data-drawn ad units (contract: units v1).
|
|
3
330
|
*
|
|
@@ -668,14 +995,21 @@ interface GravityContextOverrides {
|
|
|
668
995
|
device?: Record<string, unknown>;
|
|
669
996
|
/**
|
|
670
997
|
* Explicit consent signal. When omitted in a browser, the SDK reads the
|
|
671
|
-
* page's IAB CMP APIs (`__tcfapi` / `__uspapi`) and
|
|
672
|
-
*
|
|
673
|
-
*
|
|
998
|
+
* page's IAB CMP APIs (`__tcfapi` / `__uspapi` / `__gpp`) and
|
|
999
|
+
* `navigator.globalPrivacyControl`, and attaches the settled decision
|
|
1000
|
+
* automatically. Pass this to override (it replaces the detected object
|
|
1001
|
+
* as a whole), or in server-side runtimes where no CMP is readable.
|
|
674
1002
|
*/
|
|
675
1003
|
consent?: {
|
|
676
1004
|
gdprApplies?: boolean;
|
|
677
1005
|
tcfString?: string;
|
|
678
1006
|
usPrivacy?: string;
|
|
1007
|
+
/** IAB GPP string. */
|
|
1008
|
+
gpp?: string;
|
|
1009
|
+
/** GPP section ids that apply to this request. */
|
|
1010
|
+
gppSid?: number[];
|
|
1011
|
+
/** Global Privacy Control. Send only `true`. */
|
|
1012
|
+
gpc?: boolean;
|
|
679
1013
|
};
|
|
680
1014
|
}
|
|
681
1015
|
/** The context object returned by `gravityContext()` and sent in the request body. */
|
|
@@ -687,13 +1021,20 @@ interface GravityContext {
|
|
|
687
1021
|
device: Record<string, unknown>;
|
|
688
1022
|
/**
|
|
689
1023
|
* End-user privacy/consent signal. Auto-detected from the page's CMP
|
|
690
|
-
* (`window.__tcfapi` / `window.__uspapi`
|
|
1024
|
+
* (`window.__tcfapi` / `window.__uspapi` / `window.__gpp`) and from
|
|
1025
|
+
* `navigator.globalPrivacyControl` in browsers; callers can
|
|
691
1026
|
* override via `GravityContextOverrides.consent`.
|
|
692
1027
|
*/
|
|
693
1028
|
consent?: {
|
|
694
1029
|
gdprApplies?: boolean;
|
|
695
1030
|
tcfString?: string;
|
|
696
1031
|
usPrivacy?: string;
|
|
1032
|
+
/** IAB GPP string. */
|
|
1033
|
+
gpp?: string;
|
|
1034
|
+
/** GPP section ids that apply to this request. */
|
|
1035
|
+
gppSid?: number[];
|
|
1036
|
+
/** Global Privacy Control. Send only `true`. */
|
|
1037
|
+
gpc?: boolean;
|
|
697
1038
|
};
|
|
698
1039
|
}
|
|
699
1040
|
/** Options for `gravityAds()`. */
|
|
@@ -746,6 +1087,11 @@ interface GravityAdsOptions {
|
|
|
746
1087
|
/** @deprecated See {@link AdParams.adLayout}. */
|
|
747
1088
|
adLayout?: AdLayout;
|
|
748
1089
|
}
|
|
1090
|
+
/** Configuration for `new Gravity(opts)`, covering both ad serving and Gravity Index. */
|
|
1091
|
+
interface GravityOptions extends GravityAdsOptions {
|
|
1092
|
+
/** Optional Gravity Index configuration applied to `gravity.index`. */
|
|
1093
|
+
index?: GravityIndexOptions;
|
|
1094
|
+
}
|
|
749
1095
|
/** Result returned by `gravityAds()`. Never throws. */
|
|
750
1096
|
interface GravityAdsResult {
|
|
751
1097
|
/** Matched ads (empty array on failure or no-fill). */
|
|
@@ -778,4 +1124,4 @@ interface IncomingAdRequest {
|
|
|
778
1124
|
ip?: string;
|
|
779
1125
|
}
|
|
780
1126
|
|
|
781
|
-
export type { AdParams as A, DeviceObject as D, FrameSize as F,
|
|
1127
|
+
export type { Placement as $, AdParams as A, IndexMppCheckout as B, IndexPriceRange as C, DeviceObject as D, IndexProduct as E, FrameSize as F, GravityIndexOptions as G, HostTheme as H, IndexSearchParams as I, IndexRecommendation as J, IndexSearchContext as K, IndexSearchOption as L, MessageObject as M, IndexShopFacets as N, IndexShopFilters as O, PlacementObject as P, IndexUcpCheckout as Q, IndexVertical as R, IndexWebResult as S, LeadFormConfig as T, LeadFormField as U, LeadFormPrefill as V, McpConnect as W, McpConnectHandler as X, McpConnectRequest as Y, McpConnectResult as Z, ModelUsage as _, IndexRequestOptions as a, PromptAction as a0, RenderEnvelope as a1, Role as a2, SlotSize as a3, TextMetrics as a4, UnitCapability as a5, UnknownAdAction as a6, UserObject as a7, IndexResult as b, IndexSearchResponse as c, IndexShopSearchParams as d, IndexShopSearchResponse as e, IndexDeveloperSearchResponse as f, GravityOptions as g, IncomingAdRequest as h, GravityAdsOptions as i, GravityAdsResult as j, GravityContextOverrides as k, GravityContext as l, Ad as m, AdAction as n, AdLayout as o, AdUnit as p, ApiErrorResponse as q, Gender as r, IndexAlternative as s, IndexContextMessage as t, IndexCredentialRequest as u, IndexGender as v, IndexInstallInstructions as w, IndexInstallStep as x, IndexMcpConnect as y, IndexMonetization as z };
|