@gravity-ai/api 1.1.7 → 1.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/dist/index.d.mts +154 -3
- package/dist/index.d.ts +154 -3
- package/dist/index.js +574 -2
- package/dist/index.mjs +569 -2
- package/dist/opentui.d.mts +1 -1
- package/dist/opentui.d.ts +1 -1
- package/dist/{types-DIfiZ2zL.d.mts → types-C_krF5uC.d.mts} +157 -2
- package/dist/{types-DIfiZ2zL.d.ts → types-C_krF5uC.d.ts} +157 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GravityAdsOptions, I as IncomingAdRequest, M as MessageObject, P as PlacementObject, a as GravityAdsResult, b as GravityContextOverrides, c as GravityContext, A as AdParams, d as Ad } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { G as GravityAdsOptions, I as IncomingAdRequest, M as MessageObject, P as PlacementObject, a as GravityAdsResult, b as GravityContextOverrides, c as GravityContext, A as AdParams, d as Ad } from './types-C_krF5uC.mjs';
|
|
2
|
+
export { g as ApiErrorResponse, D as DeviceObject, i as Gender, f as LeadFormConfig, L as LeadFormField, e as LeadFormPrefill, h as Placement, R as Role, U as UserObject } from './types-C_krF5uC.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gravity ad client.
|
|
@@ -113,6 +113,14 @@ declare class Gravity {
|
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
115
115
|
declare function gravityContext(overrides: GravityContextOverrides): GravityContext;
|
|
116
|
+
/**
|
|
117
|
+
* Async variant of {@link gravityContext} that waits (bounded, never
|
|
118
|
+
* rejects) for the page's CMP to settle before attaching consent, so the
|
|
119
|
+
* first ad request of a page load carries the visitor's real decision —
|
|
120
|
+
* matching the awaited consent reads in @gravity-ai/ui and @gravity-ai/embed.
|
|
121
|
+
* An explicit `overrides.consent` skips the wait entirely.
|
|
122
|
+
*/
|
|
123
|
+
declare function gravityContextAsync(overrides: GravityContextOverrides): Promise<GravityContext>;
|
|
116
124
|
|
|
117
125
|
/**
|
|
118
126
|
* Trim conversation to the last N turns sent to Gravity for contextual matching.
|
|
@@ -354,4 +362,147 @@ interface HashedIdentity {
|
|
|
354
362
|
*/
|
|
355
363
|
declare function hashPii(values: RawIdentity): Promise<HashedIdentity>;
|
|
356
364
|
|
|
357
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Automatic CMP (Consent Management Platform) detection — browser only.
|
|
367
|
+
*
|
|
368
|
+
* EU-serving sites are required to run a consent banner, and IAB-registered
|
|
369
|
+
* CMPs all expose the same standard JavaScript APIs:
|
|
370
|
+
*
|
|
371
|
+
* - TCF v2: `window.__tcfapi(command, version, callback)`
|
|
372
|
+
* - US Privacy (CCPA): `window.__uspapi(command, version, callback)`
|
|
373
|
+
*
|
|
374
|
+
* This module reads those APIs (when present) and shapes the result into the
|
|
375
|
+
* `consent` object the Gravity ad API accepts, so consent collected by the
|
|
376
|
+
* publisher's existing banner is forwarded with zero publisher code. When no
|
|
377
|
+
* CMP is on the page nothing is attached and requests are unchanged.
|
|
378
|
+
*/
|
|
379
|
+
/** The `consent` object accepted by `POST /api/v1/ad` and `/ad-feedback`. */
|
|
380
|
+
interface ConsentSignal {
|
|
381
|
+
/** Whether GDPR applies to this end user (from the CMP). */
|
|
382
|
+
gdprApplies?: boolean;
|
|
383
|
+
/** IAB TCF v2 consent string collected by the publisher's CMP. */
|
|
384
|
+
tcfString?: string;
|
|
385
|
+
/** IAB US Privacy (CCPA) string, e.g. `"1YNN"`. */
|
|
386
|
+
usPrivacy?: string;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Synchronously return the current CMP consent signal, or `undefined` when
|
|
390
|
+
* no CMP is present / no settled decision exists yet. First call registers
|
|
391
|
+
* the standard listeners; later calls return the freshest cached state.
|
|
392
|
+
*/
|
|
393
|
+
declare function detectCmpConsent(): ConsentSignal | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* Await the CMP's settled consent decision, up to `timeoutMs` (default 500ms).
|
|
396
|
+
* Resolves early as soon as a decision is available; resolves `undefined`
|
|
397
|
+
* when no CMP is present or nothing settles in time. Never rejects — ad
|
|
398
|
+
* requests must not be delayed indefinitely by a slow CMP.
|
|
399
|
+
*/
|
|
400
|
+
declare function readCmpConsent(timeoutMs?: number): Promise<ConsentSignal | undefined>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* GravityPixel — Non-browser equivalent of gr-pix.js.
|
|
404
|
+
*
|
|
405
|
+
* Provides the same tracking capabilities as the browser pixel but for
|
|
406
|
+
* Node.js, Bun, and Deno applications. Handles visitor IDs, sessions,
|
|
407
|
+
* attribution, and event tracking automatically.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* import { gravityPixel } from '@gravity-ai/api';
|
|
412
|
+
*
|
|
413
|
+
* const pixel = gravityPixel({ pixelId: 'pub_abc123' });
|
|
414
|
+
* await pixel.start();
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
interface GravityPixelConfig {
|
|
418
|
+
/** Pixel ID from your Gravity dashboard (Settings → Pixel). */
|
|
419
|
+
pixelId: string;
|
|
420
|
+
/** Event endpoint. */
|
|
421
|
+
eventEndpoint?: string;
|
|
422
|
+
/** Session endpoint. */
|
|
423
|
+
sessionEndpoint?: string;
|
|
424
|
+
/** Session idle timeout in minutes (default 30). */
|
|
425
|
+
sessionTimeoutMinutes?: number;
|
|
426
|
+
/** Max age for persisted attribution in days (default 180). */
|
|
427
|
+
attrMaxAgeDays?: number;
|
|
428
|
+
/** Max entries in invocation history (default 50). */
|
|
429
|
+
sessionMaxPages?: number;
|
|
430
|
+
/** Hash identity fields with SHA-256 before sending (default true). */
|
|
431
|
+
hashIdentityFields?: boolean;
|
|
432
|
+
/** Custom storage directory (default ~/.gravity). */
|
|
433
|
+
storageDir?: string;
|
|
434
|
+
/** Application name used as page_title / context label. */
|
|
435
|
+
appName?: string;
|
|
436
|
+
}
|
|
437
|
+
declare class GravityPixel {
|
|
438
|
+
private config;
|
|
439
|
+
private attribution;
|
|
440
|
+
private session;
|
|
441
|
+
private isNewSession;
|
|
442
|
+
private contextSent;
|
|
443
|
+
private started;
|
|
444
|
+
constructor(opts: GravityPixelConfig);
|
|
445
|
+
/**
|
|
446
|
+
* Initialize the pixel: load persisted attribution + session, register
|
|
447
|
+
* process exit hooks, and fire the initial session update.
|
|
448
|
+
*/
|
|
449
|
+
start(): Promise<void>;
|
|
450
|
+
private shutdownSync;
|
|
451
|
+
private attrFilePath;
|
|
452
|
+
private loadAttribution;
|
|
453
|
+
private persistAttribution;
|
|
454
|
+
/**
|
|
455
|
+
* Capture attribution parameters (grclid, graid, UTMs, etc.).
|
|
456
|
+
* Call with params extracted from CLI args, environment variables,
|
|
457
|
+
* deep links, or any other source.
|
|
458
|
+
*
|
|
459
|
+
* Mirrors the same param set that gr-pix.js reads from URL query strings.
|
|
460
|
+
*/
|
|
461
|
+
handleAttribution(params: Record<string, string | undefined>): void;
|
|
462
|
+
private sessionFilePath;
|
|
463
|
+
private loadSession;
|
|
464
|
+
private persistSession;
|
|
465
|
+
private persistAll;
|
|
466
|
+
/**
|
|
467
|
+
* Fire a tracking event. Mirrors `window.gravityPixel.track()`.
|
|
468
|
+
*
|
|
469
|
+
* @param eventType - e.g. 'query', 'response', 'purchase', 'page_view'
|
|
470
|
+
* @param metadata - arbitrary key-value pairs attached to the event
|
|
471
|
+
*/
|
|
472
|
+
track(eventType: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* Track an event with identity fields (email, phone).
|
|
475
|
+
* Fields are hashed with SHA-256 before sending (same normalization
|
|
476
|
+
* as gr-pix.js: email lowercased+trimmed, phone digits-only).
|
|
477
|
+
*/
|
|
478
|
+
trackWithIdentity(eventType: string, identity: {
|
|
479
|
+
email?: string;
|
|
480
|
+
phone?: string;
|
|
481
|
+
}, metadata?: Record<string, unknown>): Promise<void>;
|
|
482
|
+
private sendSessionUpdate;
|
|
483
|
+
/** Stable first-party visitor ID (gruid_...). */
|
|
484
|
+
getVisitorId(): string | undefined;
|
|
485
|
+
/** Current session ID (gr_sess_...). */
|
|
486
|
+
getSessionId(): string | undefined;
|
|
487
|
+
/** Inbound Gravity click ID if present. */
|
|
488
|
+
getClickId(): string | undefined;
|
|
489
|
+
/** Inbound Gravity ad identifier if present. */
|
|
490
|
+
getGraid(): string | undefined;
|
|
491
|
+
/** Full attribution object. */
|
|
492
|
+
getAttribution(): Record<string, unknown>;
|
|
493
|
+
private buildUserAgent;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Create a GravityPixel instance.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* import { gravityPixel } from '@gravity-ai/api';
|
|
501
|
+
*
|
|
502
|
+
* const pixel = gravityPixel({ pixelId: 'YOUR_PIXEL_ID' });
|
|
503
|
+
* await pixel.start();
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
declare function gravityPixel(opts: GravityPixelConfig): GravityPixel;
|
|
507
|
+
|
|
508
|
+
export { Ad, AdParams, Client, type ClientParams, type ConsentSignal, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityPixel, type GravityPixelConfig, type HashedIdentity, IncomingAdRequest, MessageObject, PlacementObject, type RawIdentity, detectCmpConsent, extractClientIp, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, readCmpConsent, toGravityMessages };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GravityAdsOptions, I as IncomingAdRequest, M as MessageObject, P as PlacementObject, a as GravityAdsResult, b as GravityContextOverrides, c as GravityContext, A as AdParams, d as Ad } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { G as GravityAdsOptions, I as IncomingAdRequest, M as MessageObject, P as PlacementObject, a as GravityAdsResult, b as GravityContextOverrides, c as GravityContext, A as AdParams, d as Ad } from './types-C_krF5uC.js';
|
|
2
|
+
export { g as ApiErrorResponse, D as DeviceObject, i as Gender, f as LeadFormConfig, L as LeadFormField, e as LeadFormPrefill, h as Placement, R as Role, U as UserObject } from './types-C_krF5uC.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gravity ad client.
|
|
@@ -113,6 +113,14 @@ declare class Gravity {
|
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
115
115
|
declare function gravityContext(overrides: GravityContextOverrides): GravityContext;
|
|
116
|
+
/**
|
|
117
|
+
* Async variant of {@link gravityContext} that waits (bounded, never
|
|
118
|
+
* rejects) for the page's CMP to settle before attaching consent, so the
|
|
119
|
+
* first ad request of a page load carries the visitor's real decision —
|
|
120
|
+
* matching the awaited consent reads in @gravity-ai/ui and @gravity-ai/embed.
|
|
121
|
+
* An explicit `overrides.consent` skips the wait entirely.
|
|
122
|
+
*/
|
|
123
|
+
declare function gravityContextAsync(overrides: GravityContextOverrides): Promise<GravityContext>;
|
|
116
124
|
|
|
117
125
|
/**
|
|
118
126
|
* Trim conversation to the last N turns sent to Gravity for contextual matching.
|
|
@@ -354,4 +362,147 @@ interface HashedIdentity {
|
|
|
354
362
|
*/
|
|
355
363
|
declare function hashPii(values: RawIdentity): Promise<HashedIdentity>;
|
|
356
364
|
|
|
357
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Automatic CMP (Consent Management Platform) detection — browser only.
|
|
367
|
+
*
|
|
368
|
+
* EU-serving sites are required to run a consent banner, and IAB-registered
|
|
369
|
+
* CMPs all expose the same standard JavaScript APIs:
|
|
370
|
+
*
|
|
371
|
+
* - TCF v2: `window.__tcfapi(command, version, callback)`
|
|
372
|
+
* - US Privacy (CCPA): `window.__uspapi(command, version, callback)`
|
|
373
|
+
*
|
|
374
|
+
* This module reads those APIs (when present) and shapes the result into the
|
|
375
|
+
* `consent` object the Gravity ad API accepts, so consent collected by the
|
|
376
|
+
* publisher's existing banner is forwarded with zero publisher code. When no
|
|
377
|
+
* CMP is on the page nothing is attached and requests are unchanged.
|
|
378
|
+
*/
|
|
379
|
+
/** The `consent` object accepted by `POST /api/v1/ad` and `/ad-feedback`. */
|
|
380
|
+
interface ConsentSignal {
|
|
381
|
+
/** Whether GDPR applies to this end user (from the CMP). */
|
|
382
|
+
gdprApplies?: boolean;
|
|
383
|
+
/** IAB TCF v2 consent string collected by the publisher's CMP. */
|
|
384
|
+
tcfString?: string;
|
|
385
|
+
/** IAB US Privacy (CCPA) string, e.g. `"1YNN"`. */
|
|
386
|
+
usPrivacy?: string;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Synchronously return the current CMP consent signal, or `undefined` when
|
|
390
|
+
* no CMP is present / no settled decision exists yet. First call registers
|
|
391
|
+
* the standard listeners; later calls return the freshest cached state.
|
|
392
|
+
*/
|
|
393
|
+
declare function detectCmpConsent(): ConsentSignal | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* Await the CMP's settled consent decision, up to `timeoutMs` (default 500ms).
|
|
396
|
+
* Resolves early as soon as a decision is available; resolves `undefined`
|
|
397
|
+
* when no CMP is present or nothing settles in time. Never rejects — ad
|
|
398
|
+
* requests must not be delayed indefinitely by a slow CMP.
|
|
399
|
+
*/
|
|
400
|
+
declare function readCmpConsent(timeoutMs?: number): Promise<ConsentSignal | undefined>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* GravityPixel — Non-browser equivalent of gr-pix.js.
|
|
404
|
+
*
|
|
405
|
+
* Provides the same tracking capabilities as the browser pixel but for
|
|
406
|
+
* Node.js, Bun, and Deno applications. Handles visitor IDs, sessions,
|
|
407
|
+
* attribution, and event tracking automatically.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* import { gravityPixel } from '@gravity-ai/api';
|
|
412
|
+
*
|
|
413
|
+
* const pixel = gravityPixel({ pixelId: 'pub_abc123' });
|
|
414
|
+
* await pixel.start();
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
interface GravityPixelConfig {
|
|
418
|
+
/** Pixel ID from your Gravity dashboard (Settings → Pixel). */
|
|
419
|
+
pixelId: string;
|
|
420
|
+
/** Event endpoint. */
|
|
421
|
+
eventEndpoint?: string;
|
|
422
|
+
/** Session endpoint. */
|
|
423
|
+
sessionEndpoint?: string;
|
|
424
|
+
/** Session idle timeout in minutes (default 30). */
|
|
425
|
+
sessionTimeoutMinutes?: number;
|
|
426
|
+
/** Max age for persisted attribution in days (default 180). */
|
|
427
|
+
attrMaxAgeDays?: number;
|
|
428
|
+
/** Max entries in invocation history (default 50). */
|
|
429
|
+
sessionMaxPages?: number;
|
|
430
|
+
/** Hash identity fields with SHA-256 before sending (default true). */
|
|
431
|
+
hashIdentityFields?: boolean;
|
|
432
|
+
/** Custom storage directory (default ~/.gravity). */
|
|
433
|
+
storageDir?: string;
|
|
434
|
+
/** Application name used as page_title / context label. */
|
|
435
|
+
appName?: string;
|
|
436
|
+
}
|
|
437
|
+
declare class GravityPixel {
|
|
438
|
+
private config;
|
|
439
|
+
private attribution;
|
|
440
|
+
private session;
|
|
441
|
+
private isNewSession;
|
|
442
|
+
private contextSent;
|
|
443
|
+
private started;
|
|
444
|
+
constructor(opts: GravityPixelConfig);
|
|
445
|
+
/**
|
|
446
|
+
* Initialize the pixel: load persisted attribution + session, register
|
|
447
|
+
* process exit hooks, and fire the initial session update.
|
|
448
|
+
*/
|
|
449
|
+
start(): Promise<void>;
|
|
450
|
+
private shutdownSync;
|
|
451
|
+
private attrFilePath;
|
|
452
|
+
private loadAttribution;
|
|
453
|
+
private persistAttribution;
|
|
454
|
+
/**
|
|
455
|
+
* Capture attribution parameters (grclid, graid, UTMs, etc.).
|
|
456
|
+
* Call with params extracted from CLI args, environment variables,
|
|
457
|
+
* deep links, or any other source.
|
|
458
|
+
*
|
|
459
|
+
* Mirrors the same param set that gr-pix.js reads from URL query strings.
|
|
460
|
+
*/
|
|
461
|
+
handleAttribution(params: Record<string, string | undefined>): void;
|
|
462
|
+
private sessionFilePath;
|
|
463
|
+
private loadSession;
|
|
464
|
+
private persistSession;
|
|
465
|
+
private persistAll;
|
|
466
|
+
/**
|
|
467
|
+
* Fire a tracking event. Mirrors `window.gravityPixel.track()`.
|
|
468
|
+
*
|
|
469
|
+
* @param eventType - e.g. 'query', 'response', 'purchase', 'page_view'
|
|
470
|
+
* @param metadata - arbitrary key-value pairs attached to the event
|
|
471
|
+
*/
|
|
472
|
+
track(eventType: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* Track an event with identity fields (email, phone).
|
|
475
|
+
* Fields are hashed with SHA-256 before sending (same normalization
|
|
476
|
+
* as gr-pix.js: email lowercased+trimmed, phone digits-only).
|
|
477
|
+
*/
|
|
478
|
+
trackWithIdentity(eventType: string, identity: {
|
|
479
|
+
email?: string;
|
|
480
|
+
phone?: string;
|
|
481
|
+
}, metadata?: Record<string, unknown>): Promise<void>;
|
|
482
|
+
private sendSessionUpdate;
|
|
483
|
+
/** Stable first-party visitor ID (gruid_...). */
|
|
484
|
+
getVisitorId(): string | undefined;
|
|
485
|
+
/** Current session ID (gr_sess_...). */
|
|
486
|
+
getSessionId(): string | undefined;
|
|
487
|
+
/** Inbound Gravity click ID if present. */
|
|
488
|
+
getClickId(): string | undefined;
|
|
489
|
+
/** Inbound Gravity ad identifier if present. */
|
|
490
|
+
getGraid(): string | undefined;
|
|
491
|
+
/** Full attribution object. */
|
|
492
|
+
getAttribution(): Record<string, unknown>;
|
|
493
|
+
private buildUserAgent;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Create a GravityPixel instance.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* import { gravityPixel } from '@gravity-ai/api';
|
|
501
|
+
*
|
|
502
|
+
* const pixel = gravityPixel({ pixelId: 'YOUR_PIXEL_ID' });
|
|
503
|
+
* await pixel.start();
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
declare function gravityPixel(opts: GravityPixelConfig): GravityPixel;
|
|
507
|
+
|
|
508
|
+
export { Ad, AdParams, Client, type ClientParams, type ConsentSignal, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityPixel, type GravityPixelConfig, type HashedIdentity, IncomingAdRequest, MessageObject, PlacementObject, type RawIdentity, detectCmpConsent, extractClientIp, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, readCmpConsent, toGravityMessages };
|