@gravity-ai/react 0.1.0 → 1.0.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
@@ -23,7 +23,11 @@ function ChatMessage({ messages }) {
23
23
  const [ad, setAd] = useState(null);
24
24
 
25
25
  useEffect(() => {
26
- client.getAd({ messages }).then(setAd);
26
+ client.contextualAd({
27
+ messages,
28
+ sessionId: 'session-123',
29
+ userId: 'user-456',
30
+ }).then(res => setAd(res?.ads[0] || null));
27
31
  }, [messages]);
28
32
 
29
33
  return (
@@ -45,7 +49,7 @@ A fully-styled, customizable ad banner component.
45
49
  import { AdBanner } from '@gravity-ai/react';
46
50
 
47
51
  <AdBanner
48
- ad={adResponse}
52
+ ad={ad} // Takes a single ad object (e.g., response.ads[0])
49
53
  theme="dark" // 'light' | 'dark' | 'minimal' | 'branded'
50
54
  size="medium" // 'small' | 'medium' | 'large' | 'responsive'
51
55
  showLabel={true} // Show "Sponsored" label
@@ -60,7 +64,7 @@ import { AdBanner } from '@gravity-ai/react';
60
64
 
61
65
  | Prop | Type | Default | Description |
62
66
  |------|------|---------|-------------|
63
- | `ad` | `AdResponse \| null` | required | The ad response from Gravity API |
67
+ | `ad` | `AdResponse \| null` | required | A single ad object (e.g., `response.ads[0]`) |
64
68
  | `theme` | `'light' \| 'dark' \| 'minimal' \| 'branded'` | `'light'` | Visual theme preset |
65
69
  | `size` | `'small' \| 'medium' \| 'large' \| 'responsive'` | `'medium'` | Size preset |
66
70
  | `className` | `string` | - | Custom class name for container |
@@ -96,7 +100,7 @@ import { AdText } from '@gravity-ai/react';
96
100
 
97
101
  | Prop | Type | Default | Description |
98
102
  |------|------|---------|-------------|
99
- | `ad` | `AdResponse \| null` | required | The ad response from Gravity API |
103
+ | `ad` | `AdResponse \| null` | required | A single ad object (e.g., `response.ads[0]`) |
100
104
  | `className` | `string` | - | Custom class name |
101
105
  | `style` | `CSSProperties` | - | Custom inline styles |
102
106
  | `fallback` | `ReactNode` | `null` | Content when ad is null |
package/dist/index.d.mts CHANGED
@@ -4,12 +4,29 @@ import { CSSProperties, ReactNode } from 'react';
4
4
  /**
5
5
  * Ad response from the Gravity API
6
6
  * This mirrors the type from @gravity-ai/api for convenience
7
+ * Includes optional v1 fields for backward compatibility
7
8
  */
8
9
  interface AdResponse {
10
+ /** The advertisement copy text */
9
11
  adText: string;
12
+ /** Impression tracking URL */
10
13
  impUrl?: string;
14
+ /** Click-through tracking URL */
11
15
  clickUrl?: string;
16
+ /** Payout amount in USD */
12
17
  payout?: number;
18
+ /** Unique ad identifier (v1) */
19
+ adId?: string;
20
+ /** Ad title (v1) */
21
+ title?: string;
22
+ /** Brand/advertiser name (v1) */
23
+ brandName?: string;
24
+ /** Brand logo image URL (v1) */
25
+ brandImage?: string;
26
+ /** Landing page URL (v1) */
27
+ url?: string;
28
+ /** Favicon URL (v1) */
29
+ favicon?: string;
13
30
  }
14
31
  /**
15
32
  * Visual theme presets for the ad banner
@@ -99,8 +116,8 @@ interface AdTextProps {
99
116
  * const [ad, setAd] = useState(null);
100
117
  *
101
118
  * useEffect(() => {
102
- * client.getAd({ messages }).then(setAd);
103
- * }, []);
119
+ * client.contextualAd({ messages }).then(res => setAd(res?.ads[0] || null));
120
+ * }, [messages]);
104
121
  *
105
122
  * return (
106
123
  * <AdBanner
package/dist/index.d.ts CHANGED
@@ -4,12 +4,29 @@ import { CSSProperties, ReactNode } from 'react';
4
4
  /**
5
5
  * Ad response from the Gravity API
6
6
  * This mirrors the type from @gravity-ai/api for convenience
7
+ * Includes optional v1 fields for backward compatibility
7
8
  */
8
9
  interface AdResponse {
10
+ /** The advertisement copy text */
9
11
  adText: string;
12
+ /** Impression tracking URL */
10
13
  impUrl?: string;
14
+ /** Click-through tracking URL */
11
15
  clickUrl?: string;
16
+ /** Payout amount in USD */
12
17
  payout?: number;
18
+ /** Unique ad identifier (v1) */
19
+ adId?: string;
20
+ /** Ad title (v1) */
21
+ title?: string;
22
+ /** Brand/advertiser name (v1) */
23
+ brandName?: string;
24
+ /** Brand logo image URL (v1) */
25
+ brandImage?: string;
26
+ /** Landing page URL (v1) */
27
+ url?: string;
28
+ /** Favicon URL (v1) */
29
+ favicon?: string;
13
30
  }
14
31
  /**
15
32
  * Visual theme presets for the ad banner
@@ -99,8 +116,8 @@ interface AdTextProps {
99
116
  * const [ad, setAd] = useState(null);
100
117
  *
101
118
  * useEffect(() => {
102
- * client.getAd({ messages }).then(setAd);
103
- * }, []);
119
+ * client.contextualAd({ messages }).then(res => setAd(res?.ads[0] || null));
120
+ * }, [messages]);
104
121
  *
105
122
  * return (
106
123
  * <AdBanner
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ai/react",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "React components for rendering Gravity AI advertisements",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -72,4 +72,3 @@
72
72
  "vitest": "^1.2.1"
73
73
  }
74
74
  }
75
-