@gravity-ai/api 1.5.0 → 1.7.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 +134 -6
- package/dist/index.d.ts +134 -6
- package/dist/index.js +428 -41
- package/dist/index.mjs +418 -40
- package/dist/opentui.js +1 -1
- package/dist/opentui.mjs +1 -1
- package/dist/{types-FOlyOpps.d.mts → types-DsxvJZVE.d.mts} +333 -1
- package/dist/{types-FOlyOpps.d.ts → types-DsxvJZVE.d.ts} +333 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -302,6 +302,51 @@ if (ad) {
|
|
|
302
302
|
|
|
303
303
|
---
|
|
304
304
|
|
|
305
|
+
## Gravity Index
|
|
306
|
+
|
|
307
|
+
Use `gravity.index` on an existing `Gravity` instance, or instantiate `GravityIndex` standalone to search developer services (`POST /search`) and consumer products (`POST /shop/search`).
|
|
308
|
+
|
|
309
|
+
```ts
|
|
310
|
+
import { Gravity, GravityIndex, isDeveloperSearchResponse } from '@gravity-ai/api';
|
|
311
|
+
|
|
312
|
+
// Via existing Gravity client (shares apiKey):
|
|
313
|
+
const gravity = new Gravity({ production: true });
|
|
314
|
+
const res = await gravity.index.search({
|
|
315
|
+
query: 'serverless Postgres database with a free tier',
|
|
316
|
+
user_ip: '203.0.113.7', // real end-user IP for hosted servers (fallback: GRAVITY_INDEX_USER_IP || 'caller')
|
|
317
|
+
session_id: 'chat_8f3a',
|
|
318
|
+
email: 'alice@example.com', // SHA-256 hashed locally into hashed_email; never sent raw
|
|
319
|
+
user_agent: req.headers['user-agent'], // automatically capped at 1024 chars
|
|
320
|
+
country: 'US',
|
|
321
|
+
external_user_id_hash: 'sha256_user_id',
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
if (res.ok && isDeveloperSearchResponse(res.data)) {
|
|
325
|
+
console.log(res.data.recommendation?.name, res.data.click_url);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Or standalone (reads GRAVITY_PUBLISHER_KEY || GRAVITY_API_KEY):
|
|
329
|
+
const index = new GravityIndex();
|
|
330
|
+
const products = await index.shopSearch({
|
|
331
|
+
query: 'running shoes for wide feet',
|
|
332
|
+
user_ip: '203.0.113.7',
|
|
333
|
+
session_id: 'chat_8f3a',
|
|
334
|
+
price_max: 150,
|
|
335
|
+
max_results: 3,
|
|
336
|
+
});
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Every method resolves to `IndexResult<T>` (`{ ok, data, status, elapsed, error?, retryAfterSeconds? }`) and never throws.
|
|
340
|
+
|
|
341
|
+
| Method | Endpoint | Purpose |
|
|
342
|
+
|--------|----------|---------|
|
|
343
|
+
| `search(params)` | `POST /search` | Recommend a developer service (or consumer products with `vertical: 'consumer'` / `filters`) |
|
|
344
|
+
| `shopSearch(params)` | `POST /shop/search` | Search consumer products with structured filters and facets |
|
|
345
|
+
|
|
346
|
+
**End-user context (CPM payouts & geo targeting):** Hosted servers should pass the end user's real `user_ip` (falls back to `GRAVITY_INDEX_USER_IP`, else `'caller'`), `session_id`, `user_agent` (capped at 1,024 chars), `hashed_email` (or raw `email`, which is trimmed, lowercased, and SHA-256 hashed locally and never transmitted raw), `external_user_id_hash`, and `country` (ISO 3166-1 alpha-2 on `search`).
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
305
350
|
## License
|
|
306
351
|
|
|
307
352
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
|
-
import { G as
|
|
2
|
-
export {
|
|
1
|
+
import { G as GravityIndexOptions, I as IndexSearchParams, a as IndexRequestOptions, b as IndexResult, c as IndexSearchResponse, d as IndexShopSearchParams, e as IndexShopSearchResponse, f as IndexDeveloperSearchResponse, g as GravityOptions, h as IncomingAdRequest, M as MessageObject, P as PlacementObject, i as GravityAdsOptions, j as GravityAdsResult, k as GravityContextOverrides, l as GravityContext, A as Ad, m as AdParams } from './types-DsxvJZVE.mjs';
|
|
2
|
+
export { n as AdAction, o as AdLayout, p as AdUnit, q as ApiErrorResponse, D as DeviceObject, F as FrameSize, r as Gender, H as HostTheme, s as IndexAlternative, t as IndexContextMessage, u as IndexCredentialRequest, v as IndexGender, w as IndexInstallInstructions, x as IndexInstallStep, y as IndexMcpConnect, z as IndexMonetization, B as IndexMppCheckout, C as IndexPriceRange, E as IndexProduct, J as IndexRecommendation, K as IndexSearchContext, L as IndexSearchOption, N as IndexShopFacets, O as IndexShopFilters, Q as IndexUcpCheckout, R as IndexVertical, S as IndexWebResult, T as LeadFormConfig, U as LeadFormField, V as LeadFormPrefill, W as McpConnect, X as McpConnectHandler, Y as McpConnectRequest, Z as McpConnectResult, _ as ModelUsage, $ as Placement, a0 as PromptAction, a1 as RenderEnvelope, a2 as Role, a3 as SlotSize, a4 as TextMetrics, a5 as UnitCapability, a6 as UnknownAdAction, a7 as UserObject } from './types-DsxvJZVE.mjs';
|
|
3
|
+
|
|
4
|
+
declare const DEFAULT_INDEX_URL = "https://index.trygravity.com";
|
|
5
|
+
declare const DEFAULT_INDEX_TIMEOUT_MS = 30000;
|
|
6
|
+
/** Type guard: checks whether a `search()` payload is a consumer product response. */
|
|
7
|
+
declare function isConsumerSearchResponse(response: IndexSearchResponse | null | undefined): response is IndexShopSearchResponse;
|
|
8
|
+
/** Type guard: checks whether a `search()` payload is a developer service response. */
|
|
9
|
+
declare function isDeveloperSearchResponse(response: IndexSearchResponse | null | undefined): response is IndexDeveloperSearchResponse;
|
|
10
|
+
/**
|
|
11
|
+
* Client for the Gravity Index search APIs (`POST /search` and `POST /shop/search`).
|
|
12
|
+
*
|
|
13
|
+
* Every method resolves to `IndexResult<T>` and **never throws**.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { GravityIndex, isDeveloperSearchResponse } from '@gravity-ai/api';
|
|
18
|
+
*
|
|
19
|
+
* const index = new GravityIndex(); // reads GRAVITY_PUBLISHER_KEY or GRAVITY_API_KEY
|
|
20
|
+
*
|
|
21
|
+
* const res = await index.search({
|
|
22
|
+
* query: 'serverless Postgres database with a free tier',
|
|
23
|
+
* user_ip: '203.0.113.7',
|
|
24
|
+
* session_id: 'chat_8f3a',
|
|
25
|
+
* email: 'alice@example.com', // SHA-256 hashed locally; never sent raw
|
|
26
|
+
* });
|
|
27
|
+
* if (res.ok && isDeveloperSearchResponse(res.data)) {
|
|
28
|
+
* console.log(res.data.recommendation?.name, res.data.click_url);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare class GravityIndex {
|
|
33
|
+
private readonly opts;
|
|
34
|
+
constructor(opts?: GravityIndexOptions);
|
|
35
|
+
private resolveApiKey;
|
|
36
|
+
private resolveIndexUrl;
|
|
37
|
+
private post;
|
|
38
|
+
/**
|
|
39
|
+
* Search the Gravity Index for the best developer service (or consumer
|
|
40
|
+
* products when `vertical: 'consumer'` or `filters` are provided).
|
|
41
|
+
*
|
|
42
|
+
* `POST /search`
|
|
43
|
+
*/
|
|
44
|
+
search(params: IndexSearchParams, overrides?: IndexRequestOptions): Promise<IndexResult<IndexSearchResponse>>;
|
|
45
|
+
/**
|
|
46
|
+
* Search consumer products that a user can buy, with optional structured
|
|
47
|
+
* filters (brand, merchant, price range, sale status, etc.).
|
|
48
|
+
*
|
|
49
|
+
* `POST /shop/search`
|
|
50
|
+
*/
|
|
51
|
+
shopSearch(params: IndexShopSearchParams, overrides?: IndexRequestOptions): Promise<IndexResult<IndexShopSearchResponse>>;
|
|
52
|
+
}
|
|
3
53
|
|
|
4
54
|
/**
|
|
5
55
|
* Gravity ad client.
|
|
@@ -30,8 +80,9 @@ export { e as AdAction, f as AdLayout, g as AdUnit, h as ApiErrorResponse, D as
|
|
|
30
80
|
*/
|
|
31
81
|
declare class Gravity {
|
|
32
82
|
private opts;
|
|
83
|
+
private indexClient?;
|
|
33
84
|
/**
|
|
34
|
-
* @param opts - Configuration applied to every `getAds()` call.
|
|
85
|
+
* @param opts - Configuration applied to every `getAds()` call and `gravity.index`.
|
|
35
86
|
*
|
|
36
87
|
* | Option | Type | Default | Description |
|
|
37
88
|
* |--------|------|---------|-------------|
|
|
@@ -42,8 +93,14 @@ declare class Gravity {
|
|
|
42
93
|
* | `timeoutMs` | `number` | `4000` | Request timeout in ms |
|
|
43
94
|
* | `excludedTopics` | `string[]` | — | Topics to exclude from ad matching |
|
|
44
95
|
* | `gravityApi` | `string` | production URL | Custom API endpoint |
|
|
96
|
+
* | `index` | `GravityIndexOptions` | — | Optional Gravity Index client overrides |
|
|
97
|
+
*/
|
|
98
|
+
constructor(opts?: GravityOptions);
|
|
99
|
+
/**
|
|
100
|
+
* Gravity Index client sharing this instance's API key (plus any `opts.index`
|
|
101
|
+
* overrides).
|
|
45
102
|
*/
|
|
46
|
-
|
|
103
|
+
get index(): GravityIndex;
|
|
47
104
|
/**
|
|
48
105
|
* Fetch ads from the Gravity API. **Never throws.**
|
|
49
106
|
*
|
|
@@ -183,6 +240,77 @@ declare function extractClientIp(req: IncomingAdRequest): string | undefined;
|
|
|
183
240
|
*/
|
|
184
241
|
declare function gravityAds(req: IncomingAdRequest, messages: MessageObject[], placements: PlacementObject[], opts?: GravityAdsOptions): Promise<GravityAdsResult>;
|
|
185
242
|
|
|
243
|
+
interface InlineAdInput {
|
|
244
|
+
adText?: string | null;
|
|
245
|
+
brandName?: string | null;
|
|
246
|
+
title?: string | null;
|
|
247
|
+
clickUrl?: string | null;
|
|
248
|
+
shortClickUrl?: string | null;
|
|
249
|
+
impUrl?: string | null;
|
|
250
|
+
placement_id?: string | null;
|
|
251
|
+
}
|
|
252
|
+
interface InlineAdOptions {
|
|
253
|
+
/** Show the disclosure label (default: true). */
|
|
254
|
+
showLabel?: boolean;
|
|
255
|
+
/** Disclosure label text (default: "Sponsored"). */
|
|
256
|
+
labelText?: string;
|
|
257
|
+
/** Prefer `shortClickUrl` when present (default: false). */
|
|
258
|
+
useShortUrl?: boolean;
|
|
259
|
+
}
|
|
260
|
+
interface InlineAdParts {
|
|
261
|
+
/** Text before the hyperlinked brand/phrase. */
|
|
262
|
+
before: string;
|
|
263
|
+
/** Hyperlinked text (brand name when available, else full copy). */
|
|
264
|
+
linkText: string;
|
|
265
|
+
/** Text after the hyperlinked brand/phrase. */
|
|
266
|
+
after: string;
|
|
267
|
+
/** Validated http(s) click URL, or null if absent/unsafe. */
|
|
268
|
+
url: string | null;
|
|
269
|
+
/** Disclosure label (e.g. "Sponsored"), or null when `showLabel: false`. */
|
|
270
|
+
label: string | null;
|
|
271
|
+
}
|
|
272
|
+
interface FormatInlineAdOptions extends InlineAdOptions {
|
|
273
|
+
/** Output format (default: "markdown"). */
|
|
274
|
+
format?: 'markdown' | 'plain';
|
|
275
|
+
}
|
|
276
|
+
interface AppendInlineAdOptions extends FormatInlineAdOptions {
|
|
277
|
+
/** Text inserted between the response and the inline ad (default: "\n\n"). */
|
|
278
|
+
separator?: string;
|
|
279
|
+
/** Max ms to wait for a pending ad promise after the stream ends (default: 500). */
|
|
280
|
+
adTimeoutMs?: number;
|
|
281
|
+
/** Pick the ad for a specific `placement_id` when passing a `GravityAdsResult`. */
|
|
282
|
+
placementId?: string;
|
|
283
|
+
/** Fire `impUrl` when the inline ad is appended (default: true). */
|
|
284
|
+
trackImpression?: boolean;
|
|
285
|
+
/** Custom fetch implementation for impression tracking. */
|
|
286
|
+
fetchFn?: (url: string, init?: {
|
|
287
|
+
method?: string;
|
|
288
|
+
}) => Promise<unknown>;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Split an ad into inline text segments so the brand name is hyperlinked
|
|
292
|
+
* inside the copy (no card/box required).
|
|
293
|
+
*/
|
|
294
|
+
declare function splitInlineAd(ad: InlineAdInput | null | undefined, options?: InlineAdOptions): InlineAdParts | null;
|
|
295
|
+
/**
|
|
296
|
+
* Format an ad as a single inline Markdown (or plain-text) sentence with the
|
|
297
|
+
* brand name hyperlinked and a `(Sponsored)` disclosure.
|
|
298
|
+
*/
|
|
299
|
+
declare function formatInlineAd(ad: InlineAdInput | null | undefined, options?: FormatInlineAdOptions): string;
|
|
300
|
+
/**
|
|
301
|
+
* Fire-and-forget impression pixel for server-side / streaming inline ads
|
|
302
|
+
* where no browser SDK is rendering the ad. Never throws.
|
|
303
|
+
*/
|
|
304
|
+
declare function trackInlineImpression(ad: InlineAdInput | null | undefined, fetchFn?: (url: string, init?: {
|
|
305
|
+
method?: string;
|
|
306
|
+
}) => Promise<unknown>): Promise<boolean>;
|
|
307
|
+
type AdSource = Ad | InlineAdInput | GravityAdsResult | null | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Pass every chunk of a text stream straight through, then append the inline
|
|
310
|
+
* ad sentence when the stream finishes. Never throws on ad errors or timeouts.
|
|
311
|
+
*/
|
|
312
|
+
declare function appendInlineAd(stream: AsyncIterable<string>, adOrPromise: AdSource | Promise<AdSource>, options?: AppendInlineAdOptions): AsyncGenerator<string, void, unknown>;
|
|
313
|
+
|
|
186
314
|
/**
|
|
187
315
|
* @deprecated Use `Gravity` instead. See README for migration guide.
|
|
188
316
|
*/
|
|
@@ -516,5 +644,5 @@ declare class GravityPixel {
|
|
|
516
644
|
*/
|
|
517
645
|
declare function gravityPixel(opts: GravityPixelConfig): GravityPixel;
|
|
518
646
|
|
|
519
|
-
export { Ad, AdParams, Client, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityPixel, IncomingAdRequest, MessageObject, PlacementObject, detectCmpConsent, extractClientIp, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, readCmpConsent, toGravityMessages };
|
|
520
|
-
export type { ClientParams, ConsentSignal, GravityPixelConfig, HashedIdentity, RawIdentity };
|
|
647
|
+
export { Ad, AdParams, Client, DEFAULT_INDEX_TIMEOUT_MS, DEFAULT_INDEX_URL, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityIndex, GravityIndexOptions, GravityOptions, GravityPixel, IncomingAdRequest, IndexDeveloperSearchResponse, IndexRequestOptions, IndexResult, IndexSearchParams, IndexSearchResponse, IndexShopSearchParams, IndexShopSearchResponse, MessageObject, PlacementObject, appendInlineAd, detectCmpConsent, extractClientIp, formatInlineAd, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, isConsumerSearchResponse, isDeveloperSearchResponse, readCmpConsent, splitInlineAd, toGravityMessages, trackInlineImpression };
|
|
648
|
+
export type { AppendInlineAdOptions, ClientParams, ConsentSignal, FormatInlineAdOptions, GravityPixelConfig, HashedIdentity, InlineAdInput, InlineAdOptions, InlineAdParts, RawIdentity };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
|
-
import { G as
|
|
2
|
-
export {
|
|
1
|
+
import { G as GravityIndexOptions, I as IndexSearchParams, a as IndexRequestOptions, b as IndexResult, c as IndexSearchResponse, d as IndexShopSearchParams, e as IndexShopSearchResponse, f as IndexDeveloperSearchResponse, g as GravityOptions, h as IncomingAdRequest, M as MessageObject, P as PlacementObject, i as GravityAdsOptions, j as GravityAdsResult, k as GravityContextOverrides, l as GravityContext, A as Ad, m as AdParams } from './types-DsxvJZVE.js';
|
|
2
|
+
export { n as AdAction, o as AdLayout, p as AdUnit, q as ApiErrorResponse, D as DeviceObject, F as FrameSize, r as Gender, H as HostTheme, s as IndexAlternative, t as IndexContextMessage, u as IndexCredentialRequest, v as IndexGender, w as IndexInstallInstructions, x as IndexInstallStep, y as IndexMcpConnect, z as IndexMonetization, B as IndexMppCheckout, C as IndexPriceRange, E as IndexProduct, J as IndexRecommendation, K as IndexSearchContext, L as IndexSearchOption, N as IndexShopFacets, O as IndexShopFilters, Q as IndexUcpCheckout, R as IndexVertical, S as IndexWebResult, T as LeadFormConfig, U as LeadFormField, V as LeadFormPrefill, W as McpConnect, X as McpConnectHandler, Y as McpConnectRequest, Z as McpConnectResult, _ as ModelUsage, $ as Placement, a0 as PromptAction, a1 as RenderEnvelope, a2 as Role, a3 as SlotSize, a4 as TextMetrics, a5 as UnitCapability, a6 as UnknownAdAction, a7 as UserObject } from './types-DsxvJZVE.js';
|
|
3
|
+
|
|
4
|
+
declare const DEFAULT_INDEX_URL = "https://index.trygravity.com";
|
|
5
|
+
declare const DEFAULT_INDEX_TIMEOUT_MS = 30000;
|
|
6
|
+
/** Type guard: checks whether a `search()` payload is a consumer product response. */
|
|
7
|
+
declare function isConsumerSearchResponse(response: IndexSearchResponse | null | undefined): response is IndexShopSearchResponse;
|
|
8
|
+
/** Type guard: checks whether a `search()` payload is a developer service response. */
|
|
9
|
+
declare function isDeveloperSearchResponse(response: IndexSearchResponse | null | undefined): response is IndexDeveloperSearchResponse;
|
|
10
|
+
/**
|
|
11
|
+
* Client for the Gravity Index search APIs (`POST /search` and `POST /shop/search`).
|
|
12
|
+
*
|
|
13
|
+
* Every method resolves to `IndexResult<T>` and **never throws**.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { GravityIndex, isDeveloperSearchResponse } from '@gravity-ai/api';
|
|
18
|
+
*
|
|
19
|
+
* const index = new GravityIndex(); // reads GRAVITY_PUBLISHER_KEY or GRAVITY_API_KEY
|
|
20
|
+
*
|
|
21
|
+
* const res = await index.search({
|
|
22
|
+
* query: 'serverless Postgres database with a free tier',
|
|
23
|
+
* user_ip: '203.0.113.7',
|
|
24
|
+
* session_id: 'chat_8f3a',
|
|
25
|
+
* email: 'alice@example.com', // SHA-256 hashed locally; never sent raw
|
|
26
|
+
* });
|
|
27
|
+
* if (res.ok && isDeveloperSearchResponse(res.data)) {
|
|
28
|
+
* console.log(res.data.recommendation?.name, res.data.click_url);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare class GravityIndex {
|
|
33
|
+
private readonly opts;
|
|
34
|
+
constructor(opts?: GravityIndexOptions);
|
|
35
|
+
private resolveApiKey;
|
|
36
|
+
private resolveIndexUrl;
|
|
37
|
+
private post;
|
|
38
|
+
/**
|
|
39
|
+
* Search the Gravity Index for the best developer service (or consumer
|
|
40
|
+
* products when `vertical: 'consumer'` or `filters` are provided).
|
|
41
|
+
*
|
|
42
|
+
* `POST /search`
|
|
43
|
+
*/
|
|
44
|
+
search(params: IndexSearchParams, overrides?: IndexRequestOptions): Promise<IndexResult<IndexSearchResponse>>;
|
|
45
|
+
/**
|
|
46
|
+
* Search consumer products that a user can buy, with optional structured
|
|
47
|
+
* filters (brand, merchant, price range, sale status, etc.).
|
|
48
|
+
*
|
|
49
|
+
* `POST /shop/search`
|
|
50
|
+
*/
|
|
51
|
+
shopSearch(params: IndexShopSearchParams, overrides?: IndexRequestOptions): Promise<IndexResult<IndexShopSearchResponse>>;
|
|
52
|
+
}
|
|
3
53
|
|
|
4
54
|
/**
|
|
5
55
|
* Gravity ad client.
|
|
@@ -30,8 +80,9 @@ export { e as AdAction, f as AdLayout, g as AdUnit, h as ApiErrorResponse, D as
|
|
|
30
80
|
*/
|
|
31
81
|
declare class Gravity {
|
|
32
82
|
private opts;
|
|
83
|
+
private indexClient?;
|
|
33
84
|
/**
|
|
34
|
-
* @param opts - Configuration applied to every `getAds()` call.
|
|
85
|
+
* @param opts - Configuration applied to every `getAds()` call and `gravity.index`.
|
|
35
86
|
*
|
|
36
87
|
* | Option | Type | Default | Description |
|
|
37
88
|
* |--------|------|---------|-------------|
|
|
@@ -42,8 +93,14 @@ declare class Gravity {
|
|
|
42
93
|
* | `timeoutMs` | `number` | `4000` | Request timeout in ms |
|
|
43
94
|
* | `excludedTopics` | `string[]` | — | Topics to exclude from ad matching |
|
|
44
95
|
* | `gravityApi` | `string` | production URL | Custom API endpoint |
|
|
96
|
+
* | `index` | `GravityIndexOptions` | — | Optional Gravity Index client overrides |
|
|
97
|
+
*/
|
|
98
|
+
constructor(opts?: GravityOptions);
|
|
99
|
+
/**
|
|
100
|
+
* Gravity Index client sharing this instance's API key (plus any `opts.index`
|
|
101
|
+
* overrides).
|
|
45
102
|
*/
|
|
46
|
-
|
|
103
|
+
get index(): GravityIndex;
|
|
47
104
|
/**
|
|
48
105
|
* Fetch ads from the Gravity API. **Never throws.**
|
|
49
106
|
*
|
|
@@ -183,6 +240,77 @@ declare function extractClientIp(req: IncomingAdRequest): string | undefined;
|
|
|
183
240
|
*/
|
|
184
241
|
declare function gravityAds(req: IncomingAdRequest, messages: MessageObject[], placements: PlacementObject[], opts?: GravityAdsOptions): Promise<GravityAdsResult>;
|
|
185
242
|
|
|
243
|
+
interface InlineAdInput {
|
|
244
|
+
adText?: string | null;
|
|
245
|
+
brandName?: string | null;
|
|
246
|
+
title?: string | null;
|
|
247
|
+
clickUrl?: string | null;
|
|
248
|
+
shortClickUrl?: string | null;
|
|
249
|
+
impUrl?: string | null;
|
|
250
|
+
placement_id?: string | null;
|
|
251
|
+
}
|
|
252
|
+
interface InlineAdOptions {
|
|
253
|
+
/** Show the disclosure label (default: true). */
|
|
254
|
+
showLabel?: boolean;
|
|
255
|
+
/** Disclosure label text (default: "Sponsored"). */
|
|
256
|
+
labelText?: string;
|
|
257
|
+
/** Prefer `shortClickUrl` when present (default: false). */
|
|
258
|
+
useShortUrl?: boolean;
|
|
259
|
+
}
|
|
260
|
+
interface InlineAdParts {
|
|
261
|
+
/** Text before the hyperlinked brand/phrase. */
|
|
262
|
+
before: string;
|
|
263
|
+
/** Hyperlinked text (brand name when available, else full copy). */
|
|
264
|
+
linkText: string;
|
|
265
|
+
/** Text after the hyperlinked brand/phrase. */
|
|
266
|
+
after: string;
|
|
267
|
+
/** Validated http(s) click URL, or null if absent/unsafe. */
|
|
268
|
+
url: string | null;
|
|
269
|
+
/** Disclosure label (e.g. "Sponsored"), or null when `showLabel: false`. */
|
|
270
|
+
label: string | null;
|
|
271
|
+
}
|
|
272
|
+
interface FormatInlineAdOptions extends InlineAdOptions {
|
|
273
|
+
/** Output format (default: "markdown"). */
|
|
274
|
+
format?: 'markdown' | 'plain';
|
|
275
|
+
}
|
|
276
|
+
interface AppendInlineAdOptions extends FormatInlineAdOptions {
|
|
277
|
+
/** Text inserted between the response and the inline ad (default: "\n\n"). */
|
|
278
|
+
separator?: string;
|
|
279
|
+
/** Max ms to wait for a pending ad promise after the stream ends (default: 500). */
|
|
280
|
+
adTimeoutMs?: number;
|
|
281
|
+
/** Pick the ad for a specific `placement_id` when passing a `GravityAdsResult`. */
|
|
282
|
+
placementId?: string;
|
|
283
|
+
/** Fire `impUrl` when the inline ad is appended (default: true). */
|
|
284
|
+
trackImpression?: boolean;
|
|
285
|
+
/** Custom fetch implementation for impression tracking. */
|
|
286
|
+
fetchFn?: (url: string, init?: {
|
|
287
|
+
method?: string;
|
|
288
|
+
}) => Promise<unknown>;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Split an ad into inline text segments so the brand name is hyperlinked
|
|
292
|
+
* inside the copy (no card/box required).
|
|
293
|
+
*/
|
|
294
|
+
declare function splitInlineAd(ad: InlineAdInput | null | undefined, options?: InlineAdOptions): InlineAdParts | null;
|
|
295
|
+
/**
|
|
296
|
+
* Format an ad as a single inline Markdown (or plain-text) sentence with the
|
|
297
|
+
* brand name hyperlinked and a `(Sponsored)` disclosure.
|
|
298
|
+
*/
|
|
299
|
+
declare function formatInlineAd(ad: InlineAdInput | null | undefined, options?: FormatInlineAdOptions): string;
|
|
300
|
+
/**
|
|
301
|
+
* Fire-and-forget impression pixel for server-side / streaming inline ads
|
|
302
|
+
* where no browser SDK is rendering the ad. Never throws.
|
|
303
|
+
*/
|
|
304
|
+
declare function trackInlineImpression(ad: InlineAdInput | null | undefined, fetchFn?: (url: string, init?: {
|
|
305
|
+
method?: string;
|
|
306
|
+
}) => Promise<unknown>): Promise<boolean>;
|
|
307
|
+
type AdSource = Ad | InlineAdInput | GravityAdsResult | null | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Pass every chunk of a text stream straight through, then append the inline
|
|
310
|
+
* ad sentence when the stream finishes. Never throws on ad errors or timeouts.
|
|
311
|
+
*/
|
|
312
|
+
declare function appendInlineAd(stream: AsyncIterable<string>, adOrPromise: AdSource | Promise<AdSource>, options?: AppendInlineAdOptions): AsyncGenerator<string, void, unknown>;
|
|
313
|
+
|
|
186
314
|
/**
|
|
187
315
|
* @deprecated Use `Gravity` instead. See README for migration guide.
|
|
188
316
|
*/
|
|
@@ -516,5 +644,5 @@ declare class GravityPixel {
|
|
|
516
644
|
*/
|
|
517
645
|
declare function gravityPixel(opts: GravityPixelConfig): GravityPixel;
|
|
518
646
|
|
|
519
|
-
export { Ad, AdParams, Client, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityPixel, IncomingAdRequest, MessageObject, PlacementObject, detectCmpConsent, extractClientIp, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, readCmpConsent, toGravityMessages };
|
|
520
|
-
export type { ClientParams, ConsentSignal, GravityPixelConfig, HashedIdentity, RawIdentity };
|
|
647
|
+
export { Ad, AdParams, Client, DEFAULT_INDEX_TIMEOUT_MS, DEFAULT_INDEX_URL, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityIndex, GravityIndexOptions, GravityOptions, GravityPixel, IncomingAdRequest, IndexDeveloperSearchResponse, IndexRequestOptions, IndexResult, IndexSearchParams, IndexSearchResponse, IndexShopSearchParams, IndexShopSearchResponse, MessageObject, PlacementObject, appendInlineAd, detectCmpConsent, extractClientIp, formatInlineAd, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, isConsumerSearchResponse, isDeveloperSearchResponse, readCmpConsent, splitInlineAd, toGravityMessages, trackInlineImpression };
|
|
648
|
+
export type { AppendInlineAdOptions, ClientParams, ConsentSignal, FormatInlineAdOptions, GravityPixelConfig, HashedIdentity, InlineAdInput, InlineAdOptions, InlineAdParts, RawIdentity };
|