@gravity-ai/api 1.3.1 → 1.4.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 CHANGED
@@ -287,12 +287,15 @@ See [@gravity-ai/react](../react/README.md) for component docs, variants, and st
287
287
 
288
288
  ### Vanilla JS / any framework
289
289
 
290
- Ads are plain JSON objects. Render them however you want:
290
+ Ads are plain JSON objects. Render them however you want, but treat every ad field as untrusted text: set it with `textContent`, never `innerHTML`.
291
291
 
292
292
  ```ts
293
293
  const ad = ads[0];
294
294
  if (ad) {
295
- element.innerHTML = `<a href="${ad.clickUrl}">${ad.adText}</a>`;
295
+ const link = document.createElement('a');
296
+ link.href = ad.clickUrl;
297
+ link.textContent = ad.adText;
298
+ element.replaceChildren(link);
296
299
  if (ad.impUrl) new Image().src = ad.impUrl;
297
300
  }
298
301
  ```
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-DaB2KQT1.mjs';
2
- export { e as AdAction, f as AdLayout, g as AdUnit, h as ApiErrorResponse, D as DeviceObject, F as FrameSize, i as Gender, H as HostTheme, L as LeadFormConfig, j as LeadFormField, k as LeadFormPrefill, l as McpConnect, m as McpConnectHandler, n as McpConnectRequest, o as McpConnectResult, p as ModelUsage, q as Placement, r as PromptAction, R as RenderEnvelope, s as Role, S as SlotSize, T as TextMetrics, U as UnitCapability, t as UnknownAdAction, u as UserObject } from './types-DaB2KQT1.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-C20oXLJd.mjs';
2
+ export { e as AdAction, f as AdLayout, g as AdUnit, h as ApiErrorResponse, D as DeviceObject, F as FrameSize, i as Gender, H as HostTheme, L as LeadFormConfig, j as LeadFormField, k as LeadFormPrefill, l as McpConnect, m as McpConnectHandler, n as McpConnectRequest, o as McpConnectResult, p as ModelUsage, q as Placement, r as PromptAction, R as RenderEnvelope, s as Role, S as SlotSize, T as TextMetrics, U as UnitCapability, t as UnknownAdAction, u as UserObject } from './types-C20oXLJd.mjs';
3
3
 
4
4
  /**
5
5
  * Gravity ad client.
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-DaB2KQT1.js';
2
- export { e as AdAction, f as AdLayout, g as AdUnit, h as ApiErrorResponse, D as DeviceObject, F as FrameSize, i as Gender, H as HostTheme, L as LeadFormConfig, j as LeadFormField, k as LeadFormPrefill, l as McpConnect, m as McpConnectHandler, n as McpConnectRequest, o as McpConnectResult, p as ModelUsage, q as Placement, r as PromptAction, R as RenderEnvelope, s as Role, S as SlotSize, T as TextMetrics, U as UnitCapability, t as UnknownAdAction, u as UserObject } from './types-DaB2KQT1.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-C20oXLJd.js';
2
+ export { e as AdAction, f as AdLayout, g as AdUnit, h as ApiErrorResponse, D as DeviceObject, F as FrameSize, i as Gender, H as HostTheme, L as LeadFormConfig, j as LeadFormField, k as LeadFormPrefill, l as McpConnect, m as McpConnectHandler, n as McpConnectRequest, o as McpConnectResult, p as ModelUsage, q as Placement, r as PromptAction, R as RenderEnvelope, s as Role, S as SlotSize, T as TextMetrics, U as UnitCapability, t as UnknownAdAction, u as UserObject } from './types-C20oXLJd.js';
3
3
 
4
4
  /**
5
5
  * Gravity ad client.
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ var require_package = __commonJS({
39
39
  "package.json"(exports2, module2) {
40
40
  module2.exports = {
41
41
  name: "@gravity-ai/api",
42
- version: "1.3.1",
42
+ version: "1.4.0",
43
43
  description: "Gravity JS SDK for retrieving targeted advertisements",
44
44
  main: "dist/index.js",
45
45
  module: "dist/index.mjs",
@@ -273,8 +273,9 @@ function readHostTheme(el) {
273
273
  return void 0;
274
274
  }
275
275
  }
276
- function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false } = {}) {
276
+ function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false, banner = false } = {}) {
277
277
  const caps = ["units.v1", "image"];
278
+ if (banner) caps.push("blocks.banner");
278
279
  if (frames) caps.push("frame.gfb1");
279
280
  if (promptAction) caps.push("action.prompt");
280
281
  if (mcpConnect) caps.push("connect.mcp");
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.3.1",
11
+ version: "1.4.0",
12
12
  description: "Gravity JS SDK for retrieving targeted advertisements",
13
13
  main: "dist/index.js",
14
14
  module: "dist/index.mjs",
@@ -224,8 +224,9 @@ function readHostTheme(el) {
224
224
  return void 0;
225
225
  }
226
226
  }
227
- function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false } = {}) {
227
+ function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false, banner = false } = {}) {
228
228
  const caps = ["units.v1", "image"];
229
+ if (banner) caps.push("blocks.banner");
229
230
  if (frames) caps.push("frame.gfb1");
230
231
  if (promptAction) caps.push("action.prompt");
231
232
  if (mcpConnect) caps.push("connect.mcp");
package/dist/opentui.js CHANGED
@@ -25,6 +25,32 @@ __export(opentui_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(opentui_exports);
27
27
  var import_child_process = require("child_process");
28
+
29
+ // viewability.ts
30
+ var MAX_TRACKED_IMPRESSIONS = 1e3;
31
+ var SDK = "opentui";
32
+ var SDK_VERSION = "1.4.0";
33
+ var beaconsSent = /* @__PURE__ */ new Set();
34
+ function sendViewabilityBeacon(impUrl, ev) {
35
+ const key = `${ev} ${impUrl}`;
36
+ if (beaconsSent.has(key)) return;
37
+ try {
38
+ const url = new URL(impUrl);
39
+ url.searchParams.append("ev", ev);
40
+ url.searchParams.append("sdk", SDK);
41
+ url.searchParams.append("sv", SDK_VERSION);
42
+ beaconsSent.add(key);
43
+ if (beaconsSent.size > MAX_TRACKED_IMPRESSIONS) {
44
+ beaconsSent.delete(beaconsSent.values().next().value);
45
+ }
46
+ fetch(url.toString()).catch(() => {
47
+ });
48
+ } catch {
49
+ }
50
+ }
51
+
52
+ // opentui.ts
53
+ var VIEWABLE_DWELL_MS = 1e3;
28
54
  function openUrl(url) {
29
55
  if (!url) return;
30
56
  try {
@@ -63,6 +89,7 @@ function gravityAdTracking(options) {
63
89
  let activeUrl = "";
64
90
  let hovered = false;
65
91
  let _impressionFired = false;
92
+ let viewableTimer;
66
93
  function setHover(next) {
67
94
  if (!activeUrl) return;
68
95
  if (hovered === next) return;
@@ -116,6 +143,7 @@ function gravityAdTracking(options) {
116
143
  activeUrl = "";
117
144
  hovered = false;
118
145
  _impressionFired = false;
146
+ clearTimeout(viewableTimer);
119
147
  panel.visible = false;
120
148
  }
121
149
  function setAd(ad) {
@@ -136,11 +164,15 @@ function gravityAdTracking(options) {
136
164
  activeUrl = ad.clickUrl || ad.url || "";
137
165
  hovered = false;
138
166
  _impressionFired = false;
167
+ clearTimeout(viewableTimer);
139
168
  panel.visible = true;
140
169
  if (ad.impUrl) {
141
- fireImpression(ad.impUrl);
170
+ const impUrl = ad.impUrl;
171
+ fireImpression(impUrl);
142
172
  _impressionFired = true;
143
173
  onImpression?.(ad);
174
+ sendViewabilityBeacon(impUrl, "measured");
175
+ viewableTimer = setTimeout(() => sendViewabilityBeacon(impUrl, "viewable"), VIEWABLE_DWELL_MS);
144
176
  }
145
177
  }
146
178
  return {
package/dist/opentui.mjs CHANGED
@@ -4,6 +4,32 @@ import {
4
4
 
5
5
  // opentui.ts
6
6
  import { execFile } from "child_process";
7
+
8
+ // viewability.ts
9
+ var MAX_TRACKED_IMPRESSIONS = 1e3;
10
+ var SDK = "opentui";
11
+ var SDK_VERSION = "1.4.0";
12
+ var beaconsSent = /* @__PURE__ */ new Set();
13
+ function sendViewabilityBeacon(impUrl, ev) {
14
+ const key = `${ev} ${impUrl}`;
15
+ if (beaconsSent.has(key)) return;
16
+ try {
17
+ const url = new URL(impUrl);
18
+ url.searchParams.append("ev", ev);
19
+ url.searchParams.append("sdk", SDK);
20
+ url.searchParams.append("sv", SDK_VERSION);
21
+ beaconsSent.add(key);
22
+ if (beaconsSent.size > MAX_TRACKED_IMPRESSIONS) {
23
+ beaconsSent.delete(beaconsSent.values().next().value);
24
+ }
25
+ fetch(url.toString()).catch(() => {
26
+ });
27
+ } catch {
28
+ }
29
+ }
30
+
31
+ // opentui.ts
32
+ var VIEWABLE_DWELL_MS = 1e3;
7
33
  function openUrl(url) {
8
34
  if (!url) return;
9
35
  try {
@@ -42,6 +68,7 @@ function gravityAdTracking(options) {
42
68
  let activeUrl = "";
43
69
  let hovered = false;
44
70
  let _impressionFired = false;
71
+ let viewableTimer;
45
72
  function setHover(next) {
46
73
  if (!activeUrl) return;
47
74
  if (hovered === next) return;
@@ -95,6 +122,7 @@ function gravityAdTracking(options) {
95
122
  activeUrl = "";
96
123
  hovered = false;
97
124
  _impressionFired = false;
125
+ clearTimeout(viewableTimer);
98
126
  panel.visible = false;
99
127
  }
100
128
  function setAd(ad) {
@@ -115,11 +143,15 @@ function gravityAdTracking(options) {
115
143
  activeUrl = ad.clickUrl || ad.url || "";
116
144
  hovered = false;
117
145
  _impressionFired = false;
146
+ clearTimeout(viewableTimer);
118
147
  panel.visible = true;
119
148
  if (ad.impUrl) {
120
- fireImpression(ad.impUrl);
149
+ const impUrl = ad.impUrl;
150
+ fireImpression(impUrl);
121
151
  _impressionFired = true;
122
152
  onImpression?.(ad);
153
+ sendViewabilityBeacon(impUrl, "measured");
154
+ viewableTimer = setTimeout(() => sendViewabilityBeacon(impUrl, "viewable"), VIEWABLE_DWELL_MS);
123
155
  }
124
156
  }
125
157
  return {
@@ -9,8 +9,8 @@
9
9
  * from the server: a layout only selects one of the renderer's fixed
10
10
  * arrangements and sets numbers inside it.
11
11
  */
12
- type UnitType = 'text' | 'brand_card' | 'link_preview' | 'product_rail' | 'action_card' | 'connect_card' | 'rich_frame';
13
- type UnitArrangement = 'text' | 'stack' | 'split' | 'hero' | 'row' | 'rail';
12
+ type UnitType = 'text' | 'brand_card' | 'link_preview' | 'product_rail' | 'action_card' | 'connect_card' | 'media_card' | 'rich_frame' | 'storefront' | 'discover' | 'configurator';
13
+ type UnitArrangement = 'text' | 'stack' | 'split' | 'hero' | 'row' | 'rail' | 'media' | 'storefront' | 'discover' | 'configurator';
14
14
  interface UnitTextStyle {
15
15
  size?: number;
16
16
  lines?: number;
@@ -21,11 +21,15 @@ interface UnitLayout {
21
21
  minWidth: number;
22
22
  maxWidth?: number;
23
23
  arrangement: UnitArrangement;
24
+ /** Lowest height the engine assumes when it fits this layout into a slot's maxHeight. The SDK does not draw it. */
25
+ minHeight?: number;
24
26
  image?: {
25
27
  mode: 'hidden' | 'optional' | 'required';
26
28
  position?: 'top' | 'left' | 'right' | 'background';
27
29
  aspect?: number;
28
30
  width?: number;
31
+ /** Media only: the square artwork's side, in px. */
32
+ size?: number;
29
33
  };
30
34
  text?: {
31
35
  headline?: UnitTextStyle;
@@ -63,6 +67,8 @@ interface UnitTheme {
63
67
  ctaShape?: 'pill' | 'rounded';
64
68
  /** Corner radius of a rounded call to action, in px. */
65
69
  ctaRadius?: number;
70
+ /** Call-to-action fill when it differs from the accent (the accent still colours emphasis). */
71
+ ctaBackground?: string;
66
72
  pillBackground?: string;
67
73
  pillForeground?: string;
68
74
  headlineFont?: UnitFont;
@@ -81,9 +87,11 @@ interface UnitTheme {
81
87
  width?: number;
82
88
  fade?: boolean;
83
89
  scrim?: string;
84
- /** Set to "none" to drop the backdrop in layouts that would draw it full-bleed. */
85
- compact?: 'none' | 'full';
90
+ /** In layouts that would draw it full-bleed: "none" drops it, "side" keeps it beside the text. */
91
+ compact?: 'none' | 'full' | 'side';
86
92
  };
93
+ /** A pattern over the background colour, drawn in the foreground colour: "dots". */
94
+ texture?: 'dots';
87
95
  /** Multiplies the layout's headline size, for display faces that run large or small. */
88
96
  headlineScale?: number;
89
97
  }
@@ -115,6 +123,8 @@ interface UnitContent {
115
123
  sizes?: unknown;
116
124
  frameEventSource?: string;
117
125
  };
126
+ /** Building-block data, keyed by block name (blocks/<name>.ts). */
127
+ blocks?: Record<string, unknown>;
118
128
  }
119
129
  interface AdUnit {
120
130
  type: UnitType | string;
@@ -150,7 +160,7 @@ interface HostTheme {
150
160
  * Every function here returns undefined (never throws) when the value can't
151
161
  * be measured, and nothing touches window or document at import time.
152
162
  */
153
- type UnitCapability = 'units.v1' | 'image' | 'frame.gfb1' | 'action.prompt' | 'connect.mcp';
163
+ type UnitCapability = 'units.v1' | 'image' | 'blocks.banner' | 'frame.gfb1' | 'action.prompt' | 'connect.mcp';
154
164
  interface SlotSize {
155
165
  width: number;
156
166
  maxHeight?: number;
@@ -553,6 +563,8 @@ interface McpConnect {
553
563
  name: string;
554
564
  /** Optional https icon URL. */
555
565
  iconUrl?: string;
566
+ /** Optional one-line card copy (1-120 characters); the card falls back to the ad copy. */
567
+ connectLine?: string;
556
568
  }
557
569
  /** What the SDK hands the host's `onConnect` callback. */
558
570
  interface McpConnectRequest {
@@ -9,8 +9,8 @@
9
9
  * from the server: a layout only selects one of the renderer's fixed
10
10
  * arrangements and sets numbers inside it.
11
11
  */
12
- type UnitType = 'text' | 'brand_card' | 'link_preview' | 'product_rail' | 'action_card' | 'connect_card' | 'rich_frame';
13
- type UnitArrangement = 'text' | 'stack' | 'split' | 'hero' | 'row' | 'rail';
12
+ type UnitType = 'text' | 'brand_card' | 'link_preview' | 'product_rail' | 'action_card' | 'connect_card' | 'media_card' | 'rich_frame' | 'storefront' | 'discover' | 'configurator';
13
+ type UnitArrangement = 'text' | 'stack' | 'split' | 'hero' | 'row' | 'rail' | 'media' | 'storefront' | 'discover' | 'configurator';
14
14
  interface UnitTextStyle {
15
15
  size?: number;
16
16
  lines?: number;
@@ -21,11 +21,15 @@ interface UnitLayout {
21
21
  minWidth: number;
22
22
  maxWidth?: number;
23
23
  arrangement: UnitArrangement;
24
+ /** Lowest height the engine assumes when it fits this layout into a slot's maxHeight. The SDK does not draw it. */
25
+ minHeight?: number;
24
26
  image?: {
25
27
  mode: 'hidden' | 'optional' | 'required';
26
28
  position?: 'top' | 'left' | 'right' | 'background';
27
29
  aspect?: number;
28
30
  width?: number;
31
+ /** Media only: the square artwork's side, in px. */
32
+ size?: number;
29
33
  };
30
34
  text?: {
31
35
  headline?: UnitTextStyle;
@@ -63,6 +67,8 @@ interface UnitTheme {
63
67
  ctaShape?: 'pill' | 'rounded';
64
68
  /** Corner radius of a rounded call to action, in px. */
65
69
  ctaRadius?: number;
70
+ /** Call-to-action fill when it differs from the accent (the accent still colours emphasis). */
71
+ ctaBackground?: string;
66
72
  pillBackground?: string;
67
73
  pillForeground?: string;
68
74
  headlineFont?: UnitFont;
@@ -81,9 +87,11 @@ interface UnitTheme {
81
87
  width?: number;
82
88
  fade?: boolean;
83
89
  scrim?: string;
84
- /** Set to "none" to drop the backdrop in layouts that would draw it full-bleed. */
85
- compact?: 'none' | 'full';
90
+ /** In layouts that would draw it full-bleed: "none" drops it, "side" keeps it beside the text. */
91
+ compact?: 'none' | 'full' | 'side';
86
92
  };
93
+ /** A pattern over the background colour, drawn in the foreground colour: "dots". */
94
+ texture?: 'dots';
87
95
  /** Multiplies the layout's headline size, for display faces that run large or small. */
88
96
  headlineScale?: number;
89
97
  }
@@ -115,6 +123,8 @@ interface UnitContent {
115
123
  sizes?: unknown;
116
124
  frameEventSource?: string;
117
125
  };
126
+ /** Building-block data, keyed by block name (blocks/<name>.ts). */
127
+ blocks?: Record<string, unknown>;
118
128
  }
119
129
  interface AdUnit {
120
130
  type: UnitType | string;
@@ -150,7 +160,7 @@ interface HostTheme {
150
160
  * Every function here returns undefined (never throws) when the value can't
151
161
  * be measured, and nothing touches window or document at import time.
152
162
  */
153
- type UnitCapability = 'units.v1' | 'image' | 'frame.gfb1' | 'action.prompt' | 'connect.mcp';
163
+ type UnitCapability = 'units.v1' | 'image' | 'blocks.banner' | 'frame.gfb1' | 'action.prompt' | 'connect.mcp';
154
164
  interface SlotSize {
155
165
  width: number;
156
166
  maxHeight?: number;
@@ -553,6 +563,8 @@ interface McpConnect {
553
563
  name: string;
554
564
  /** Optional https icon URL. */
555
565
  iconUrl?: string;
566
+ /** Optional one-line card copy (1-120 characters); the card falls back to the ad copy. */
567
+ connectLine?: string;
556
568
  }
557
569
  /** What the SDK hands the host's `onConnect` callback. */
558
570
  interface McpConnectRequest {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ai/api",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Gravity JS SDK for retrieving targeted advertisements",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",