@gravity-ai/api 1.2.0 → 1.3.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 +5 -1
- package/dist/{chunk-EBO3CZXG.mjs → chunk-F4FGMBDK.mjs} +5 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +191 -30
- package/dist/index.mjs +187 -30
- package/dist/opentui.d.mts +3 -2
- package/dist/opentui.d.ts +3 -2
- package/dist/opentui.mjs +1 -1
- package/dist/{types-CnuFH98L.d.mts → types-0HZXp9b_.d.mts} +321 -22
- package/dist/{types-CnuFH98L.d.ts → types-0HZXp9b_.d.ts} +321 -22
- package/package.json +6 -14
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ Ad latency never blocks the chat response.
|
|
|
109
109
|
|
|
110
110
|
## Server — Python
|
|
111
111
|
|
|
112
|
-
For Python backends (FastAPI, Django, Flask), use the [`gravity-
|
|
112
|
+
For Python backends (FastAPI, Django, Flask), use the [`gravity-sdk`](https://docs.trygravity.ai/sdks/python) package:
|
|
113
113
|
|
|
114
114
|
```bash
|
|
115
115
|
pip install gravity-sdk
|
|
@@ -179,6 +179,10 @@ Fetch ads. **Never throws.** Returns `{ ads: [] }` on any failure.
|
|
|
179
179
|
|
|
180
180
|
**Returns:** `{ ads: Ad[], status: number, elapsed: string, requestBody: object, error?: string }`
|
|
181
181
|
|
|
182
|
+
Set `supportsMcpConnect: true` on a placement only when your app can connect an MCP server on click. Eligible ads then carry `connect: { type: 'mcp', id, serverUrl, name, iconUrl? }` and the button copy in `cta`; the types `McpConnect`, `McpConnectRequest`, `McpConnectResult` and `McpConnectHandler` describe the contract.
|
|
183
|
+
|
|
184
|
+
Each placement also declares the unit capabilities a Gravity renderer draws (`units.v1`, `image`, `frame.gfb1` while frames are on, `action.prompt` and `connect.mcp` when the placement opts in), unless `supportsSpec` is `false`. Ads then may carry a `unit` that `@gravity-ai/react` and `@gravity-ai/ui` draw. When `getAds` runs in a browser it also sends the page's font and theme. Any `slot`, `text`, `theme` or `capabilities` you set on a placement is sent as is; in a browser, `getPlacementContext(element)` from `@gravity-ai/react` fills them from the ad's container.
|
|
185
|
+
|
|
182
186
|
### `gravityContext(overrides)`
|
|
183
187
|
|
|
184
188
|
Client-side. Collects device + user context. Returns a plain object to include in your request body.
|
|
@@ -6,7 +6,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
7
|
});
|
|
8
8
|
var __commonJS = (cb, mod) => function __require2() {
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw mod = 0, e;
|
|
13
|
+
}
|
|
10
14
|
};
|
|
11
15
|
|
|
12
16
|
export {
|
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 { e as AdLayout, h as ApiErrorResponse, D as DeviceObject,
|
|
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';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gravity ad client.
|
|
@@ -506,4 +506,5 @@ declare class GravityPixel {
|
|
|
506
506
|
*/
|
|
507
507
|
declare function gravityPixel(opts: GravityPixelConfig): GravityPixel;
|
|
508
508
|
|
|
509
|
-
export { Ad, AdParams, Client,
|
|
509
|
+
export { Ad, AdParams, Client, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityPixel, IncomingAdRequest, MessageObject, PlacementObject, detectCmpConsent, extractClientIp, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, readCmpConsent, toGravityMessages };
|
|
510
|
+
export type { ClientParams, ConsentSignal, GravityPixelConfig, HashedIdentity, RawIdentity };
|
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 { e as AdLayout, h as ApiErrorResponse, D as DeviceObject,
|
|
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';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gravity ad client.
|
|
@@ -506,4 +506,5 @@ declare class GravityPixel {
|
|
|
506
506
|
*/
|
|
507
507
|
declare function gravityPixel(opts: GravityPixelConfig): GravityPixel;
|
|
508
508
|
|
|
509
|
-
export { Ad, AdParams, Client,
|
|
509
|
+
export { Ad, AdParams, Client, Gravity, GravityAdsOptions, GravityAdsResult, GravityContext, GravityContextOverrides, GravityPixel, IncomingAdRequest, MessageObject, PlacementObject, detectCmpConsent, extractClientIp, gravityAds, gravityContext, gravityContextAsync, gravityPixel, hashPii, readCmpConsent, toGravityMessages };
|
|
510
|
+
export type { ClientParams, ConsentSignal, GravityPixelConfig, HashedIdentity, RawIdentity };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw mod = 0, e;
|
|
13
|
+
}
|
|
10
14
|
};
|
|
11
15
|
var __export = (target, all) => {
|
|
12
16
|
for (var name in all)
|
|
@@ -35,7 +39,7 @@ var require_package = __commonJS({
|
|
|
35
39
|
"package.json"(exports2, module2) {
|
|
36
40
|
module2.exports = {
|
|
37
41
|
name: "@gravity-ai/api",
|
|
38
|
-
version: "1.
|
|
42
|
+
version: "1.3.0",
|
|
39
43
|
description: "Gravity JS SDK for retrieving targeted advertisements",
|
|
40
44
|
main: "dist/index.js",
|
|
41
45
|
module: "dist/index.mjs",
|
|
@@ -81,15 +85,7 @@ var require_package = __commonJS({
|
|
|
81
85
|
],
|
|
82
86
|
author: "Gravity Team",
|
|
83
87
|
license: "MIT",
|
|
84
|
-
homepage: "https://
|
|
85
|
-
repository: {
|
|
86
|
-
type: "git",
|
|
87
|
-
url: "git+https://github.com/Try-Gravity/gravity-js.git",
|
|
88
|
-
directory: "packages/api"
|
|
89
|
-
},
|
|
90
|
-
bugs: {
|
|
91
|
-
url: "https://github.com/Try-Gravity/gravity-js/issues"
|
|
92
|
-
},
|
|
88
|
+
homepage: "https://docs.trygravity.ai/sdks/javascript",
|
|
93
89
|
publishConfig: {
|
|
94
90
|
access: "public"
|
|
95
91
|
},
|
|
@@ -105,13 +101,13 @@ var require_package = __commonJS({
|
|
|
105
101
|
}
|
|
106
102
|
},
|
|
107
103
|
dependencies: {
|
|
108
|
-
axios: "^1.
|
|
104
|
+
axios: "^1.21.0"
|
|
109
105
|
},
|
|
110
106
|
devDependencies: {
|
|
111
|
-
"@opentui/core": "^0.
|
|
112
|
-
tsup: "^
|
|
107
|
+
"@opentui/core": "^0.8.0",
|
|
108
|
+
tsup: "^9.0.0",
|
|
113
109
|
typescript: "^5.3.3",
|
|
114
|
-
vitest: "^1.
|
|
110
|
+
vitest: "^4.1.12"
|
|
115
111
|
}
|
|
116
112
|
};
|
|
117
113
|
}
|
|
@@ -135,6 +131,156 @@ __export(index_exports, {
|
|
|
135
131
|
});
|
|
136
132
|
module.exports = __toCommonJS(index_exports);
|
|
137
133
|
|
|
134
|
+
// sdk.ts
|
|
135
|
+
var pkg = (() => {
|
|
136
|
+
try {
|
|
137
|
+
return require_package();
|
|
138
|
+
} catch {
|
|
139
|
+
return { name: "@gravity-ai/api", version: "0.0.0" };
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
var SDK = { name: pkg.name, version: pkg.version };
|
|
143
|
+
|
|
144
|
+
// ../ui/src/theme.ts
|
|
145
|
+
var GRAVITY_DARK_VARS = {
|
|
146
|
+
"--gravity-bg": "#1F1F23",
|
|
147
|
+
"--gravity-text": "#FAFAFA",
|
|
148
|
+
"--gravity-text-muted": "#A1A1AA",
|
|
149
|
+
"--gravity-border": "#3F3F46",
|
|
150
|
+
"--gravity-muted": "#27272A",
|
|
151
|
+
"--background": "240 6% 13%",
|
|
152
|
+
"--foreground": "0 0% 98%",
|
|
153
|
+
"--card": "240 6% 13%",
|
|
154
|
+
"--card-foreground": "0 0% 98%",
|
|
155
|
+
"--muted": "240 5% 16%",
|
|
156
|
+
"--muted-foreground": "240 5% 65%",
|
|
157
|
+
"--border": "240 5% 26%"
|
|
158
|
+
};
|
|
159
|
+
var GRAVITY_DARK_WIDGET_VARS = Object.fromEntries(
|
|
160
|
+
Object.entries(GRAVITY_DARK_VARS).filter(
|
|
161
|
+
([k]) => k.startsWith("--gravity-")
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
function parseColor(value) {
|
|
165
|
+
const m = value.match(/rgba?\(([^)]+)\)/);
|
|
166
|
+
if (!m) return null;
|
|
167
|
+
const parts = m[1].split(",").map((p) => parseFloat(p.trim()));
|
|
168
|
+
if (parts.length < 3 || parts.some((n) => Number.isNaN(n))) return null;
|
|
169
|
+
return [parts[0], parts[1], parts[2], parts.length >= 4 ? parts[3] : 1];
|
|
170
|
+
}
|
|
171
|
+
function luminance(r, g, b) {
|
|
172
|
+
return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
|
|
173
|
+
}
|
|
174
|
+
function effectiveBackground(el) {
|
|
175
|
+
let node = el;
|
|
176
|
+
while (node) {
|
|
177
|
+
if (!node.hasAttribute("data-gravity-ad")) {
|
|
178
|
+
const bg = getComputedStyle(node).backgroundColor;
|
|
179
|
+
const c = bg ? parseColor(bg) : null;
|
|
180
|
+
if (c && c[3] > 0.1) return [c[0], c[1], c[2]];
|
|
181
|
+
}
|
|
182
|
+
node = node.parentElement;
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
function hostIsDark(el) {
|
|
187
|
+
try {
|
|
188
|
+
const bg = effectiveBackground(el);
|
|
189
|
+
if (bg) return luminance(bg[0], bg[1], bg[2]) < 0.4;
|
|
190
|
+
const text = parseColor(getComputedStyle(el).color);
|
|
191
|
+
if (text) return luminance(text[0], text[1], text[2]) > 0.6;
|
|
192
|
+
return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches;
|
|
193
|
+
} catch {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ../ui/src/units/collect.ts
|
|
199
|
+
var SAMPLE = "Find the right tool for your team and ship your next project faster. Try it free today.";
|
|
200
|
+
var SAMPLE_PX = 100;
|
|
201
|
+
var metricsCache = /* @__PURE__ */ new Map();
|
|
202
|
+
function hasDom() {
|
|
203
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
204
|
+
}
|
|
205
|
+
function hostElement(el) {
|
|
206
|
+
if (el) return el;
|
|
207
|
+
return hasDom() ? document.body ?? document.documentElement : null;
|
|
208
|
+
}
|
|
209
|
+
function primaryFamily(stack) {
|
|
210
|
+
const first = stack.split(",")[0]?.trim().replace(/^["']|["']$/g, "");
|
|
211
|
+
return first && first.length <= 80 ? first : void 0;
|
|
212
|
+
}
|
|
213
|
+
function hex(value) {
|
|
214
|
+
const v = value.trim();
|
|
215
|
+
if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v)) {
|
|
216
|
+
return (v.length === 4 ? "#" + [...v.slice(1)].map((c2) => c2 + c2).join("") : v).toUpperCase();
|
|
217
|
+
}
|
|
218
|
+
const c = parseColor(v);
|
|
219
|
+
if (!c || c[3] === 0) return void 0;
|
|
220
|
+
return "#" + c.slice(0, 3).map((n) => Math.round(Math.min(255, Math.max(0, n))).toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
221
|
+
}
|
|
222
|
+
function px(value, rootPx) {
|
|
223
|
+
const m = /^(-?[\d.]+)(px|rem)$/.exec(value.trim());
|
|
224
|
+
if (!m) return void 0;
|
|
225
|
+
const n = parseFloat(m[1]) * (m[2] === "rem" ? rootPx : 1);
|
|
226
|
+
return Number.isFinite(n) && n >= 0 ? Math.round(n) : void 0;
|
|
227
|
+
}
|
|
228
|
+
function measureText(el) {
|
|
229
|
+
try {
|
|
230
|
+
const node = hostElement(el);
|
|
231
|
+
if (!node) return void 0;
|
|
232
|
+
const stack = getComputedStyle(node).fontFamily;
|
|
233
|
+
const fontFamily = stack ? primaryFamily(stack) : void 0;
|
|
234
|
+
if (!fontFamily) return void 0;
|
|
235
|
+
const cached = metricsCache.get(stack);
|
|
236
|
+
if (cached) return cached;
|
|
237
|
+
const ctx = document.createElement("canvas").getContext("2d");
|
|
238
|
+
if (!ctx) return { fontFamily };
|
|
239
|
+
const measure = (weight) => {
|
|
240
|
+
ctx.font = weight + " " + SAMPLE_PX + "px " + stack;
|
|
241
|
+
return Math.round(ctx.measureText(SAMPLE).width / (SAMPLE.length * SAMPLE_PX) * 1e3) / 1e3;
|
|
242
|
+
};
|
|
243
|
+
const regular = measure(400);
|
|
244
|
+
const bold = measure(700);
|
|
245
|
+
if (!(regular > 0) || !(bold > 0)) return { fontFamily };
|
|
246
|
+
const metrics = { fontFamily, avgCharEm: { regular, bold } };
|
|
247
|
+
const fonts = document.fonts;
|
|
248
|
+
if (typeof fonts?.check !== "function" || fonts.check(SAMPLE_PX + "px " + stack)) metricsCache.set(stack, metrics);
|
|
249
|
+
return metrics;
|
|
250
|
+
} catch {
|
|
251
|
+
return void 0;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function readHostTheme(el) {
|
|
255
|
+
try {
|
|
256
|
+
const node = hostElement(el);
|
|
257
|
+
if (!node) return void 0;
|
|
258
|
+
const cs = getComputedStyle(node);
|
|
259
|
+
const theme = { scheme: hostIsDark(node) ? "dark" : "light" };
|
|
260
|
+
const bg = effectiveBackground(node);
|
|
261
|
+
if (bg) theme.background = hex("rgb(" + bg.join(",") + ")");
|
|
262
|
+
const fg = hex(cs.color);
|
|
263
|
+
if (fg) theme.foreground = fg;
|
|
264
|
+
const accent = hex(cs.getPropertyValue("--gravity-accent"));
|
|
265
|
+
if (accent) theme.accent = accent;
|
|
266
|
+
const rootPx = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
267
|
+
const radius = px(cs.getPropertyValue("--gravity-radius"), rootPx);
|
|
268
|
+
if (radius !== void 0) theme.radius = radius;
|
|
269
|
+
const family = cs.fontFamily ? primaryFamily(cs.fontFamily) : void 0;
|
|
270
|
+
if (family) theme.fontFamily = family;
|
|
271
|
+
return theme;
|
|
272
|
+
} catch {
|
|
273
|
+
return void 0;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false } = {}) {
|
|
277
|
+
const caps = ["units.v1", "image"];
|
|
278
|
+
if (frames) caps.push("frame.gfb1");
|
|
279
|
+
if (promptAction) caps.push("action.prompt");
|
|
280
|
+
if (mcpConnect) caps.push("connect.mcp");
|
|
281
|
+
return caps;
|
|
282
|
+
}
|
|
283
|
+
|
|
138
284
|
// ads.ts
|
|
139
285
|
var DEFAULT_GRAVITY_API = "https://server.trygravity.ai/api/v1/ad";
|
|
140
286
|
var DEFAULT_TIMEOUT_MS = 4e3;
|
|
@@ -158,6 +304,23 @@ function extractClientIp(req) {
|
|
|
158
304
|
if (req.ip) return req.ip;
|
|
159
305
|
return void 0;
|
|
160
306
|
}
|
|
307
|
+
function withUnitContext(placements, frames) {
|
|
308
|
+
if (!Array.isArray(placements)) return placements;
|
|
309
|
+
const text = measureText();
|
|
310
|
+
const theme = readHostTheme();
|
|
311
|
+
return placements.map(
|
|
312
|
+
(p) => p && typeof p === "object" ? {
|
|
313
|
+
...text ? { text } : {},
|
|
314
|
+
...theme ? { theme } : {},
|
|
315
|
+
capabilities: capabilitiesFor({
|
|
316
|
+
frames,
|
|
317
|
+
promptAction: p.supportsPromptAction === true,
|
|
318
|
+
mcpConnect: p.supportsMcpConnect === true
|
|
319
|
+
}),
|
|
320
|
+
...p
|
|
321
|
+
} : p
|
|
322
|
+
);
|
|
323
|
+
}
|
|
161
324
|
async function gravityAds(req, messages, placements, opts = {}) {
|
|
162
325
|
const apiKey = opts.apiKey || (typeof process !== "undefined" ? process.env?.GRAVITY_API_KEY : void 0);
|
|
163
326
|
const gravityApi = opts.gravityApi || DEFAULT_GRAVITY_API;
|
|
@@ -169,10 +332,13 @@ async function gravityAds(req, messages, placements, opts = {}) {
|
|
|
169
332
|
const clientUser = ctx?.user || {};
|
|
170
333
|
const clientDevice = ctx?.device || {};
|
|
171
334
|
const clientIp = extractClientIp(req);
|
|
335
|
+
const supportsSpec = opts.supportsSpec ?? true;
|
|
336
|
+
const frames = opts.enableFrames ?? supportsSpec;
|
|
172
337
|
const body = {
|
|
338
|
+
sdk: SDK,
|
|
173
339
|
messages: toGravityMessages(messages),
|
|
174
340
|
sessionId: ctx?.sessionId,
|
|
175
|
-
placements,
|
|
341
|
+
placements: supportsSpec ? withUnitContext(placements, frames) : placements,
|
|
176
342
|
user: {
|
|
177
343
|
...clientUser,
|
|
178
344
|
id: clientUser.id || clientUser.userId || "anonymous"
|
|
@@ -188,12 +354,13 @@ async function gravityAds(req, messages, placements, opts = {}) {
|
|
|
188
354
|
body.relevancy = opts.relevancy ?? 0.2;
|
|
189
355
|
body.testAd = opts.production === true ? false : true;
|
|
190
356
|
if (body.testAd && opts.alwaysReturn === true) body.alwaysReturn = true;
|
|
191
|
-
|
|
357
|
+
if (body.testAd && opts.testAdFormat === "action") body.testAdFormat = "action";
|
|
192
358
|
body.supportsSpec = supportsSpec;
|
|
193
359
|
if (supportsSpec) body.specCapabilities = opts.specCapabilities ?? "web1";
|
|
194
|
-
if (
|
|
360
|
+
if (frames) body.supportsFrames = true;
|
|
195
361
|
if (body.testAd && opts.adLayout) body.adLayout = opts.adLayout;
|
|
196
362
|
if (opts.excludedTopics) body.excludedTopics = opts.excludedTopics;
|
|
363
|
+
if (opts.usage) body.usage = opts.usage;
|
|
197
364
|
const start = performance.now();
|
|
198
365
|
try {
|
|
199
366
|
const res = await fetch(gravityApi, {
|
|
@@ -455,7 +622,7 @@ function nodeDevice() {
|
|
|
455
622
|
const rows = typeof process !== "undefined" ? process.stdout?.rows || 24 : 24;
|
|
456
623
|
const env = typeof process !== "undefined" ? process.env : {};
|
|
457
624
|
return {
|
|
458
|
-
ua: `gravity-js/${
|
|
625
|
+
ua: `gravity-js/${SDK.version} (${os?.type() || "unknown"} ${os?.arch() || "unknown"}; ${runtimeTag})`,
|
|
459
626
|
os: os ? `${os.type()} ${os.release()}` : void 0,
|
|
460
627
|
browser: "cli",
|
|
461
628
|
device_type: env.CI ? "server" : "desktop",
|
|
@@ -475,13 +642,6 @@ function nodeDevice() {
|
|
|
475
642
|
is_ci: !!env.CI
|
|
476
643
|
};
|
|
477
644
|
}
|
|
478
|
-
var PKG_VERSION = (() => {
|
|
479
|
-
try {
|
|
480
|
-
return require_package().version;
|
|
481
|
-
} catch {
|
|
482
|
-
return "0.0.0";
|
|
483
|
-
}
|
|
484
|
-
})();
|
|
485
645
|
|
|
486
646
|
// client.ts
|
|
487
647
|
var import_axios = __toESM(require("axios"));
|
|
@@ -585,6 +745,7 @@ var Client = class {
|
|
|
585
745
|
const supportsSpec = params.supportsSpec ?? true;
|
|
586
746
|
const { enableFrames, ...requestParams } = params;
|
|
587
747
|
const body = {
|
|
748
|
+
sdk: SDK,
|
|
588
749
|
...requestParams,
|
|
589
750
|
...enableFrames ?? supportsSpec ? { supportsFrames: true } : {},
|
|
590
751
|
supportsSpec,
|
|
@@ -646,8 +807,8 @@ async function sha256Hex(value) {
|
|
|
646
807
|
try {
|
|
647
808
|
const bytes = new TextEncoder().encode(value);
|
|
648
809
|
const digest = await subtle.digest("SHA-256", bytes);
|
|
649
|
-
const
|
|
650
|
-
return
|
|
810
|
+
const hex2 = Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
811
|
+
return hex2;
|
|
651
812
|
} catch {
|
|
652
813
|
return void 0;
|
|
653
814
|
}
|
|
@@ -677,8 +838,8 @@ async function hashPii(values) {
|
|
|
677
838
|
|
|
678
839
|
// gravity-pixel.ts
|
|
679
840
|
function uuid(prefix) {
|
|
680
|
-
const
|
|
681
|
-
return prefix +
|
|
841
|
+
const hex2 = () => Math.random().toString(36).slice(2, 10);
|
|
842
|
+
return prefix + hex2() + hex2();
|
|
682
843
|
}
|
|
683
844
|
function nowMs() {
|
|
684
845
|
return Date.now();
|