@gravity-ai/api 1.3.0 → 1.3.1

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
@@ -214,7 +214,9 @@ Auto-detected fields vary by runtime:
214
214
  |-------|---------|---------------|
215
215
  | `ua` | `navigator.userAgent` | `gravity-js/x.x.x (OS arch; Runtime/ver)` |
216
216
  | `browser` | `"web"` | `"cli"` |
217
- | `device_type` | `"mobile"` or `"desktop"` | `"server"` (CI) or `"desktop"` |
217
+ | `device_type` | `"desktop"`, `"mobile"` or `"tablet"` | `"desktop"` |
218
+ | `os` | `"ios"`, `"android"`, `"macos"`, `"windows"`, `"linux"`, `"chromeos"` or `"other"` | `"macos"`, `"windows"`, `"linux"`, `"android"` or `"other"` |
219
+ | `os_version` | — | OS type and release, e.g. `"Darwin 24.1.0"` |
218
220
  | `timezone` | `Intl.DateTimeFormat` | `Intl.DateTimeFormat` |
219
221
  | `screen_width/height` | `screen.width/height` | `stdout.columns/rows` |
220
222
  | `viewport_width/height` | `innerWidth/Height` | `stdout.columns/rows` |
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-0HZXp9b_.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-0HZXp9b_.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-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';
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-0HZXp9b_.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-0HZXp9b_.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-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';
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.0",
42
+ version: "1.3.1",
43
43
  description: "Gravity JS SDK for retrieving targeted advertisements",
44
44
  main: "dist/index.js",
45
45
  module: "dist/index.mjs",
@@ -578,13 +578,33 @@ async function gravityContextAsync(overrides) {
578
578
  const consent = overrides.consent ?? (isBrowser ? await readCmpConsent() : void 0);
579
579
  return gravityContext(consent ? { ...overrides, consent } : overrides);
580
580
  }
581
+ function browserDeviceCategory(ua, maxTouchPoints) {
582
+ if (/iPad/.test(ua) || /Macintosh/.test(ua) && maxTouchPoints > 1) {
583
+ return { device_type: "tablet", os: "ios" };
584
+ }
585
+ if (/iPhone|iPod/.test(ua)) return { device_type: "mobile", os: "ios" };
586
+ if (/Android/.test(ua)) {
587
+ return { device_type: /Mobile/.test(ua) ? "mobile" : "tablet", os: "android" };
588
+ }
589
+ if (/CrOS/.test(ua)) return { device_type: "desktop", os: "chromeos" };
590
+ if (/Windows/.test(ua)) return { device_type: "desktop", os: "windows" };
591
+ if (/Macintosh|Mac OS X/.test(ua)) return { device_type: "desktop", os: "macos" };
592
+ if (/Linux/.test(ua)) return { device_type: "desktop", os: "linux" };
593
+ return { device_type: /Mobi/.test(ua) ? "mobile" : "desktop", os: "other" };
594
+ }
595
+ var NODE_OS_CATEGORY = {
596
+ darwin: "macos",
597
+ win32: "windows",
598
+ linux: "linux",
599
+ android: "android"
600
+ };
581
601
  function browserDevice() {
582
602
  const nav = typeof navigator !== "undefined" ? navigator : void 0;
583
603
  const win = typeof window !== "undefined" ? window : void 0;
584
604
  return {
585
605
  ua: nav?.userAgent || "",
586
606
  browser: "web",
587
- device_type: /Mobi|Android/i.test(nav?.userAgent || "") ? "mobile" : "desktop",
607
+ ...browserDeviceCategory(nav?.userAgent || "", nav?.maxTouchPoints || 0),
588
608
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
589
609
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
590
610
  language: nav?.language || "en",
@@ -623,9 +643,10 @@ function nodeDevice() {
623
643
  const env = typeof process !== "undefined" ? process.env : {};
624
644
  return {
625
645
  ua: `gravity-js/${SDK.version} (${os?.type() || "unknown"} ${os?.arch() || "unknown"}; ${runtimeTag})`,
626
- os: os ? `${os.type()} ${os.release()}` : void 0,
646
+ os: typeof process !== "undefined" && NODE_OS_CATEGORY[process.platform] || "other",
647
+ os_version: os ? `${os.type()} ${os.release()}` : void 0,
627
648
  browser: "cli",
628
- device_type: env.CI ? "server" : "desktop",
649
+ device_type: "desktop",
629
650
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
630
651
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
631
652
  language: env.LANG?.split(".")[0]?.replace("_", "-") || "en",
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.0",
11
+ version: "1.3.1",
12
12
  description: "Gravity JS SDK for retrieving targeted advertisements",
13
13
  main: "dist/index.js",
14
14
  module: "dist/index.mjs",
@@ -529,13 +529,33 @@ async function gravityContextAsync(overrides) {
529
529
  const consent = overrides.consent ?? (isBrowser ? await readCmpConsent() : void 0);
530
530
  return gravityContext(consent ? { ...overrides, consent } : overrides);
531
531
  }
532
+ function browserDeviceCategory(ua, maxTouchPoints) {
533
+ if (/iPad/.test(ua) || /Macintosh/.test(ua) && maxTouchPoints > 1) {
534
+ return { device_type: "tablet", os: "ios" };
535
+ }
536
+ if (/iPhone|iPod/.test(ua)) return { device_type: "mobile", os: "ios" };
537
+ if (/Android/.test(ua)) {
538
+ return { device_type: /Mobile/.test(ua) ? "mobile" : "tablet", os: "android" };
539
+ }
540
+ if (/CrOS/.test(ua)) return { device_type: "desktop", os: "chromeos" };
541
+ if (/Windows/.test(ua)) return { device_type: "desktop", os: "windows" };
542
+ if (/Macintosh|Mac OS X/.test(ua)) return { device_type: "desktop", os: "macos" };
543
+ if (/Linux/.test(ua)) return { device_type: "desktop", os: "linux" };
544
+ return { device_type: /Mobi/.test(ua) ? "mobile" : "desktop", os: "other" };
545
+ }
546
+ var NODE_OS_CATEGORY = {
547
+ darwin: "macos",
548
+ win32: "windows",
549
+ linux: "linux",
550
+ android: "android"
551
+ };
532
552
  function browserDevice() {
533
553
  const nav = typeof navigator !== "undefined" ? navigator : void 0;
534
554
  const win = typeof window !== "undefined" ? window : void 0;
535
555
  return {
536
556
  ua: nav?.userAgent || "",
537
557
  browser: "web",
538
- device_type: /Mobi|Android/i.test(nav?.userAgent || "") ? "mobile" : "desktop",
558
+ ...browserDeviceCategory(nav?.userAgent || "", nav?.maxTouchPoints || 0),
539
559
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
540
560
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
541
561
  language: nav?.language || "en",
@@ -574,9 +594,10 @@ function nodeDevice() {
574
594
  const env = typeof process !== "undefined" ? process.env : {};
575
595
  return {
576
596
  ua: `gravity-js/${SDK.version} (${os?.type() || "unknown"} ${os?.arch() || "unknown"}; ${runtimeTag})`,
577
- os: os ? `${os.type()} ${os.release()}` : void 0,
597
+ os: typeof process !== "undefined" && NODE_OS_CATEGORY[process.platform] || "other",
598
+ os_version: os ? `${os.type()} ${os.release()}` : void 0,
578
599
  browser: "cli",
579
- device_type: env.CI ? "server" : "desktop",
600
+ device_type: "desktop",
580
601
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
581
602
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
582
603
  language: env.LANG?.split(".")[0]?.replace("_", "-") || "en",
@@ -259,7 +259,8 @@ interface MessageObject {
259
259
  * ip: '192.168.1.1',
260
260
  * country: 'US',
261
261
  * ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...',
262
- * os: 'macOS'
262
+ * device_type: 'desktop',
263
+ * os: 'macos'
263
264
  * };
264
265
  * ```
265
266
  */
@@ -270,8 +271,10 @@ interface DeviceObject {
270
271
  ua?: string;
271
272
  /** ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB', 'DE') */
272
273
  country?: string;
273
- /** Operating system name (e.g., 'macOS', 'Windows', 'iOS', 'Android') */
274
- os?: string;
274
+ /** Device class: 'desktop', 'mobile' or 'tablet' */
275
+ device_type?: 'desktop' | 'mobile' | 'tablet' | (string & {});
276
+ /** Operating system category: 'ios', 'android', 'macos', 'windows', 'linux', 'chromeos' or 'other' */
277
+ os?: 'ios' | 'android' | 'macos' | 'windows' | 'linux' | 'chromeos' | 'other' | (string & {});
275
278
  /** Identifier for Advertisers (mobile advertising ID) */
276
279
  ifa?: string;
277
280
  /** Additional device properties (timezone, locale, browser, device_type, screen dimensions, etc.) */
@@ -259,7 +259,8 @@ interface MessageObject {
259
259
  * ip: '192.168.1.1',
260
260
  * country: 'US',
261
261
  * ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...',
262
- * os: 'macOS'
262
+ * device_type: 'desktop',
263
+ * os: 'macos'
263
264
  * };
264
265
  * ```
265
266
  */
@@ -270,8 +271,10 @@ interface DeviceObject {
270
271
  ua?: string;
271
272
  /** ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB', 'DE') */
272
273
  country?: string;
273
- /** Operating system name (e.g., 'macOS', 'Windows', 'iOS', 'Android') */
274
- os?: string;
274
+ /** Device class: 'desktop', 'mobile' or 'tablet' */
275
+ device_type?: 'desktop' | 'mobile' | 'tablet' | (string & {});
276
+ /** Operating system category: 'ios', 'android', 'macos', 'windows', 'linux', 'chromeos' or 'other' */
277
+ os?: 'ios' | 'android' | 'macos' | 'windows' | 'linux' | 'chromeos' | 'other' | (string & {});
275
278
  /** Identifier for Advertisers (mobile advertising ID) */
276
279
  ifa?: string;
277
280
  /** Additional device properties (timezone, locale, browser, device_type, screen dimensions, etc.) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ai/api",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Gravity JS SDK for retrieving targeted advertisements",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",