@gravity-ai/api 1.3.2 → 1.5.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 -2
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +244 -9
- package/dist/index.mjs +244 -9
- package/dist/opentui.js +1 -1
- package/dist/opentui.mjs +1 -1
- package/dist/{types-DaB2KQT1.d.mts → types-FOlyOpps.d.mts} +35 -9
- package/dist/{types-DaB2KQT1.d.ts → types-FOlyOpps.d.ts} +35 -9
- package/package.json +1 -1
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
|
-
|
|
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-
|
|
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-
|
|
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-FOlyOpps.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-FOlyOpps.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gravity ad client.
|
|
@@ -371,6 +371,10 @@ declare function hashPii(values: RawIdentity): Promise<HashedIdentity>;
|
|
|
371
371
|
*
|
|
372
372
|
* - TCF v2: `window.__tcfapi(command, version, callback)`
|
|
373
373
|
* - US Privacy (CCPA): `window.__uspapi(command, version, callback)`
|
|
374
|
+
* - GPP v1.1: `window.__gpp(command, callback, parameter, version)`
|
|
375
|
+
*
|
|
376
|
+
* It also reads the browser's Global Privacy Control signal
|
|
377
|
+
* (`navigator.globalPrivacyControl`).
|
|
374
378
|
*
|
|
375
379
|
* This module reads those APIs (when present) and shapes the result into the
|
|
376
380
|
* `consent` object the Gravity ad API accepts, so consent collected by the
|
|
@@ -385,6 +389,12 @@ interface ConsentSignal {
|
|
|
385
389
|
tcfString?: string;
|
|
386
390
|
/** IAB US Privacy (CCPA) string, e.g. `"1YNN"`. */
|
|
387
391
|
usPrivacy?: string;
|
|
392
|
+
/** IAB Global Privacy Platform (GPP) string from the publisher's CMP. */
|
|
393
|
+
gpp?: string;
|
|
394
|
+
/** GPP section ids that apply to this request (`applicableSections`). */
|
|
395
|
+
gppSid?: number[];
|
|
396
|
+
/** Global Privacy Control. Only `true` is a signal; omit it otherwise. */
|
|
397
|
+
gpc?: boolean;
|
|
388
398
|
}
|
|
389
399
|
/**
|
|
390
400
|
* Synchronously return the current CMP consent signal, or `undefined` when
|
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 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-
|
|
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-FOlyOpps.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-FOlyOpps.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gravity ad client.
|
|
@@ -371,6 +371,10 @@ declare function hashPii(values: RawIdentity): Promise<HashedIdentity>;
|
|
|
371
371
|
*
|
|
372
372
|
* - TCF v2: `window.__tcfapi(command, version, callback)`
|
|
373
373
|
* - US Privacy (CCPA): `window.__uspapi(command, version, callback)`
|
|
374
|
+
* - GPP v1.1: `window.__gpp(command, callback, parameter, version)`
|
|
375
|
+
*
|
|
376
|
+
* It also reads the browser's Global Privacy Control signal
|
|
377
|
+
* (`navigator.globalPrivacyControl`).
|
|
374
378
|
*
|
|
375
379
|
* This module reads those APIs (when present) and shapes the result into the
|
|
376
380
|
* `consent` object the Gravity ad API accepts, so consent collected by the
|
|
@@ -385,6 +389,12 @@ interface ConsentSignal {
|
|
|
385
389
|
tcfString?: string;
|
|
386
390
|
/** IAB US Privacy (CCPA) string, e.g. `"1YNN"`. */
|
|
387
391
|
usPrivacy?: string;
|
|
392
|
+
/** IAB Global Privacy Platform (GPP) string from the publisher's CMP. */
|
|
393
|
+
gpp?: string;
|
|
394
|
+
/** GPP section ids that apply to this request (`applicableSections`). */
|
|
395
|
+
gppSid?: number[];
|
|
396
|
+
/** Global Privacy Control. Only `true` is a signal; omit it otherwise. */
|
|
397
|
+
gpc?: boolean;
|
|
388
398
|
}
|
|
389
399
|
/**
|
|
390
400
|
* Synchronously return the current CMP consent signal, or `undefined` when
|
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.
|
|
42
|
+
version: "1.5.0",
|
|
43
43
|
description: "Gravity JS SDK for retrieving targeted advertisements",
|
|
44
44
|
main: "dist/index.js",
|
|
45
45
|
module: "dist/index.mjs",
|
|
@@ -141,6 +141,195 @@ var pkg = (() => {
|
|
|
141
141
|
})();
|
|
142
142
|
var SDK = { name: pkg.name, version: pkg.version };
|
|
143
143
|
|
|
144
|
+
// ../ui/src/psp.ts
|
|
145
|
+
var SPEC_LINK_PROTOCOLS = ["http:", "https:", "mailto:"];
|
|
146
|
+
var SHADCN_CHANNEL_DEFAULTS = {
|
|
147
|
+
background: "0 0% 100%",
|
|
148
|
+
foreground: "240 6% 10%",
|
|
149
|
+
card: "0 0% 100%",
|
|
150
|
+
"card-foreground": "240 6% 10%",
|
|
151
|
+
primary: "221 83% 53%",
|
|
152
|
+
"primary-foreground": "0 0% 100%",
|
|
153
|
+
muted: "240 5% 96%",
|
|
154
|
+
"muted-foreground": "240 5% 47%",
|
|
155
|
+
accent: "221 83% 53%",
|
|
156
|
+
"accent-foreground": "0 0% 100%",
|
|
157
|
+
border: "240 5% 90%"
|
|
158
|
+
};
|
|
159
|
+
var SHADCN_HOST_TOKENS = Object.keys(SHADCN_CHANNEL_DEFAULTS);
|
|
160
|
+
var PSP1_COLOR_TOKENS = [
|
|
161
|
+
"background",
|
|
162
|
+
"foreground",
|
|
163
|
+
"card",
|
|
164
|
+
"card-foreground",
|
|
165
|
+
"primary",
|
|
166
|
+
"primary-foreground",
|
|
167
|
+
"muted",
|
|
168
|
+
"muted-foreground",
|
|
169
|
+
"accent",
|
|
170
|
+
"accent-foreground",
|
|
171
|
+
"border"
|
|
172
|
+
];
|
|
173
|
+
var PSP1_MAX_FONT_SIZE_PX = 20;
|
|
174
|
+
var PSP1_MAX_SPACING_PX = 32;
|
|
175
|
+
var PSP1_MAX_IMAGE_PX = 64;
|
|
176
|
+
var ok = null;
|
|
177
|
+
function err(msg) {
|
|
178
|
+
return msg;
|
|
179
|
+
}
|
|
180
|
+
var PX_RE = /^\d+(\.\d+)?px$/;
|
|
181
|
+
var PX_LIST_RE = /^\d+(\.\d+)?px( \d+(\.\d+)?px){0,3}$/;
|
|
182
|
+
var EM_RE = /^-?\d+(\.\d+)?em$/;
|
|
183
|
+
var TOKEN_RE = new RegExp(
|
|
184
|
+
`^\\$(${PSP1_COLOR_TOKENS.join("|")})(/(100|[1-9]?[0-9]))?$`
|
|
185
|
+
);
|
|
186
|
+
function pxNumber(value) {
|
|
187
|
+
if (typeof value === "number") return value >= 0 ? value : null;
|
|
188
|
+
if (typeof value === "string" && PX_RE.test(value)) return parseFloat(value);
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
function ruleColor(value) {
|
|
192
|
+
if (typeof value !== "string") return err("color must be a string");
|
|
193
|
+
if (value === "transparent" || TOKEN_RE.test(value)) return ok;
|
|
194
|
+
return err(`color must be "transparent" or a $token, got "${value}"`);
|
|
195
|
+
}
|
|
196
|
+
function rulePx(cap) {
|
|
197
|
+
return (value) => {
|
|
198
|
+
const px2 = pxNumber(value);
|
|
199
|
+
if (px2 === null) return err(`must be a px value, got "${value}"`);
|
|
200
|
+
if (px2 > cap) return err(`exceeds ${cap}px cap (${px2}px)`);
|
|
201
|
+
return ok;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function rulePxList(cap) {
|
|
205
|
+
return (value) => {
|
|
206
|
+
if (typeof value === "number") {
|
|
207
|
+
if (value < 0) return err(`must not be negative (${value}px)`);
|
|
208
|
+
return value <= cap ? ok : err(`exceeds ${cap}px cap (${value}px)`);
|
|
209
|
+
}
|
|
210
|
+
if (typeof value !== "string" || !PX_LIST_RE.test(value)) {
|
|
211
|
+
return err(`must be 1-4 px values, got "${value}"`);
|
|
212
|
+
}
|
|
213
|
+
for (const part of value.split(" ")) {
|
|
214
|
+
if (parseFloat(part) > cap) {
|
|
215
|
+
return err(`exceeds ${cap}px cap ("${value}")`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return ok;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function ruleEnum(...allowed) {
|
|
222
|
+
return (value) => allowed.includes(value) ? ok : err(`must be one of ${allowed.join("|")}, got "${value}"`);
|
|
223
|
+
}
|
|
224
|
+
var ruleDimension = (value, node) => {
|
|
225
|
+
if (value === "100%") return ok;
|
|
226
|
+
const px2 = pxNumber(value);
|
|
227
|
+
if (px2 === null) return err(`must be px or "100%", got "${value}"`);
|
|
228
|
+
if (node.type === "image" && px2 > PSP1_MAX_IMAGE_PX) {
|
|
229
|
+
return err(`image dimension exceeds ${PSP1_MAX_IMAGE_PX}px cap (${px2}px)`);
|
|
230
|
+
}
|
|
231
|
+
return ok;
|
|
232
|
+
};
|
|
233
|
+
var ruleRadius = (value) => {
|
|
234
|
+
if (value === "full" || value === "$radius") return ok;
|
|
235
|
+
const px2 = pxNumber(value);
|
|
236
|
+
if (px2 === null) {
|
|
237
|
+
return err(`must be px, "full", or "$radius", got "${value}"`);
|
|
238
|
+
}
|
|
239
|
+
return ok;
|
|
240
|
+
};
|
|
241
|
+
var ruleBorder = (value) => {
|
|
242
|
+
if (typeof value !== "string") return err("border must be a string");
|
|
243
|
+
const m = value.match(/^1px solid (\$\S+)$/);
|
|
244
|
+
if (!m || ruleColor(m[1]) !== null) {
|
|
245
|
+
return err(`must be "1px solid $token", got "${value}"`);
|
|
246
|
+
}
|
|
247
|
+
return ok;
|
|
248
|
+
};
|
|
249
|
+
var ruleLineHeight = (value) => {
|
|
250
|
+
if (typeof value === "boolean") return err("must be a number");
|
|
251
|
+
const n = typeof value === "number" ? value : parseFloat(value);
|
|
252
|
+
if (typeof value === "string" && !/^\d+(\.\d+)?$/.test(value)) {
|
|
253
|
+
return err(`must be a unitless multiplier, got "${value}"`);
|
|
254
|
+
}
|
|
255
|
+
if (Number.isNaN(n) || n < 1 || n > 2) {
|
|
256
|
+
return err(`must be a unitless multiplier in [1, 2], got "${value}"`);
|
|
257
|
+
}
|
|
258
|
+
return ok;
|
|
259
|
+
};
|
|
260
|
+
var ruleOpacity = (value) => {
|
|
261
|
+
if (typeof value === "boolean") return err("must be a number");
|
|
262
|
+
if (typeof value === "string" && !/^\d+(\.\d+)?$/.test(value)) {
|
|
263
|
+
return err(`must be a unitless number, got "${value}"`);
|
|
264
|
+
}
|
|
265
|
+
const n = typeof value === "number" ? value : parseFloat(value);
|
|
266
|
+
if (Number.isNaN(n) || n < 0 || n > 1) {
|
|
267
|
+
return err(`must be in [0, 1], got "${value}"`);
|
|
268
|
+
}
|
|
269
|
+
return ok;
|
|
270
|
+
};
|
|
271
|
+
var ruleMaxLines = (value) => {
|
|
272
|
+
if (typeof value === "boolean") return err("must be an integer");
|
|
273
|
+
if (typeof value === "string" && !/^\d+$/.test(value)) {
|
|
274
|
+
return err(`must be an integer, got "${value}"`);
|
|
275
|
+
}
|
|
276
|
+
const n = typeof value === "number" ? value : parseInt(value, 10);
|
|
277
|
+
if (!Number.isInteger(n) || n < 1 || n > 10) {
|
|
278
|
+
return err(`must be an integer in [1, 10], got "${value}"`);
|
|
279
|
+
}
|
|
280
|
+
return ok;
|
|
281
|
+
};
|
|
282
|
+
var ruleLetterSpacing = (value) => {
|
|
283
|
+
if (typeof value === "string" && EM_RE.test(value)) return ok;
|
|
284
|
+
return err(`must be an em value, got "${value}"`);
|
|
285
|
+
};
|
|
286
|
+
var ruleBool = (value) => value === true || value === false ? ok : err(`must be a boolean, got "${value}"`);
|
|
287
|
+
var PSP1_STYLE_RULES = {
|
|
288
|
+
// Layout
|
|
289
|
+
direction: ruleEnum("row", "column"),
|
|
290
|
+
gap: rulePx(PSP1_MAX_SPACING_PX),
|
|
291
|
+
align: ruleEnum("start", "center", "end", "baseline"),
|
|
292
|
+
justify: ruleEnum("start", "center", "end", "space-between"),
|
|
293
|
+
grow: ruleEnum(0, 1),
|
|
294
|
+
shrink: ruleEnum(0, 1),
|
|
295
|
+
spacerBefore: ruleBool,
|
|
296
|
+
// Box
|
|
297
|
+
padding: rulePxList(PSP1_MAX_SPACING_PX),
|
|
298
|
+
paddingTop: rulePx(PSP1_MAX_SPACING_PX),
|
|
299
|
+
paddingRight: rulePx(PSP1_MAX_SPACING_PX),
|
|
300
|
+
paddingBottom: rulePx(PSP1_MAX_SPACING_PX),
|
|
301
|
+
paddingLeft: rulePx(PSP1_MAX_SPACING_PX),
|
|
302
|
+
margin: rulePxList(PSP1_MAX_SPACING_PX),
|
|
303
|
+
marginTop: rulePx(PSP1_MAX_SPACING_PX),
|
|
304
|
+
marginRight: rulePx(PSP1_MAX_SPACING_PX),
|
|
305
|
+
marginBottom: rulePx(PSP1_MAX_SPACING_PX),
|
|
306
|
+
marginLeft: rulePx(PSP1_MAX_SPACING_PX),
|
|
307
|
+
width: ruleDimension,
|
|
308
|
+
height: ruleDimension,
|
|
309
|
+
maxWidth: rulePx(Infinity),
|
|
310
|
+
minWidth: (value) => value === 0 || value === "0" || pxNumber(value) !== null ? ok : err(`must be 0 or px, got "${value}"`),
|
|
311
|
+
// Surface
|
|
312
|
+
background: ruleColor,
|
|
313
|
+
border: ruleBorder,
|
|
314
|
+
borderRadius: ruleRadius,
|
|
315
|
+
elevation: ruleEnum("none", "sm", "md"),
|
|
316
|
+
opacity: ruleOpacity,
|
|
317
|
+
// Text
|
|
318
|
+
fontSize: rulePx(PSP1_MAX_FONT_SIZE_PX),
|
|
319
|
+
fontWeight: ruleEnum(400, 500, 600, 700, 800),
|
|
320
|
+
lineHeight: ruleLineHeight,
|
|
321
|
+
letterSpacing: ruleLetterSpacing,
|
|
322
|
+
color: ruleColor,
|
|
323
|
+
textTransform: ruleEnum("none", "uppercase"),
|
|
324
|
+
textDecoration: ruleEnum("none", "underline"),
|
|
325
|
+
textAlign: ruleEnum("left", "center", "right"),
|
|
326
|
+
maxLines: ruleMaxLines,
|
|
327
|
+
nowrap: ruleBool,
|
|
328
|
+
// Image
|
|
329
|
+
fit: ruleEnum("contain", "cover")
|
|
330
|
+
};
|
|
331
|
+
var ALLOWED_URL_PROTOCOLS = SPEC_LINK_PROTOCOLS.map((p) => p.slice(0, -1));
|
|
332
|
+
|
|
144
333
|
// ../ui/src/theme.ts
|
|
145
334
|
var GRAVITY_DARK_VARS = {
|
|
146
335
|
"--gravity-bg": "#1F1F23",
|
|
@@ -273,8 +462,9 @@ function readHostTheme(el) {
|
|
|
273
462
|
return void 0;
|
|
274
463
|
}
|
|
275
464
|
}
|
|
276
|
-
function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false } = {}) {
|
|
465
|
+
function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false, banner = false } = {}) {
|
|
277
466
|
const caps = ["units.v1", "image"];
|
|
467
|
+
if (banner) caps.push("blocks.banner");
|
|
278
468
|
if (frames) caps.push("frame.gfb1");
|
|
279
469
|
if (promptAction) caps.push("action.prompt");
|
|
280
470
|
if (mcpConnect) caps.push("connect.mcp");
|
|
@@ -389,9 +579,9 @@ async function gravityAds(req, messages, placements, opts = {}) {
|
|
|
389
579
|
const data = await res.json();
|
|
390
580
|
const ads = Array.isArray(data) ? data : [data];
|
|
391
581
|
return { ads, status: res.status, elapsed, requestBody: body };
|
|
392
|
-
} catch (
|
|
582
|
+
} catch (err2) {
|
|
393
583
|
const elapsed = (performance.now() - start).toFixed(0);
|
|
394
|
-
const error =
|
|
584
|
+
const error = err2 instanceof Error ? err2.name === "TimeoutError" ? `Timeout (${timeoutMs}ms)` : err2.message : String(err2);
|
|
395
585
|
return { ads: [], status: 0, elapsed, error, requestBody: body };
|
|
396
586
|
}
|
|
397
587
|
}
|
|
@@ -453,7 +643,10 @@ function findCmpApi(name) {
|
|
|
453
643
|
}
|
|
454
644
|
var cachedTcf;
|
|
455
645
|
var cachedUsp;
|
|
646
|
+
var cachedGpp;
|
|
456
647
|
var tcfListening = false;
|
|
648
|
+
var tcfBroken = false;
|
|
649
|
+
var gppListening = false;
|
|
457
650
|
var cmpWaitExhausted = false;
|
|
458
651
|
function ensureListening() {
|
|
459
652
|
if (typeof window === "undefined") return;
|
|
@@ -473,6 +666,21 @@ function ensureListening() {
|
|
|
473
666
|
cachedTcf = { gdprApplies: false };
|
|
474
667
|
}
|
|
475
668
|
});
|
|
669
|
+
} catch {
|
|
670
|
+
tcfBroken = true;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
const gpp = gppListening ? void 0 : findCmpApi("__gpp");
|
|
674
|
+
if (gpp) {
|
|
675
|
+
gppListening = true;
|
|
676
|
+
try {
|
|
677
|
+
gpp("addEventListener", (data, success) => {
|
|
678
|
+
if (!success || typeof data !== "object" || data === null) return;
|
|
679
|
+
cacheGppPing(data.pingData);
|
|
680
|
+
});
|
|
681
|
+
gpp("ping", (data, success) => {
|
|
682
|
+
if (success) cacheGppPing(data);
|
|
683
|
+
});
|
|
476
684
|
} catch {
|
|
477
685
|
}
|
|
478
686
|
}
|
|
@@ -488,13 +696,38 @@ function ensureListening() {
|
|
|
488
696
|
}
|
|
489
697
|
}
|
|
490
698
|
}
|
|
699
|
+
function cacheGppPing(ping) {
|
|
700
|
+
if (typeof ping !== "object" || ping === null) return;
|
|
701
|
+
const p = ping;
|
|
702
|
+
if (p.signalStatus !== "ready") return;
|
|
703
|
+
if (typeof p.gppString !== "string" || !p.gppString) return;
|
|
704
|
+
const raw = Array.isArray(p.applicableSections) ? p.applicableSections : [];
|
|
705
|
+
const readable = raw.every((id) => Number.isInteger(id));
|
|
706
|
+
const sections = readable ? raw.filter((id) => id !== -1) : [];
|
|
707
|
+
cachedGpp = sections.length ? { gpp: p.gppString, gppSid: sections } : { gpp: p.gppString };
|
|
708
|
+
}
|
|
709
|
+
function tcfPending() {
|
|
710
|
+
return !cachedTcf && !tcfBroken && Boolean(findCmpApi("__tcfapi"));
|
|
711
|
+
}
|
|
712
|
+
function cmpSettled() {
|
|
713
|
+
return !tcfPending() && (cachedGpp !== void 0 || !findCmpApi("__gpp"));
|
|
714
|
+
}
|
|
715
|
+
function detectGpc() {
|
|
716
|
+
return typeof navigator !== "undefined" && navigator.globalPrivacyControl === true;
|
|
717
|
+
}
|
|
491
718
|
function detectCmpConsent() {
|
|
492
719
|
ensureListening();
|
|
493
|
-
|
|
720
|
+
const gpc = detectGpc();
|
|
721
|
+
if (!cachedTcf && !cachedUsp && !cachedGpp && !gpc) return void 0;
|
|
494
722
|
const consent = {};
|
|
495
723
|
if (cachedTcf?.gdprApplies !== void 0) consent.gdprApplies = cachedTcf.gdprApplies;
|
|
496
724
|
if (cachedTcf?.tcfString) consent.tcfString = cachedTcf.tcfString;
|
|
497
725
|
if (cachedUsp) consent.usPrivacy = cachedUsp;
|
|
726
|
+
if (cachedGpp && !tcfPending()) {
|
|
727
|
+
consent.gpp = cachedGpp.gpp;
|
|
728
|
+
if (cachedGpp.gppSid) consent.gppSid = [...cachedGpp.gppSid];
|
|
729
|
+
}
|
|
730
|
+
if (gpc) consent.gpc = true;
|
|
498
731
|
if (Object.keys(consent).length === 0) return void 0;
|
|
499
732
|
return consent;
|
|
500
733
|
}
|
|
@@ -504,20 +737,22 @@ if (typeof window !== "undefined") ensureListening();
|
|
|
504
737
|
function readCmpConsent(timeoutMs = 500) {
|
|
505
738
|
ensureListening();
|
|
506
739
|
const immediate = detectCmpConsent();
|
|
507
|
-
if (immediate || cmpWaitExhausted || typeof window === "undefined") {
|
|
740
|
+
if (immediate && cmpSettled() || cmpWaitExhausted || typeof window === "undefined") {
|
|
508
741
|
return Promise.resolve(immediate);
|
|
509
742
|
}
|
|
510
743
|
return new Promise((resolve) => {
|
|
511
744
|
const started = Date.now();
|
|
512
745
|
const poll = () => {
|
|
513
746
|
const consent = detectCmpConsent();
|
|
514
|
-
if (consent) return resolve(consent);
|
|
747
|
+
if (consent && cmpSettled()) return resolve(consent);
|
|
515
748
|
const elapsed = Date.now() - started;
|
|
516
|
-
const cmpPresent = Boolean(
|
|
749
|
+
const cmpPresent = Boolean(
|
|
750
|
+
findCmpApi("__tcfapi") || findCmpApi("__uspapi") || findCmpApi("__gpp")
|
|
751
|
+
);
|
|
517
752
|
if (cmpPresent) {
|
|
518
753
|
if (elapsed >= timeoutMs) {
|
|
519
754
|
cmpWaitExhausted = true;
|
|
520
|
-
return resolve(
|
|
755
|
+
return resolve(consent);
|
|
521
756
|
}
|
|
522
757
|
} else if (elapsed >= timeoutMs || Date.now() - graceStartedAt >= NO_CMP_GRACE_MS) {
|
|
523
758
|
return resolve(void 0);
|
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.
|
|
11
|
+
version: "1.5.0",
|
|
12
12
|
description: "Gravity JS SDK for retrieving targeted advertisements",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
module: "dist/index.mjs",
|
|
@@ -92,6 +92,195 @@ var pkg = (() => {
|
|
|
92
92
|
})();
|
|
93
93
|
var SDK = { name: pkg.name, version: pkg.version };
|
|
94
94
|
|
|
95
|
+
// ../ui/src/psp.ts
|
|
96
|
+
var SPEC_LINK_PROTOCOLS = ["http:", "https:", "mailto:"];
|
|
97
|
+
var SHADCN_CHANNEL_DEFAULTS = {
|
|
98
|
+
background: "0 0% 100%",
|
|
99
|
+
foreground: "240 6% 10%",
|
|
100
|
+
card: "0 0% 100%",
|
|
101
|
+
"card-foreground": "240 6% 10%",
|
|
102
|
+
primary: "221 83% 53%",
|
|
103
|
+
"primary-foreground": "0 0% 100%",
|
|
104
|
+
muted: "240 5% 96%",
|
|
105
|
+
"muted-foreground": "240 5% 47%",
|
|
106
|
+
accent: "221 83% 53%",
|
|
107
|
+
"accent-foreground": "0 0% 100%",
|
|
108
|
+
border: "240 5% 90%"
|
|
109
|
+
};
|
|
110
|
+
var SHADCN_HOST_TOKENS = Object.keys(SHADCN_CHANNEL_DEFAULTS);
|
|
111
|
+
var PSP1_COLOR_TOKENS = [
|
|
112
|
+
"background",
|
|
113
|
+
"foreground",
|
|
114
|
+
"card",
|
|
115
|
+
"card-foreground",
|
|
116
|
+
"primary",
|
|
117
|
+
"primary-foreground",
|
|
118
|
+
"muted",
|
|
119
|
+
"muted-foreground",
|
|
120
|
+
"accent",
|
|
121
|
+
"accent-foreground",
|
|
122
|
+
"border"
|
|
123
|
+
];
|
|
124
|
+
var PSP1_MAX_FONT_SIZE_PX = 20;
|
|
125
|
+
var PSP1_MAX_SPACING_PX = 32;
|
|
126
|
+
var PSP1_MAX_IMAGE_PX = 64;
|
|
127
|
+
var ok = null;
|
|
128
|
+
function err(msg) {
|
|
129
|
+
return msg;
|
|
130
|
+
}
|
|
131
|
+
var PX_RE = /^\d+(\.\d+)?px$/;
|
|
132
|
+
var PX_LIST_RE = /^\d+(\.\d+)?px( \d+(\.\d+)?px){0,3}$/;
|
|
133
|
+
var EM_RE = /^-?\d+(\.\d+)?em$/;
|
|
134
|
+
var TOKEN_RE = new RegExp(
|
|
135
|
+
`^\\$(${PSP1_COLOR_TOKENS.join("|")})(/(100|[1-9]?[0-9]))?$`
|
|
136
|
+
);
|
|
137
|
+
function pxNumber(value) {
|
|
138
|
+
if (typeof value === "number") return value >= 0 ? value : null;
|
|
139
|
+
if (typeof value === "string" && PX_RE.test(value)) return parseFloat(value);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
function ruleColor(value) {
|
|
143
|
+
if (typeof value !== "string") return err("color must be a string");
|
|
144
|
+
if (value === "transparent" || TOKEN_RE.test(value)) return ok;
|
|
145
|
+
return err(`color must be "transparent" or a $token, got "${value}"`);
|
|
146
|
+
}
|
|
147
|
+
function rulePx(cap) {
|
|
148
|
+
return (value) => {
|
|
149
|
+
const px2 = pxNumber(value);
|
|
150
|
+
if (px2 === null) return err(`must be a px value, got "${value}"`);
|
|
151
|
+
if (px2 > cap) return err(`exceeds ${cap}px cap (${px2}px)`);
|
|
152
|
+
return ok;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function rulePxList(cap) {
|
|
156
|
+
return (value) => {
|
|
157
|
+
if (typeof value === "number") {
|
|
158
|
+
if (value < 0) return err(`must not be negative (${value}px)`);
|
|
159
|
+
return value <= cap ? ok : err(`exceeds ${cap}px cap (${value}px)`);
|
|
160
|
+
}
|
|
161
|
+
if (typeof value !== "string" || !PX_LIST_RE.test(value)) {
|
|
162
|
+
return err(`must be 1-4 px values, got "${value}"`);
|
|
163
|
+
}
|
|
164
|
+
for (const part of value.split(" ")) {
|
|
165
|
+
if (parseFloat(part) > cap) {
|
|
166
|
+
return err(`exceeds ${cap}px cap ("${value}")`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return ok;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function ruleEnum(...allowed) {
|
|
173
|
+
return (value) => allowed.includes(value) ? ok : err(`must be one of ${allowed.join("|")}, got "${value}"`);
|
|
174
|
+
}
|
|
175
|
+
var ruleDimension = (value, node) => {
|
|
176
|
+
if (value === "100%") return ok;
|
|
177
|
+
const px2 = pxNumber(value);
|
|
178
|
+
if (px2 === null) return err(`must be px or "100%", got "${value}"`);
|
|
179
|
+
if (node.type === "image" && px2 > PSP1_MAX_IMAGE_PX) {
|
|
180
|
+
return err(`image dimension exceeds ${PSP1_MAX_IMAGE_PX}px cap (${px2}px)`);
|
|
181
|
+
}
|
|
182
|
+
return ok;
|
|
183
|
+
};
|
|
184
|
+
var ruleRadius = (value) => {
|
|
185
|
+
if (value === "full" || value === "$radius") return ok;
|
|
186
|
+
const px2 = pxNumber(value);
|
|
187
|
+
if (px2 === null) {
|
|
188
|
+
return err(`must be px, "full", or "$radius", got "${value}"`);
|
|
189
|
+
}
|
|
190
|
+
return ok;
|
|
191
|
+
};
|
|
192
|
+
var ruleBorder = (value) => {
|
|
193
|
+
if (typeof value !== "string") return err("border must be a string");
|
|
194
|
+
const m = value.match(/^1px solid (\$\S+)$/);
|
|
195
|
+
if (!m || ruleColor(m[1]) !== null) {
|
|
196
|
+
return err(`must be "1px solid $token", got "${value}"`);
|
|
197
|
+
}
|
|
198
|
+
return ok;
|
|
199
|
+
};
|
|
200
|
+
var ruleLineHeight = (value) => {
|
|
201
|
+
if (typeof value === "boolean") return err("must be a number");
|
|
202
|
+
const n = typeof value === "number" ? value : parseFloat(value);
|
|
203
|
+
if (typeof value === "string" && !/^\d+(\.\d+)?$/.test(value)) {
|
|
204
|
+
return err(`must be a unitless multiplier, got "${value}"`);
|
|
205
|
+
}
|
|
206
|
+
if (Number.isNaN(n) || n < 1 || n > 2) {
|
|
207
|
+
return err(`must be a unitless multiplier in [1, 2], got "${value}"`);
|
|
208
|
+
}
|
|
209
|
+
return ok;
|
|
210
|
+
};
|
|
211
|
+
var ruleOpacity = (value) => {
|
|
212
|
+
if (typeof value === "boolean") return err("must be a number");
|
|
213
|
+
if (typeof value === "string" && !/^\d+(\.\d+)?$/.test(value)) {
|
|
214
|
+
return err(`must be a unitless number, got "${value}"`);
|
|
215
|
+
}
|
|
216
|
+
const n = typeof value === "number" ? value : parseFloat(value);
|
|
217
|
+
if (Number.isNaN(n) || n < 0 || n > 1) {
|
|
218
|
+
return err(`must be in [0, 1], got "${value}"`);
|
|
219
|
+
}
|
|
220
|
+
return ok;
|
|
221
|
+
};
|
|
222
|
+
var ruleMaxLines = (value) => {
|
|
223
|
+
if (typeof value === "boolean") return err("must be an integer");
|
|
224
|
+
if (typeof value === "string" && !/^\d+$/.test(value)) {
|
|
225
|
+
return err(`must be an integer, got "${value}"`);
|
|
226
|
+
}
|
|
227
|
+
const n = typeof value === "number" ? value : parseInt(value, 10);
|
|
228
|
+
if (!Number.isInteger(n) || n < 1 || n > 10) {
|
|
229
|
+
return err(`must be an integer in [1, 10], got "${value}"`);
|
|
230
|
+
}
|
|
231
|
+
return ok;
|
|
232
|
+
};
|
|
233
|
+
var ruleLetterSpacing = (value) => {
|
|
234
|
+
if (typeof value === "string" && EM_RE.test(value)) return ok;
|
|
235
|
+
return err(`must be an em value, got "${value}"`);
|
|
236
|
+
};
|
|
237
|
+
var ruleBool = (value) => value === true || value === false ? ok : err(`must be a boolean, got "${value}"`);
|
|
238
|
+
var PSP1_STYLE_RULES = {
|
|
239
|
+
// Layout
|
|
240
|
+
direction: ruleEnum("row", "column"),
|
|
241
|
+
gap: rulePx(PSP1_MAX_SPACING_PX),
|
|
242
|
+
align: ruleEnum("start", "center", "end", "baseline"),
|
|
243
|
+
justify: ruleEnum("start", "center", "end", "space-between"),
|
|
244
|
+
grow: ruleEnum(0, 1),
|
|
245
|
+
shrink: ruleEnum(0, 1),
|
|
246
|
+
spacerBefore: ruleBool,
|
|
247
|
+
// Box
|
|
248
|
+
padding: rulePxList(PSP1_MAX_SPACING_PX),
|
|
249
|
+
paddingTop: rulePx(PSP1_MAX_SPACING_PX),
|
|
250
|
+
paddingRight: rulePx(PSP1_MAX_SPACING_PX),
|
|
251
|
+
paddingBottom: rulePx(PSP1_MAX_SPACING_PX),
|
|
252
|
+
paddingLeft: rulePx(PSP1_MAX_SPACING_PX),
|
|
253
|
+
margin: rulePxList(PSP1_MAX_SPACING_PX),
|
|
254
|
+
marginTop: rulePx(PSP1_MAX_SPACING_PX),
|
|
255
|
+
marginRight: rulePx(PSP1_MAX_SPACING_PX),
|
|
256
|
+
marginBottom: rulePx(PSP1_MAX_SPACING_PX),
|
|
257
|
+
marginLeft: rulePx(PSP1_MAX_SPACING_PX),
|
|
258
|
+
width: ruleDimension,
|
|
259
|
+
height: ruleDimension,
|
|
260
|
+
maxWidth: rulePx(Infinity),
|
|
261
|
+
minWidth: (value) => value === 0 || value === "0" || pxNumber(value) !== null ? ok : err(`must be 0 or px, got "${value}"`),
|
|
262
|
+
// Surface
|
|
263
|
+
background: ruleColor,
|
|
264
|
+
border: ruleBorder,
|
|
265
|
+
borderRadius: ruleRadius,
|
|
266
|
+
elevation: ruleEnum("none", "sm", "md"),
|
|
267
|
+
opacity: ruleOpacity,
|
|
268
|
+
// Text
|
|
269
|
+
fontSize: rulePx(PSP1_MAX_FONT_SIZE_PX),
|
|
270
|
+
fontWeight: ruleEnum(400, 500, 600, 700, 800),
|
|
271
|
+
lineHeight: ruleLineHeight,
|
|
272
|
+
letterSpacing: ruleLetterSpacing,
|
|
273
|
+
color: ruleColor,
|
|
274
|
+
textTransform: ruleEnum("none", "uppercase"),
|
|
275
|
+
textDecoration: ruleEnum("none", "underline"),
|
|
276
|
+
textAlign: ruleEnum("left", "center", "right"),
|
|
277
|
+
maxLines: ruleMaxLines,
|
|
278
|
+
nowrap: ruleBool,
|
|
279
|
+
// Image
|
|
280
|
+
fit: ruleEnum("contain", "cover")
|
|
281
|
+
};
|
|
282
|
+
var ALLOWED_URL_PROTOCOLS = SPEC_LINK_PROTOCOLS.map((p) => p.slice(0, -1));
|
|
283
|
+
|
|
95
284
|
// ../ui/src/theme.ts
|
|
96
285
|
var GRAVITY_DARK_VARS = {
|
|
97
286
|
"--gravity-bg": "#1F1F23",
|
|
@@ -224,8 +413,9 @@ function readHostTheme(el) {
|
|
|
224
413
|
return void 0;
|
|
225
414
|
}
|
|
226
415
|
}
|
|
227
|
-
function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false } = {}) {
|
|
416
|
+
function capabilitiesFor({ frames = false, promptAction = false, mcpConnect = false, banner = false } = {}) {
|
|
228
417
|
const caps = ["units.v1", "image"];
|
|
418
|
+
if (banner) caps.push("blocks.banner");
|
|
229
419
|
if (frames) caps.push("frame.gfb1");
|
|
230
420
|
if (promptAction) caps.push("action.prompt");
|
|
231
421
|
if (mcpConnect) caps.push("connect.mcp");
|
|
@@ -340,9 +530,9 @@ async function gravityAds(req, messages, placements, opts = {}) {
|
|
|
340
530
|
const data = await res.json();
|
|
341
531
|
const ads = Array.isArray(data) ? data : [data];
|
|
342
532
|
return { ads, status: res.status, elapsed, requestBody: body };
|
|
343
|
-
} catch (
|
|
533
|
+
} catch (err2) {
|
|
344
534
|
const elapsed = (performance.now() - start).toFixed(0);
|
|
345
|
-
const error =
|
|
535
|
+
const error = err2 instanceof Error ? err2.name === "TimeoutError" ? `Timeout (${timeoutMs}ms)` : err2.message : String(err2);
|
|
346
536
|
return { ads: [], status: 0, elapsed, error, requestBody: body };
|
|
347
537
|
}
|
|
348
538
|
}
|
|
@@ -404,7 +594,10 @@ function findCmpApi(name) {
|
|
|
404
594
|
}
|
|
405
595
|
var cachedTcf;
|
|
406
596
|
var cachedUsp;
|
|
597
|
+
var cachedGpp;
|
|
407
598
|
var tcfListening = false;
|
|
599
|
+
var tcfBroken = false;
|
|
600
|
+
var gppListening = false;
|
|
408
601
|
var cmpWaitExhausted = false;
|
|
409
602
|
function ensureListening() {
|
|
410
603
|
if (typeof window === "undefined") return;
|
|
@@ -424,6 +617,21 @@ function ensureListening() {
|
|
|
424
617
|
cachedTcf = { gdprApplies: false };
|
|
425
618
|
}
|
|
426
619
|
});
|
|
620
|
+
} catch {
|
|
621
|
+
tcfBroken = true;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const gpp = gppListening ? void 0 : findCmpApi("__gpp");
|
|
625
|
+
if (gpp) {
|
|
626
|
+
gppListening = true;
|
|
627
|
+
try {
|
|
628
|
+
gpp("addEventListener", (data, success) => {
|
|
629
|
+
if (!success || typeof data !== "object" || data === null) return;
|
|
630
|
+
cacheGppPing(data.pingData);
|
|
631
|
+
});
|
|
632
|
+
gpp("ping", (data, success) => {
|
|
633
|
+
if (success) cacheGppPing(data);
|
|
634
|
+
});
|
|
427
635
|
} catch {
|
|
428
636
|
}
|
|
429
637
|
}
|
|
@@ -439,13 +647,38 @@ function ensureListening() {
|
|
|
439
647
|
}
|
|
440
648
|
}
|
|
441
649
|
}
|
|
650
|
+
function cacheGppPing(ping) {
|
|
651
|
+
if (typeof ping !== "object" || ping === null) return;
|
|
652
|
+
const p = ping;
|
|
653
|
+
if (p.signalStatus !== "ready") return;
|
|
654
|
+
if (typeof p.gppString !== "string" || !p.gppString) return;
|
|
655
|
+
const raw = Array.isArray(p.applicableSections) ? p.applicableSections : [];
|
|
656
|
+
const readable = raw.every((id) => Number.isInteger(id));
|
|
657
|
+
const sections = readable ? raw.filter((id) => id !== -1) : [];
|
|
658
|
+
cachedGpp = sections.length ? { gpp: p.gppString, gppSid: sections } : { gpp: p.gppString };
|
|
659
|
+
}
|
|
660
|
+
function tcfPending() {
|
|
661
|
+
return !cachedTcf && !tcfBroken && Boolean(findCmpApi("__tcfapi"));
|
|
662
|
+
}
|
|
663
|
+
function cmpSettled() {
|
|
664
|
+
return !tcfPending() && (cachedGpp !== void 0 || !findCmpApi("__gpp"));
|
|
665
|
+
}
|
|
666
|
+
function detectGpc() {
|
|
667
|
+
return typeof navigator !== "undefined" && navigator.globalPrivacyControl === true;
|
|
668
|
+
}
|
|
442
669
|
function detectCmpConsent() {
|
|
443
670
|
ensureListening();
|
|
444
|
-
|
|
671
|
+
const gpc = detectGpc();
|
|
672
|
+
if (!cachedTcf && !cachedUsp && !cachedGpp && !gpc) return void 0;
|
|
445
673
|
const consent = {};
|
|
446
674
|
if (cachedTcf?.gdprApplies !== void 0) consent.gdprApplies = cachedTcf.gdprApplies;
|
|
447
675
|
if (cachedTcf?.tcfString) consent.tcfString = cachedTcf.tcfString;
|
|
448
676
|
if (cachedUsp) consent.usPrivacy = cachedUsp;
|
|
677
|
+
if (cachedGpp && !tcfPending()) {
|
|
678
|
+
consent.gpp = cachedGpp.gpp;
|
|
679
|
+
if (cachedGpp.gppSid) consent.gppSid = [...cachedGpp.gppSid];
|
|
680
|
+
}
|
|
681
|
+
if (gpc) consent.gpc = true;
|
|
449
682
|
if (Object.keys(consent).length === 0) return void 0;
|
|
450
683
|
return consent;
|
|
451
684
|
}
|
|
@@ -455,20 +688,22 @@ if (typeof window !== "undefined") ensureListening();
|
|
|
455
688
|
function readCmpConsent(timeoutMs = 500) {
|
|
456
689
|
ensureListening();
|
|
457
690
|
const immediate = detectCmpConsent();
|
|
458
|
-
if (immediate || cmpWaitExhausted || typeof window === "undefined") {
|
|
691
|
+
if (immediate && cmpSettled() || cmpWaitExhausted || typeof window === "undefined") {
|
|
459
692
|
return Promise.resolve(immediate);
|
|
460
693
|
}
|
|
461
694
|
return new Promise((resolve) => {
|
|
462
695
|
const started = Date.now();
|
|
463
696
|
const poll = () => {
|
|
464
697
|
const consent = detectCmpConsent();
|
|
465
|
-
if (consent) return resolve(consent);
|
|
698
|
+
if (consent && cmpSettled()) return resolve(consent);
|
|
466
699
|
const elapsed = Date.now() - started;
|
|
467
|
-
const cmpPresent = Boolean(
|
|
700
|
+
const cmpPresent = Boolean(
|
|
701
|
+
findCmpApi("__tcfapi") || findCmpApi("__uspapi") || findCmpApi("__gpp")
|
|
702
|
+
);
|
|
468
703
|
if (cmpPresent) {
|
|
469
704
|
if (elapsed >= timeoutMs) {
|
|
470
705
|
cmpWaitExhausted = true;
|
|
471
|
-
return resolve(
|
|
706
|
+
return resolve(consent);
|
|
472
707
|
}
|
|
473
708
|
} else if (elapsed >= timeoutMs || Date.now() - graceStartedAt >= NO_CMP_GRACE_MS) {
|
|
474
709
|
return resolve(void 0);
|
package/dist/opentui.js
CHANGED
|
@@ -29,7 +29,7 @@ var import_child_process = require("child_process");
|
|
|
29
29
|
// viewability.ts
|
|
30
30
|
var MAX_TRACKED_IMPRESSIONS = 1e3;
|
|
31
31
|
var SDK = "opentui";
|
|
32
|
-
var SDK_VERSION = "1.
|
|
32
|
+
var SDK_VERSION = "1.5.0";
|
|
33
33
|
var beaconsSent = /* @__PURE__ */ new Set();
|
|
34
34
|
function sendViewabilityBeacon(impUrl, ev) {
|
|
35
35
|
const key = `${ev} ${impUrl}`;
|
package/dist/opentui.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { execFile } from "child_process";
|
|
|
8
8
|
// viewability.ts
|
|
9
9
|
var MAX_TRACKED_IMPRESSIONS = 1e3;
|
|
10
10
|
var SDK = "opentui";
|
|
11
|
-
var SDK_VERSION = "1.
|
|
11
|
+
var SDK_VERSION = "1.5.0";
|
|
12
12
|
var beaconsSent = /* @__PURE__ */ new Set();
|
|
13
13
|
function sendViewabilityBeacon(impUrl, ev) {
|
|
14
14
|
const key = `${ev} ${impUrl}`;
|
|
@@ -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
|
-
/**
|
|
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 {
|
|
@@ -656,14 +668,21 @@ interface GravityContextOverrides {
|
|
|
656
668
|
device?: Record<string, unknown>;
|
|
657
669
|
/**
|
|
658
670
|
* Explicit consent signal. When omitted in a browser, the SDK reads the
|
|
659
|
-
* page's IAB CMP APIs (`__tcfapi` / `__uspapi`) and
|
|
660
|
-
*
|
|
661
|
-
*
|
|
671
|
+
* page's IAB CMP APIs (`__tcfapi` / `__uspapi` / `__gpp`) and
|
|
672
|
+
* `navigator.globalPrivacyControl`, and attaches the settled decision
|
|
673
|
+
* automatically. Pass this to override (it replaces the detected object
|
|
674
|
+
* as a whole), or in server-side runtimes where no CMP is readable.
|
|
662
675
|
*/
|
|
663
676
|
consent?: {
|
|
664
677
|
gdprApplies?: boolean;
|
|
665
678
|
tcfString?: string;
|
|
666
679
|
usPrivacy?: string;
|
|
680
|
+
/** IAB GPP string. */
|
|
681
|
+
gpp?: string;
|
|
682
|
+
/** GPP section ids that apply to this request. */
|
|
683
|
+
gppSid?: number[];
|
|
684
|
+
/** Global Privacy Control. Send only `true`. */
|
|
685
|
+
gpc?: boolean;
|
|
667
686
|
};
|
|
668
687
|
}
|
|
669
688
|
/** The context object returned by `gravityContext()` and sent in the request body. */
|
|
@@ -675,13 +694,20 @@ interface GravityContext {
|
|
|
675
694
|
device: Record<string, unknown>;
|
|
676
695
|
/**
|
|
677
696
|
* End-user privacy/consent signal. Auto-detected from the page's CMP
|
|
678
|
-
* (`window.__tcfapi` / `window.__uspapi`
|
|
697
|
+
* (`window.__tcfapi` / `window.__uspapi` / `window.__gpp`) and from
|
|
698
|
+
* `navigator.globalPrivacyControl` in browsers; callers can
|
|
679
699
|
* override via `GravityContextOverrides.consent`.
|
|
680
700
|
*/
|
|
681
701
|
consent?: {
|
|
682
702
|
gdprApplies?: boolean;
|
|
683
703
|
tcfString?: string;
|
|
684
704
|
usPrivacy?: string;
|
|
705
|
+
/** IAB GPP string. */
|
|
706
|
+
gpp?: string;
|
|
707
|
+
/** GPP section ids that apply to this request. */
|
|
708
|
+
gppSid?: number[];
|
|
709
|
+
/** Global Privacy Control. Send only `true`. */
|
|
710
|
+
gpc?: boolean;
|
|
685
711
|
};
|
|
686
712
|
}
|
|
687
713
|
/** Options for `gravityAds()`. */
|
|
@@ -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
|
-
/**
|
|
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 {
|
|
@@ -656,14 +668,21 @@ interface GravityContextOverrides {
|
|
|
656
668
|
device?: Record<string, unknown>;
|
|
657
669
|
/**
|
|
658
670
|
* Explicit consent signal. When omitted in a browser, the SDK reads the
|
|
659
|
-
* page's IAB CMP APIs (`__tcfapi` / `__uspapi`) and
|
|
660
|
-
*
|
|
661
|
-
*
|
|
671
|
+
* page's IAB CMP APIs (`__tcfapi` / `__uspapi` / `__gpp`) and
|
|
672
|
+
* `navigator.globalPrivacyControl`, and attaches the settled decision
|
|
673
|
+
* automatically. Pass this to override (it replaces the detected object
|
|
674
|
+
* as a whole), or in server-side runtimes where no CMP is readable.
|
|
662
675
|
*/
|
|
663
676
|
consent?: {
|
|
664
677
|
gdprApplies?: boolean;
|
|
665
678
|
tcfString?: string;
|
|
666
679
|
usPrivacy?: string;
|
|
680
|
+
/** IAB GPP string. */
|
|
681
|
+
gpp?: string;
|
|
682
|
+
/** GPP section ids that apply to this request. */
|
|
683
|
+
gppSid?: number[];
|
|
684
|
+
/** Global Privacy Control. Send only `true`. */
|
|
685
|
+
gpc?: boolean;
|
|
667
686
|
};
|
|
668
687
|
}
|
|
669
688
|
/** The context object returned by `gravityContext()` and sent in the request body. */
|
|
@@ -675,13 +694,20 @@ interface GravityContext {
|
|
|
675
694
|
device: Record<string, unknown>;
|
|
676
695
|
/**
|
|
677
696
|
* End-user privacy/consent signal. Auto-detected from the page's CMP
|
|
678
|
-
* (`window.__tcfapi` / `window.__uspapi`
|
|
697
|
+
* (`window.__tcfapi` / `window.__uspapi` / `window.__gpp`) and from
|
|
698
|
+
* `navigator.globalPrivacyControl` in browsers; callers can
|
|
679
699
|
* override via `GravityContextOverrides.consent`.
|
|
680
700
|
*/
|
|
681
701
|
consent?: {
|
|
682
702
|
gdprApplies?: boolean;
|
|
683
703
|
tcfString?: string;
|
|
684
704
|
usPrivacy?: string;
|
|
705
|
+
/** IAB GPP string. */
|
|
706
|
+
gpp?: string;
|
|
707
|
+
/** GPP section ids that apply to this request. */
|
|
708
|
+
gppSid?: number[];
|
|
709
|
+
/** Global Privacy Control. Send only `true`. */
|
|
710
|
+
gpc?: boolean;
|
|
685
711
|
};
|
|
686
712
|
}
|
|
687
713
|
/** Options for `gravityAds()`. */
|