@gravity-ai/api 1.1.5 → 1.1.7

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 CHANGED
@@ -184,12 +184,25 @@ Client-side. Collects device + user context. Returns a plain object to include i
184
184
 
185
185
  | Parameter | Type | Required | Description |
186
186
  |-----------|------|----------|-------------|
187
- | `overrides.sessionId` | `string` | Yes | Your chat/conversation session ID |
187
+ | `overrides.sessionId` | `string` | Conditional | Your chat/conversation session ID. Optional in browsers when the [Gravity pixel](https://docs.trygravity.ai/ai-platforms/pixel) is loaded (falls back to `window.gravityPixel.getSessionId()`). Required in Node/Bun/Deno. |
188
188
  | `overrides.user.userId` | `string` | Yes | Your authenticated user's ID |
189
189
  | `overrides.device` | `object` | No | Device field overrides |
190
190
 
191
191
  **Returns:** `{ sessionId, user: { id, ... }, device: { ua, timezone, locale, ... } }`
192
192
 
193
+ #### Pixel auto-forwarding (browser only)
194
+
195
+ If the Gravity pixel (`gr-pix.js`) is loaded on the page, these pixel values are auto-attached to the context object. Caller-supplied values always win:
196
+
197
+ | Pixel method | Attached as | Used for |
198
+ |---|---|---|
199
+ | `getVisitorId()` | `user.gruid` | Stable cross-session visitor ID (180-day cookie) |
200
+ | `getSessionId()` | top-level `sessionId` fallback | `gr_sess_…` session ID (30-min idle, 1-day max) |
201
+ | `getClickId()` | `user.grclid` | Inbound Gravity ad click ID for attribution |
202
+ | `getGraid()` | `user.graid` | Inbound Gravity ad identifier |
203
+
204
+ Install the pixel once on your site and the SDK picks up the extra signals automatically — no glue code.
205
+
193
206
  Auto-detected fields vary by runtime:
194
207
 
195
208
  | Field | Browser | Node/Bun/Deno |
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-DYbti_CZ.mjs';
2
- export { e as ApiErrorResponse, D as DeviceObject, g as Gender, f as Placement, R as Role, U as UserObject } from './types-DYbti_CZ.mjs';
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-DIfiZ2zL.mjs';
2
+ export { e as ApiErrorResponse, D as DeviceObject, g as Gender, f as Placement, R as Role, U as UserObject } from './types-DIfiZ2zL.mjs';
3
3
 
4
4
  /**
5
5
  * Gravity ad client.
@@ -68,7 +68,20 @@ declare class Gravity {
68
68
  *
69
69
  * Nothing is written to disk, localStorage, or cookies.
70
70
  *
71
- * @param overrides - Must include `sessionId` and `user.userId`.
71
+ * ## Pixel auto-forwarding (browser only)
72
+ *
73
+ * If the Gravity pixel (`gr-pix.js`) is loaded on the page, this function
74
+ * reads `window.gravityPixel` and auto-attaches:
75
+ *
76
+ * - `getVisitorId()` → `user.gruid`
77
+ * - `getSessionId()` → top-level `sessionId` (used only if caller didn't pass one)
78
+ * - `getClickId()` → `user.grclid` (inbound Gravity ad click)
79
+ * - `getGraid()` → `user.graid` (inbound Gravity ad identifier)
80
+ *
81
+ * Caller-provided values always win; pixel values are fallbacks.
82
+ *
83
+ * @param overrides - `user.userId` is required. `sessionId` is required
84
+ * unless the pixel is loaded (in which case `getSessionId()` is used).
72
85
  *
73
86
  * @example Browser (React, Next.js, vanilla JS)
74
87
  * ```ts
@@ -85,6 +98,12 @@ declare class Gravity {
85
98
  * });
86
99
  * ```
87
100
  *
101
+ * @example Browser with Gravity pixel installed (no sessionId needed)
102
+ * ```ts
103
+ * // Pixel's gr_sess_... ID is used automatically
104
+ * const ctx = gravityContext({ user: { userId: currentUser.id } });
105
+ * ```
106
+ *
88
107
  * @example Node.js CLI
89
108
  * ```ts
90
109
  * const ctx = gravityContext({
@@ -292,4 +311,47 @@ declare class Client {
292
311
  private handleError;
293
312
  }
294
313
 
295
- export { Ad, AdParams, Client, type ClientParams, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, IncomingAdRequest, MessageObject, PlacementObject, extractClientIp, gravityAds, gravityContext, toGravityMessages };
314
+ /**
315
+ * SHA-256 hashing helpers for publisher-side PII.
316
+ *
317
+ * Matches the normalization used by the Gravity publisher pixel so that
318
+ * hashed emails/phones sent via the SDK collide with hashed values captured
319
+ * by the pixel and by the advertiser-side conversion pipeline. That collision
320
+ * is what lets the identity graph resolve a user across surfaces.
321
+ *
322
+ * Normalization:
323
+ * - email: trim + lowercase
324
+ * - phone: strip non-digits (e.g. "+1 (555) 123-4567" -> "15551234567")
325
+ *
326
+ * All inputs are hashed client-side with Web Crypto (`crypto.subtle.digest`),
327
+ * which is available in modern browsers, Node.js >= 18, Bun, and Deno. Raw
328
+ * PII never leaves the caller's process.
329
+ */
330
+ interface RawIdentity {
331
+ email?: string | null;
332
+ phone?: string | null;
333
+ }
334
+ interface HashedIdentity {
335
+ hashed_email?: string;
336
+ hashed_phone?: string;
337
+ }
338
+ /**
339
+ * Hash raw email and/or phone with SHA-256 after normalizing to the canonical
340
+ * form the Gravity pipeline uses. Returns only the fields that successfully
341
+ * hashed — callers can spread the result into their user context without
342
+ * worrying about `undefined` values.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * import { gravityContext, hashPii } from '@gravity-ai/api';
347
+ *
348
+ * const hashed = await hashPii({ email: user.email, phone: user.phone });
349
+ * const ctx = gravityContext({
350
+ * sessionId: chatSession.id,
351
+ * user: { userId: user.id, ...hashed },
352
+ * });
353
+ * ```
354
+ */
355
+ declare function hashPii(values: RawIdentity): Promise<HashedIdentity>;
356
+
357
+ export { Ad, AdParams, Client, type ClientParams, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, type HashedIdentity, IncomingAdRequest, MessageObject, PlacementObject, type RawIdentity, extractClientIp, gravityAds, gravityContext, hashPii, 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-DYbti_CZ.js';
2
- export { e as ApiErrorResponse, D as DeviceObject, g as Gender, f as Placement, R as Role, U as UserObject } from './types-DYbti_CZ.js';
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-DIfiZ2zL.js';
2
+ export { e as ApiErrorResponse, D as DeviceObject, g as Gender, f as Placement, R as Role, U as UserObject } from './types-DIfiZ2zL.js';
3
3
 
4
4
  /**
5
5
  * Gravity ad client.
@@ -68,7 +68,20 @@ declare class Gravity {
68
68
  *
69
69
  * Nothing is written to disk, localStorage, or cookies.
70
70
  *
71
- * @param overrides - Must include `sessionId` and `user.userId`.
71
+ * ## Pixel auto-forwarding (browser only)
72
+ *
73
+ * If the Gravity pixel (`gr-pix.js`) is loaded on the page, this function
74
+ * reads `window.gravityPixel` and auto-attaches:
75
+ *
76
+ * - `getVisitorId()` → `user.gruid`
77
+ * - `getSessionId()` → top-level `sessionId` (used only if caller didn't pass one)
78
+ * - `getClickId()` → `user.grclid` (inbound Gravity ad click)
79
+ * - `getGraid()` → `user.graid` (inbound Gravity ad identifier)
80
+ *
81
+ * Caller-provided values always win; pixel values are fallbacks.
82
+ *
83
+ * @param overrides - `user.userId` is required. `sessionId` is required
84
+ * unless the pixel is loaded (in which case `getSessionId()` is used).
72
85
  *
73
86
  * @example Browser (React, Next.js, vanilla JS)
74
87
  * ```ts
@@ -85,6 +98,12 @@ declare class Gravity {
85
98
  * });
86
99
  * ```
87
100
  *
101
+ * @example Browser with Gravity pixel installed (no sessionId needed)
102
+ * ```ts
103
+ * // Pixel's gr_sess_... ID is used automatically
104
+ * const ctx = gravityContext({ user: { userId: currentUser.id } });
105
+ * ```
106
+ *
88
107
  * @example Node.js CLI
89
108
  * ```ts
90
109
  * const ctx = gravityContext({
@@ -292,4 +311,47 @@ declare class Client {
292
311
  private handleError;
293
312
  }
294
313
 
295
- export { Ad, AdParams, Client, type ClientParams, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, IncomingAdRequest, MessageObject, PlacementObject, extractClientIp, gravityAds, gravityContext, toGravityMessages };
314
+ /**
315
+ * SHA-256 hashing helpers for publisher-side PII.
316
+ *
317
+ * Matches the normalization used by the Gravity publisher pixel so that
318
+ * hashed emails/phones sent via the SDK collide with hashed values captured
319
+ * by the pixel and by the advertiser-side conversion pipeline. That collision
320
+ * is what lets the identity graph resolve a user across surfaces.
321
+ *
322
+ * Normalization:
323
+ * - email: trim + lowercase
324
+ * - phone: strip non-digits (e.g. "+1 (555) 123-4567" -> "15551234567")
325
+ *
326
+ * All inputs are hashed client-side with Web Crypto (`crypto.subtle.digest`),
327
+ * which is available in modern browsers, Node.js >= 18, Bun, and Deno. Raw
328
+ * PII never leaves the caller's process.
329
+ */
330
+ interface RawIdentity {
331
+ email?: string | null;
332
+ phone?: string | null;
333
+ }
334
+ interface HashedIdentity {
335
+ hashed_email?: string;
336
+ hashed_phone?: string;
337
+ }
338
+ /**
339
+ * Hash raw email and/or phone with SHA-256 after normalizing to the canonical
340
+ * form the Gravity pipeline uses. Returns only the fields that successfully
341
+ * hashed — callers can spread the result into their user context without
342
+ * worrying about `undefined` values.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * import { gravityContext, hashPii } from '@gravity-ai/api';
347
+ *
348
+ * const hashed = await hashPii({ email: user.email, phone: user.phone });
349
+ * const ctx = gravityContext({
350
+ * sessionId: chatSession.id,
351
+ * user: { userId: user.id, ...hashed },
352
+ * });
353
+ * ```
354
+ */
355
+ declare function hashPii(values: RawIdentity): Promise<HashedIdentity>;
356
+
357
+ export { Ad, AdParams, Client, type ClientParams, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, type HashedIdentity, IncomingAdRequest, MessageObject, PlacementObject, type RawIdentity, extractClientIp, gravityAds, gravityContext, hashPii, toGravityMessages };
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ var require_package = __commonJS({
35
35
  "package.json"(exports2, module2) {
36
36
  module2.exports = {
37
37
  name: "@gravity-ai/api",
38
- version: "1.1.5",
38
+ version: "1.1.7",
39
39
  description: "Gravity JS SDK for retrieving targeted advertisements",
40
40
  main: "dist/index.js",
41
41
  module: "dist/index.mjs",
@@ -125,6 +125,7 @@ __export(index_exports, {
125
125
  extractClientIp: () => extractClientIp,
126
126
  gravityAds: () => gravityAds,
127
127
  gravityContext: () => gravityContext,
128
+ hashPii: () => hashPii,
128
129
  toGravityMessages: () => toGravityMessages
129
130
  });
130
131
  module.exports = __toCommonJS(index_exports);
@@ -253,10 +254,19 @@ var Gravity = class {
253
254
  };
254
255
 
255
256
  // context.ts
256
- function gravityContext(overrides) {
257
- if (!overrides?.sessionId) {
258
- throw new Error("gravityContext() requires sessionId");
257
+ function readPixel(method) {
258
+ if (typeof window === "undefined") return void 0;
259
+ try {
260
+ const pixel = window.gravityPixel;
261
+ const fn = pixel?.[method];
262
+ if (typeof fn !== "function") return void 0;
263
+ const value = fn.call(pixel);
264
+ return value ?? void 0;
265
+ } catch {
266
+ return void 0;
259
267
  }
268
+ }
269
+ function gravityContext(overrides) {
260
270
  if (!overrides?.user?.userId) {
261
271
  throw new Error("gravityContext() requires user.userId");
262
272
  }
@@ -266,9 +276,23 @@ function gravityContext(overrides) {
266
276
  Object.assign(device, overrides.device);
267
277
  }
268
278
  const { userId, ...restUser } = overrides.user;
279
+ const gruid = readPixel("getVisitorId");
280
+ const pixelSessionId = readPixel("getSessionId");
281
+ const grclid = readPixel("getClickId");
282
+ const graid = readPixel("getGraid");
283
+ const sessionId = overrides.sessionId ?? pixelSessionId;
284
+ if (!sessionId) {
285
+ throw new Error(
286
+ "gravityContext() requires sessionId (or the Gravity pixel must be loaded so window.gravityPixel.getSessionId() returns a value)"
287
+ );
288
+ }
289
+ const pixelUserFields = {};
290
+ if (gruid) pixelUserFields.gruid = gruid;
291
+ if (grclid) pixelUserFields.grclid = grclid;
292
+ if (graid) pixelUserFields.graid = graid;
269
293
  return {
270
- sessionId: overrides.sessionId,
271
- user: { ...restUser, id: userId },
294
+ sessionId,
295
+ user: { ...pixelUserFields, ...restUser, id: userId },
272
296
  device
273
297
  };
274
298
  }
@@ -494,6 +518,42 @@ var Client = class {
494
518
  }
495
519
  }
496
520
  };
521
+
522
+ // hash.ts
523
+ async function sha256Hex(value) {
524
+ const subtle = typeof globalThis !== "undefined" && globalThis.crypto?.subtle || void 0;
525
+ if (!subtle) return void 0;
526
+ try {
527
+ const bytes = new TextEncoder().encode(value);
528
+ const digest = await subtle.digest("SHA-256", bytes);
529
+ const hex = Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
530
+ return hex;
531
+ } catch {
532
+ return void 0;
533
+ }
534
+ }
535
+ function normalizeEmail(raw) {
536
+ if (typeof raw !== "string") return void 0;
537
+ const trimmed = raw.trim().toLowerCase();
538
+ return trimmed || void 0;
539
+ }
540
+ function normalizePhone(raw) {
541
+ if (typeof raw !== "string") return void 0;
542
+ const digits = raw.replace(/\D+/g, "");
543
+ return digits || void 0;
544
+ }
545
+ async function hashPii(values) {
546
+ const out = {};
547
+ const emailNorm = normalizeEmail(values.email ?? void 0);
548
+ const phoneNorm = normalizePhone(values.phone ?? void 0);
549
+ const [hashedEmail, hashedPhone] = await Promise.all([
550
+ emailNorm ? sha256Hex(emailNorm) : Promise.resolve(void 0),
551
+ phoneNorm ? sha256Hex(phoneNorm) : Promise.resolve(void 0)
552
+ ]);
553
+ if (hashedEmail) out.hashed_email = hashedEmail;
554
+ if (hashedPhone) out.hashed_phone = hashedPhone;
555
+ return out;
556
+ }
497
557
  // Annotate the CommonJS export names for ESM import in node:
498
558
  0 && (module.exports = {
499
559
  Client,
@@ -501,5 +561,6 @@ var Client = class {
501
561
  extractClientIp,
502
562
  gravityAds,
503
563
  gravityContext,
564
+ hashPii,
504
565
  toGravityMessages
505
566
  });
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ var require_package = __commonJS({
8
8
  "package.json"(exports, module) {
9
9
  module.exports = {
10
10
  name: "@gravity-ai/api",
11
- version: "1.1.5",
11
+ version: "1.1.7",
12
12
  description: "Gravity JS SDK for retrieving targeted advertisements",
13
13
  main: "dist/index.js",
14
14
  module: "dist/index.mjs",
@@ -214,10 +214,19 @@ var Gravity = class {
214
214
  };
215
215
 
216
216
  // context.ts
217
- function gravityContext(overrides) {
218
- if (!overrides?.sessionId) {
219
- throw new Error("gravityContext() requires sessionId");
217
+ function readPixel(method) {
218
+ if (typeof window === "undefined") return void 0;
219
+ try {
220
+ const pixel = window.gravityPixel;
221
+ const fn = pixel?.[method];
222
+ if (typeof fn !== "function") return void 0;
223
+ const value = fn.call(pixel);
224
+ return value ?? void 0;
225
+ } catch {
226
+ return void 0;
220
227
  }
228
+ }
229
+ function gravityContext(overrides) {
221
230
  if (!overrides?.user?.userId) {
222
231
  throw new Error("gravityContext() requires user.userId");
223
232
  }
@@ -227,9 +236,23 @@ function gravityContext(overrides) {
227
236
  Object.assign(device, overrides.device);
228
237
  }
229
238
  const { userId, ...restUser } = overrides.user;
239
+ const gruid = readPixel("getVisitorId");
240
+ const pixelSessionId = readPixel("getSessionId");
241
+ const grclid = readPixel("getClickId");
242
+ const graid = readPixel("getGraid");
243
+ const sessionId = overrides.sessionId ?? pixelSessionId;
244
+ if (!sessionId) {
245
+ throw new Error(
246
+ "gravityContext() requires sessionId (or the Gravity pixel must be loaded so window.gravityPixel.getSessionId() returns a value)"
247
+ );
248
+ }
249
+ const pixelUserFields = {};
250
+ if (gruid) pixelUserFields.gruid = gruid;
251
+ if (grclid) pixelUserFields.grclid = grclid;
252
+ if (graid) pixelUserFields.graid = graid;
230
253
  return {
231
- sessionId: overrides.sessionId,
232
- user: { ...restUser, id: userId },
254
+ sessionId,
255
+ user: { ...pixelUserFields, ...restUser, id: userId },
233
256
  device
234
257
  };
235
258
  }
@@ -455,11 +478,48 @@ var Client = class {
455
478
  }
456
479
  }
457
480
  };
481
+
482
+ // hash.ts
483
+ async function sha256Hex(value) {
484
+ const subtle = typeof globalThis !== "undefined" && globalThis.crypto?.subtle || void 0;
485
+ if (!subtle) return void 0;
486
+ try {
487
+ const bytes = new TextEncoder().encode(value);
488
+ const digest = await subtle.digest("SHA-256", bytes);
489
+ const hex = Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
490
+ return hex;
491
+ } catch {
492
+ return void 0;
493
+ }
494
+ }
495
+ function normalizeEmail(raw) {
496
+ if (typeof raw !== "string") return void 0;
497
+ const trimmed = raw.trim().toLowerCase();
498
+ return trimmed || void 0;
499
+ }
500
+ function normalizePhone(raw) {
501
+ if (typeof raw !== "string") return void 0;
502
+ const digits = raw.replace(/\D+/g, "");
503
+ return digits || void 0;
504
+ }
505
+ async function hashPii(values) {
506
+ const out = {};
507
+ const emailNorm = normalizeEmail(values.email ?? void 0);
508
+ const phoneNorm = normalizePhone(values.phone ?? void 0);
509
+ const [hashedEmail, hashedPhone] = await Promise.all([
510
+ emailNorm ? sha256Hex(emailNorm) : Promise.resolve(void 0),
511
+ phoneNorm ? sha256Hex(phoneNorm) : Promise.resolve(void 0)
512
+ ]);
513
+ if (hashedEmail) out.hashed_email = hashedEmail;
514
+ if (hashedPhone) out.hashed_phone = hashedPhone;
515
+ return out;
516
+ }
458
517
  export {
459
518
  Client,
460
519
  Gravity,
461
520
  extractClientIp,
462
521
  gravityAds,
463
522
  gravityContext,
523
+ hashPii,
464
524
  toGravityMessages
465
525
  };
@@ -1,4 +1,4 @@
1
- import { d as Ad } from './types-DYbti_CZ.mjs';
1
+ import { d as Ad } from './types-DIfiZ2zL.mjs';
2
2
 
3
3
  /**
4
4
  * @gravity-ai/api/opentui — Gravity ad rendering + tracking for OpenTUI terminals
package/dist/opentui.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as Ad } from './types-DYbti_CZ.js';
1
+ import { d as Ad } from './types-DIfiZ2zL.js';
2
2
 
3
3
  /**
4
4
  * @gravity-ai/api/opentui — Gravity ad rendering + tracking for OpenTUI terminals
@@ -161,6 +161,18 @@ interface Ad {
161
161
  impUrl?: string;
162
162
  /** Click-through tracking URL - use this as href for ad clicks */
163
163
  clickUrl?: string;
164
+ /** Placement type this ad was served to */
165
+ placement?: string;
166
+ /** Publisher's slot correlation ID */
167
+ placement_id?: string;
168
+ /** Experiment fields (present when a composition experiment is active) */
169
+ variant?: string;
170
+ experiment_id?: string;
171
+ composition_id?: string;
172
+ renderer_key?: string;
173
+ composition_mode?: string;
174
+ /** Full composition envelope for SDK rendering */
175
+ composition?: Record<string, unknown>;
164
176
  }
165
177
  /**
166
178
  * Error response structure from the Gravity API
@@ -176,11 +188,18 @@ interface ApiErrorResponse {
176
188
  }
177
189
  /**
178
190
  * Overrides passed to `gravityContext()`.
179
- * `sessionId` and `user.userId` are required; everything else is auto-detected.
191
+ * `user.userId` is required; everything else is auto-detected.
192
+ *
193
+ * `sessionId` is required unless the Gravity pixel is loaded on the page,
194
+ * in which case `window.gravityPixel.getSessionId()` is used as a fallback.
180
195
  */
181
196
  interface GravityContextOverrides {
182
- /** Your chat/conversation session ID (required) */
183
- sessionId: string;
197
+ /**
198
+ * Your chat/conversation session ID. Optional when the Gravity pixel
199
+ * is loaded — the SDK will fall back to `window.gravityPixel.getSessionId()`.
200
+ * Required in server-side / non-browser runtimes.
201
+ */
202
+ sessionId?: string;
184
203
  /** User info — `userId` is required */
185
204
  user: {
186
205
  userId: string;
@@ -161,6 +161,18 @@ interface Ad {
161
161
  impUrl?: string;
162
162
  /** Click-through tracking URL - use this as href for ad clicks */
163
163
  clickUrl?: string;
164
+ /** Placement type this ad was served to */
165
+ placement?: string;
166
+ /** Publisher's slot correlation ID */
167
+ placement_id?: string;
168
+ /** Experiment fields (present when a composition experiment is active) */
169
+ variant?: string;
170
+ experiment_id?: string;
171
+ composition_id?: string;
172
+ renderer_key?: string;
173
+ composition_mode?: string;
174
+ /** Full composition envelope for SDK rendering */
175
+ composition?: Record<string, unknown>;
164
176
  }
165
177
  /**
166
178
  * Error response structure from the Gravity API
@@ -176,11 +188,18 @@ interface ApiErrorResponse {
176
188
  }
177
189
  /**
178
190
  * Overrides passed to `gravityContext()`.
179
- * `sessionId` and `user.userId` are required; everything else is auto-detected.
191
+ * `user.userId` is required; everything else is auto-detected.
192
+ *
193
+ * `sessionId` is required unless the Gravity pixel is loaded on the page,
194
+ * in which case `window.gravityPixel.getSessionId()` is used as a fallback.
180
195
  */
181
196
  interface GravityContextOverrides {
182
- /** Your chat/conversation session ID (required) */
183
- sessionId: string;
197
+ /**
198
+ * Your chat/conversation session ID. Optional when the Gravity pixel
199
+ * is loaded — the SDK will fall back to `window.gravityPixel.getSessionId()`.
200
+ * Required in server-side / non-browser runtimes.
201
+ */
202
+ sessionId?: string;
184
203
  /** User info — `userId` is required */
185
204
  user: {
186
205
  userId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ai/api",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Gravity JS SDK for retrieving targeted advertisements",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",