@tolinku/react-native-sdk 0.6.0 → 0.7.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/dist/index.js CHANGED
@@ -2,15 +2,16 @@
2
2
 
3
3
  var reactNative = require('react-native');
4
4
  var AsyncStorage = require('@react-native-async-storage/async-storage');
5
- var react = require('react');
5
+ var React = require('react');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
10
  var AsyncStorage__default = /*#__PURE__*/_interopDefault(AsyncStorage);
11
+ var React__default = /*#__PURE__*/_interopDefault(React);
11
12
 
12
13
  // src/types.ts
13
- var SDK_VERSION = "0.6.0";
14
+ var SDK_VERSION = "0.7.0";
14
15
 
15
16
  // src/debug.ts
16
17
  var _debugEnabled = false;
@@ -32,6 +33,9 @@ function debugWarn(message) {
32
33
  var MAX_RETRIES = 3;
33
34
  var BASE_DELAY_MS = 500;
34
35
  var MAX_JITTER_MS = 250;
36
+ function isAbortError(err) {
37
+ return typeof err === "object" && err !== null && err.name === "AbortError";
38
+ }
35
39
  var HttpClient = class {
36
40
  constructor(config) {
37
41
  /** Set of AbortControllers for in-flight requests. Used by destroy() to cancel all. */
@@ -186,7 +190,7 @@ var HttpClient = class {
186
190
  if (this.destroyed) {
187
191
  throw new TolinkuError("Tolinku: request aborted (client destroyed).", 0);
188
192
  }
189
- if (err instanceof DOMException && err.name === "AbortError") {
193
+ if (isAbortError(err)) {
190
194
  const timeoutErr = new TolinkuError(`Tolinku: request timed out after ${this.timeout}ms`, 0);
191
195
  if (attempt === MAX_RETRIES) throw timeoutErr;
192
196
  lastError = timeoutErr;
@@ -224,16 +228,44 @@ var TolinkuError = class extends Error {
224
228
  };
225
229
 
226
230
  // src/validation.ts
231
+ function urlScheme(url) {
232
+ if (!url || typeof url !== "string") return null;
233
+ const cleaned = url.replace(/[\t\n\r]/g, "").replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, "");
234
+ const match = /^([a-zA-Z][a-zA-Z\d+\-._]*):/.exec(cleaned);
235
+ return match ? `${match[1].toLowerCase()}:` : null;
236
+ }
237
+ function parseHttpUrl(url) {
238
+ if (!url || typeof url !== "string") return null;
239
+ const cleaned = url.replace(/[\t\n\r]/g, "").trim();
240
+ const match = /^(https?):\/\/([^/?#]+)([^?#]*)/i.exec(cleaned);
241
+ if (!match) return null;
242
+ const [, scheme, authority, path] = match;
243
+ if (!authority) return null;
244
+ return {
245
+ origin: `${scheme.toLowerCase()}://${authority.toLowerCase()}`,
246
+ // A URL with no path means the root, which is what a server expects to be
247
+ // asked about.
248
+ pathname: path || "/"
249
+ };
250
+ }
227
251
  function isSafeUrl(url) {
228
- if (!url || typeof url !== "string") return false;
229
- const trimmed = url.trim();
230
- if (!trimmed) return false;
231
- try {
232
- const parsed = new URL(trimmed);
233
- return parsed.protocol === "http:" || parsed.protocol === "https:";
234
- } catch {
235
- return false;
236
- }
252
+ const scheme = urlScheme(url);
253
+ return scheme === "http:" || scheme === "https:";
254
+ }
255
+ var EXECUTABLE_SCHEMES = /* @__PURE__ */ new Set([
256
+ "javascript:",
257
+ "vbscript:",
258
+ "data:",
259
+ "blob:",
260
+ "file:",
261
+ "content:",
262
+ "jar:",
263
+ "filesystem:"
264
+ ]);
265
+ function isSafeActionUrl(url) {
266
+ const scheme = urlScheme(url);
267
+ if (!scheme) return false;
268
+ return !EXECUTABLE_SCHEMES.has(scheme);
237
269
  }
238
270
  function validateBaseUrl(baseUrl) {
239
271
  if (typeof baseUrl !== "string") {
@@ -330,13 +362,7 @@ var _Analytics = class _Analytics {
330
362
  if (this.appOpensDisabled) return;
331
363
  const trimmed = typeof url === "string" ? url.trim() : "";
332
364
  if (!trimmed) return;
333
- let parsed;
334
- try {
335
- parsed = new URL(trimmed);
336
- } catch {
337
- return;
338
- }
339
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return;
365
+ if (!isSafeUrl(trimmed)) return;
340
366
  const now = Date.now();
341
367
  if (this.lastOpenUrl === trimmed && now - this.lastOpenAt < _Analytics.OPEN_DEDUPE_MS) return;
342
368
  this.lastOpenUrl = trimmed;
@@ -633,8 +659,9 @@ var Ecommerce = class {
633
659
  }
634
660
  }
635
661
  generateId() {
636
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
637
- return crypto.randomUUID();
662
+ const g = globalThis;
663
+ if (typeof g.crypto?.randomUUID === "function") {
664
+ return g.crypto.randomUUID();
638
665
  }
639
666
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
640
667
  const r = Math.random() * 16 | 0;
@@ -891,14 +918,11 @@ var Links = class {
891
918
  */
892
919
  async resolve(url) {
893
920
  if (!url || typeof url !== "string") return null;
894
- let parsed;
895
- try {
896
- parsed = new URL(url.trim());
897
- } catch {
898
- debugWarn(`Links.resolve: not a URL: ${url}`);
921
+ const parsed = parseHttpUrl(url);
922
+ if (!parsed) {
923
+ debugWarn(`Links.resolve: not an http(s) URL: ${url}`);
899
924
  return null;
900
925
  }
901
- if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
902
926
  try {
903
927
  const result = await this.client.postPublicToOrigin(
904
928
  parsed.origin,
@@ -1193,29 +1217,364 @@ _Tolinku.linksInstance = null;
1193
1217
  _Tolinku._initialized = false;
1194
1218
  _Tolinku._userId = null;
1195
1219
  var Tolinku = _Tolinku;
1220
+ var DEFAULT_IMAGE_HEIGHT = 200;
1221
+ function dimension(raw) {
1222
+ if (typeof raw === "number" && isFinite(raw) && raw > 0) return raw;
1223
+ if (typeof raw !== "string") return void 0;
1224
+ const value = raw.trim();
1225
+ if (!value) return void 0;
1226
+ if (value.endsWith("%")) {
1227
+ return /^\d+(?:\.\d+)?%$/.test(value) ? value : void 0;
1228
+ }
1229
+ const match = /^(\d+(?:\.\d+)?)(?:px)?$/i.exec(value);
1230
+ if (!match) {
1231
+ debugWarn(`Dimension "${raw}" is not a size React Native understands; ignoring it.`);
1232
+ return void 0;
1233
+ }
1234
+ const parsed = parseFloat(match[1]);
1235
+ return parsed > 0 ? parsed : void 0;
1236
+ }
1237
+ function num(raw, fallback) {
1238
+ if (typeof raw === "number" && isFinite(raw)) return raw;
1239
+ if (typeof raw === "string" && raw.trim()) {
1240
+ const parsed = parseFloat(raw);
1241
+ if (isFinite(parsed)) return parsed;
1242
+ }
1243
+ return fallback;
1244
+ }
1245
+ function alignment(raw) {
1246
+ return raw === "center" || raw === "right" || raw === "justify" ? raw : "left";
1247
+ }
1248
+ var NAMED_COLORS = /* @__PURE__ */ new Set([
1249
+ "transparent",
1250
+ "aliceblue",
1251
+ "antiquewhite",
1252
+ "aqua",
1253
+ "aquamarine",
1254
+ "azure",
1255
+ "beige",
1256
+ "bisque",
1257
+ "black",
1258
+ "blanchedalmond",
1259
+ "blue",
1260
+ "blueviolet",
1261
+ "brown",
1262
+ "burlywood",
1263
+ "cadetblue",
1264
+ "chartreuse",
1265
+ "chocolate",
1266
+ "coral",
1267
+ "cornflowerblue",
1268
+ "cornsilk",
1269
+ "crimson",
1270
+ "cyan",
1271
+ "darkblue",
1272
+ "darkcyan",
1273
+ "darkgoldenrod",
1274
+ "darkgray",
1275
+ "darkgreen",
1276
+ "darkgrey",
1277
+ "darkkhaki",
1278
+ "darkmagenta",
1279
+ "darkolivegreen",
1280
+ "darkorange",
1281
+ "darkorchid",
1282
+ "darkred",
1283
+ "darksalmon",
1284
+ "darkseagreen",
1285
+ "darkslateblue",
1286
+ "darkslategray",
1287
+ "darkslategrey",
1288
+ "darkturquoise",
1289
+ "darkviolet",
1290
+ "deeppink",
1291
+ "deepskyblue",
1292
+ "dimgray",
1293
+ "dimgrey",
1294
+ "dodgerblue",
1295
+ "firebrick",
1296
+ "floralwhite",
1297
+ "forestgreen",
1298
+ "fuchsia",
1299
+ "gainsboro",
1300
+ "ghostwhite",
1301
+ "gold",
1302
+ "goldenrod",
1303
+ "gray",
1304
+ "green",
1305
+ "greenyellow",
1306
+ "grey",
1307
+ "honeydew",
1308
+ "hotpink",
1309
+ "indianred",
1310
+ "indigo",
1311
+ "ivory",
1312
+ "khaki",
1313
+ "lavender",
1314
+ "lavenderblush",
1315
+ "lawngreen",
1316
+ "lemonchiffon",
1317
+ "lightblue",
1318
+ "lightcoral",
1319
+ "lightcyan",
1320
+ "lightgoldenrodyellow",
1321
+ "lightgray",
1322
+ "lightgreen",
1323
+ "lightgrey",
1324
+ "lightpink",
1325
+ "lightsalmon",
1326
+ "lightseagreen",
1327
+ "lightskyblue",
1328
+ "lightslategray",
1329
+ "lightslategrey",
1330
+ "lightsteelblue",
1331
+ "lightyellow",
1332
+ "lime",
1333
+ "limegreen",
1334
+ "linen",
1335
+ "magenta",
1336
+ "maroon",
1337
+ "mediumaquamarine",
1338
+ "mediumblue",
1339
+ "mediumorchid",
1340
+ "mediumpurple",
1341
+ "mediumseagreen",
1342
+ "mediumslateblue",
1343
+ "mediumspringgreen",
1344
+ "mediumturquoise",
1345
+ "mediumvioletred",
1346
+ "midnightblue",
1347
+ "mintcream",
1348
+ "mistyrose",
1349
+ "moccasin",
1350
+ "navajowhite",
1351
+ "navy",
1352
+ "oldlace",
1353
+ "olive",
1354
+ "olivedrab",
1355
+ "orange",
1356
+ "orangered",
1357
+ "orchid",
1358
+ "palegoldenrod",
1359
+ "palegreen",
1360
+ "paleturquoise",
1361
+ "palevioletred",
1362
+ "papayawhip",
1363
+ "peachpuff",
1364
+ "peru",
1365
+ "pink",
1366
+ "plum",
1367
+ "powderblue",
1368
+ "purple",
1369
+ "rebeccapurple",
1370
+ "red",
1371
+ "rosybrown",
1372
+ "royalblue",
1373
+ "saddlebrown",
1374
+ "salmon",
1375
+ "sandybrown",
1376
+ "seagreen",
1377
+ "seashell",
1378
+ "sienna",
1379
+ "silver",
1380
+ "skyblue",
1381
+ "slateblue",
1382
+ "slategray",
1383
+ "slategrey",
1384
+ "snow",
1385
+ "springgreen",
1386
+ "steelblue",
1387
+ "tan",
1388
+ "teal",
1389
+ "thistle",
1390
+ "tomato",
1391
+ "turquoise",
1392
+ "violet",
1393
+ "wheat",
1394
+ "white",
1395
+ "whitesmoke",
1396
+ "yellow",
1397
+ "yellowgreen"
1398
+ ]);
1399
+ function color(raw, fallback) {
1400
+ if (typeof raw !== "string") return fallback;
1401
+ const value = raw.trim();
1402
+ if (!value) return fallback;
1403
+ if (/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value)) return value;
1404
+ if (/^(?:rgb|rgba|hsl|hsla)\(\s*[\d.]+\s*,[^)%]*\)$/i.test(value)) return value;
1405
+ if (NAMED_COLORS.has(value.toLowerCase())) return value.toLowerCase();
1406
+ debugWarn(`Colour "${raw}" is not one React Native can read; using ${fallback}.`);
1407
+ return fallback;
1408
+ }
1409
+ function softVariant(hex) {
1410
+ if (/^#[0-9a-f]{6}$/i.test(hex)) return `${hex}22`;
1411
+ if (/^#[0-9a-f]{3}$/i.test(hex)) {
1412
+ const [, r, g, b] = hex;
1413
+ return `#${r}${r}${g}${g}${b}${b}22`;
1414
+ }
1415
+ return null;
1416
+ }
1417
+ function richText(text, onPressUrl) {
1418
+ if (!text) return "";
1419
+ const regex = /\[([^\]]+)\]\(([^)]+)\)/g;
1420
+ const parts = [];
1421
+ let lastIndex = 0;
1422
+ let match;
1423
+ let key = 0;
1424
+ while ((match = regex.exec(text)) !== null) {
1425
+ if (match.index > lastIndex) parts.push(text.slice(lastIndex, match.index));
1426
+ const [full, label, rawUrl] = match;
1427
+ const url = (rawUrl || "").trim();
1428
+ if (isSafeActionUrl(url)) {
1429
+ parts.push(
1430
+ /* @__PURE__ */ jsxRuntime.jsx(
1431
+ reactNative.Text,
1432
+ {
1433
+ style: { textDecorationLine: "underline" },
1434
+ onPress: () => onPressUrl(url),
1435
+ children: label
1436
+ },
1437
+ `link-${key++}`
1438
+ )
1439
+ );
1440
+ } else {
1441
+ parts.push(full);
1442
+ }
1443
+ lastIndex = regex.lastIndex;
1444
+ }
1445
+ if (lastIndex < text.length) parts.push(text.slice(lastIndex));
1446
+ return parts.length === 1 ? parts[0] : parts;
1447
+ }
1448
+ function useImageRatio(uri, enabled) {
1449
+ const [ratio, setRatio] = React__default.default.useState(null);
1450
+ React__default.default.useEffect(() => {
1451
+ if (!enabled || !uri) return;
1452
+ let cancelled = false;
1453
+ reactNative.Image.getSize(
1454
+ uri,
1455
+ (w, h) => {
1456
+ if (!cancelled && w > 0 && h > 0) setRatio(w / h);
1457
+ },
1458
+ () => {
1459
+ }
1460
+ );
1461
+ return () => {
1462
+ cancelled = true;
1463
+ };
1464
+ }, [uri, enabled]);
1465
+ return ratio;
1466
+ }
1467
+ function MessageImage({
1468
+ uri,
1469
+ width,
1470
+ height,
1471
+ borderRadius,
1472
+ borderWidth,
1473
+ borderColor,
1474
+ alt
1475
+ }) {
1476
+ const wantsNaturalHeight = height === void 0;
1477
+ const ratio = useImageRatio(uri, wantsNaturalHeight);
1478
+ const style = {
1479
+ width: width ?? "100%",
1480
+ borderRadius,
1481
+ alignSelf: "center",
1482
+ marginBottom: 8,
1483
+ ...borderWidth > 0 ? { borderWidth, borderColor } : {},
1484
+ ...wantsNaturalHeight ? ratio ? { aspectRatio: ratio } : { height: DEFAULT_IMAGE_HEIGHT } : { height }
1485
+ };
1486
+ return /* @__PURE__ */ jsxRuntime.jsx(
1487
+ reactNative.Image,
1488
+ {
1489
+ source: { uri },
1490
+ style,
1491
+ resizeMode: wantsNaturalHeight && !ratio ? "contain" : "cover",
1492
+ accessibilityLabel: alt
1493
+ }
1494
+ );
1495
+ }
1496
+ function StoreBadge({
1497
+ uri,
1498
+ height,
1499
+ label,
1500
+ onPress
1501
+ }) {
1502
+ const usable = !!uri && isSafeUrl(uri);
1503
+ const ratio = useImageRatio(usable ? uri : "", usable);
1504
+ const usableHeight = height > 0 ? height : 44;
1505
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.TouchableOpacity, { onPress, activeOpacity: 0.7, accessibilityRole: "button", children: usable ? /* @__PURE__ */ jsxRuntime.jsx(
1506
+ reactNative.Image,
1507
+ {
1508
+ source: { uri },
1509
+ style: { height: usableHeight, width: usableHeight * (ratio || 3.47), marginHorizontal: 6 },
1510
+ resizeMode: "contain",
1511
+ accessibilityLabel: label
1512
+ }
1513
+ ) : (
1514
+ // A text link rather than a blank space, for the case where the badge
1515
+ // artwork itself cannot be loaded.
1516
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: "#1B1B1B", fontSize: 15, fontWeight: "600", marginHorizontal: 6 }, children: label })
1517
+ ) });
1518
+ }
1519
+ var SUPPORTED = /* @__PURE__ */ new Set([
1520
+ "Heading",
1521
+ "TextBlock",
1522
+ "Image",
1523
+ "Button",
1524
+ "DeepLinkButton",
1525
+ "Section",
1526
+ "Spacer",
1527
+ "Divider",
1528
+ "AppIcon",
1529
+ "StoreButtons"
1530
+ ]);
1531
+ function drawsAnything(content, app) {
1532
+ return (content || []).some((c) => {
1533
+ if (!c || !SUPPORTED.has(c.type)) return false;
1534
+ const props = c.props || {};
1535
+ if (c.type === "Image") return isSafeUrl(props.url || "");
1536
+ if (c.type === "DeepLinkButton") return !!app?.deep_link_url;
1537
+ if (c.type === "StoreButtons") {
1538
+ const ios = props.showIos !== false && (props.iosUrlOverride || app?.ios_store_url);
1539
+ const android = props.showAndroid !== false && (props.androidUrlOverride || app?.android_store_url);
1540
+ return !!(ios || android);
1541
+ }
1542
+ return true;
1543
+ });
1544
+ }
1545
+ var MAX_SECTION_DEPTH = 20;
1196
1546
  function PuckComponentRenderer({ component, messageId, options }) {
1197
- const { props } = component;
1547
+ if (!component || typeof component !== "object" || typeof component.type !== "string") return null;
1548
+ const props = component.props && typeof component.props === "object" ? component.props : {};
1549
+ const app = options.app;
1550
+ const follow = (url) => {
1551
+ if (options.onButtonPress) options.onButtonPress(url, messageId);
1552
+ else reactNative.Linking.openURL(url).catch(() => {
1553
+ });
1554
+ };
1198
1555
  switch (component.type) {
1199
1556
  case "Heading": {
1557
+ const fontSize = num(props.fontSize, 28);
1200
1558
  const style = {
1201
- fontSize: props.fontSize || 28,
1559
+ fontSize,
1202
1560
  fontWeight: "700",
1203
- color: props.color || "#1B1B1B",
1204
- textAlign: props.alignment || "left",
1205
- lineHeight: (props.fontSize || 28) * 1.2,
1561
+ color: color(props.color, "#1B1B1B"),
1562
+ textAlign: alignment(props.alignment),
1563
+ lineHeight: fontSize * 1.2,
1206
1564
  marginBottom: 8
1207
1565
  };
1208
1566
  return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style, children: props.text || "" });
1209
1567
  }
1210
1568
  case "TextBlock": {
1569
+ const fontSize = num(props.fontSize, 15);
1211
1570
  const style = {
1212
- fontSize: props.fontSize || 15,
1213
- color: props.color || "#555555",
1214
- textAlign: props.alignment || "left",
1215
- lineHeight: (props.fontSize || 15) * 1.5,
1571
+ fontSize,
1572
+ color: color(props.color, "#555555"),
1573
+ textAlign: alignment(props.alignment),
1574
+ lineHeight: fontSize * 1.5,
1216
1575
  marginBottom: 8
1217
1576
  };
1218
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style, children: props.content || "" });
1577
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style, children: richText(props.content || "", follow) });
1219
1578
  }
1220
1579
  case "Image": {
1221
1580
  const imageUrl = props.url || "";
@@ -1227,82 +1586,85 @@ function PuckComponentRenderer({ component, messageId, options }) {
1227
1586
  debugWarn(`Image URL blocked (unsafe protocol): ${imageUrl}`);
1228
1587
  return null;
1229
1588
  }
1230
- const widthRaw = props.width || "100%";
1231
- let imageWidth = "100%";
1232
- if (widthRaw.endsWith("px")) {
1233
- imageWidth = parseInt(widthRaw, 10);
1234
- } else if (widthRaw.endsWith("%")) {
1235
- imageWidth = widthRaw;
1236
- } else {
1237
- const parsed = parseInt(widthRaw, 10);
1238
- imageWidth = isNaN(parsed) ? "100%" : parsed;
1239
- }
1240
- const style = {
1241
- width: imageWidth,
1242
- height: props.height || 200,
1243
- borderRadius: props.borderRadius || 8,
1244
- alignSelf: "center",
1245
- marginBottom: 8
1246
- };
1247
1589
  return /* @__PURE__ */ jsxRuntime.jsx(
1248
- reactNative.Image,
1590
+ MessageImage,
1249
1591
  {
1250
- source: { uri: imageUrl },
1251
- style,
1252
- resizeMode: "cover",
1253
- accessibilityLabel: props.alt || ""
1592
+ uri: imageUrl,
1593
+ width: dimension(props.width) ?? "100%",
1594
+ height: dimension(props.height),
1595
+ borderRadius: num(props.borderRadius, 8),
1596
+ borderWidth: num(props.borderWidth, 0),
1597
+ borderColor: color(props.borderColor, "#1B1B1B"),
1598
+ alt: props.alt || ""
1254
1599
  }
1255
1600
  );
1256
1601
  }
1257
- case "Button": {
1602
+ case "Button":
1603
+ case "DeepLinkButton": {
1604
+ const isDeepLink = component.type === "DeepLinkButton";
1605
+ const action = isDeepLink ? app?.deep_link_url || "" : props.action || "";
1606
+ const label = isDeepLink ? props.label || "Open in App" : props.label || "";
1607
+ if (isDeepLink && !action) return null;
1258
1608
  const handlePress = () => {
1259
- const action = props.action || "";
1260
1609
  if (!action) return;
1261
- if (!isSafeUrl(action)) {
1262
- debugWarn(`Button action URL blocked (unsafe protocol): ${action}`);
1610
+ if (action === "close") {
1611
+ options.onRequestClose?.();
1263
1612
  return;
1264
1613
  }
1265
- if (options.onButtonPress) {
1266
- options.onButtonPress(action, messageId);
1267
- } else {
1268
- reactNative.Linking.openURL(action).catch(() => {
1269
- });
1614
+ if (!isSafeActionUrl(action)) {
1615
+ debugWarn(`Button action URL blocked (unsafe protocol): ${action}`);
1616
+ return;
1270
1617
  }
1618
+ follow(action);
1271
1619
  };
1620
+ const variant = props.style || "filled";
1621
+ const isOutline = variant === "outline";
1622
+ const tint = variant === "soft" ? softVariant(color(props.bgColor, "#1B1B1B")) : null;
1623
+ const isSoft = tint !== null;
1624
+ const baseColor = color(props.bgColor, "#1B1B1B");
1625
+ const background = isOutline ? "transparent" : isSoft ? tint : baseColor;
1626
+ const labelColor = isOutline || isSoft ? baseColor : color(props.textColor, "#ffffff");
1272
1627
  const containerStyle = {
1273
- backgroundColor: props.bgColor || "#1B1B1B",
1274
- borderRadius: props.borderRadius || 8,
1275
- paddingVertical: 10,
1276
- paddingHorizontal: 20,
1628
+ backgroundColor: background,
1629
+ borderRadius: num(props.borderRadius, 8),
1630
+ paddingVertical: 12,
1631
+ paddingHorizontal: 24,
1277
1632
  marginVertical: 8,
1278
1633
  alignItems: "center",
1279
- ...props.fullWidth ? { width: "100%" } : {}
1634
+ ...isOutline ? { borderWidth: 2, borderColor: baseColor } : {},
1635
+ // A button that is not full width is a compact, centred one. Without
1636
+ // alignSelf it stretches to the column anyway, which made the setting
1637
+ // do nothing at all.
1638
+ ...props.fullWidth ? { width: "100%" } : { alignSelf: "center" }
1280
1639
  };
1281
1640
  const textStyle = {
1282
- color: props.textColor || "#ffffff",
1283
- fontSize: props.fontSize || 16,
1641
+ color: labelColor,
1642
+ fontSize: num(props.fontSize, 16),
1284
1643
  fontWeight: "600"
1285
1644
  };
1286
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.TouchableOpacity, { onPress: handlePress, style: containerStyle, activeOpacity: 0.7, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: textStyle, children: props.label || "Click" }) });
1645
+ const emoji = props.emoji || "";
1646
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.TouchableOpacity, { onPress: handlePress, style: containerStyle, activeOpacity: 0.7, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: textStyle, children: emoji ? `${emoji} ${label}` : label }) });
1287
1647
  }
1288
1648
  case "Section": {
1289
- const children = props.children || [];
1649
+ const sectionId = typeof props.id === "string" && props.id ? props.id : null;
1650
+ const depth = options.depth || 0;
1651
+ const children = sectionId && depth < MAX_SECTION_DEPTH ? options.zones?.[`${sectionId}:content`] || [] : [];
1290
1652
  const containerStyle = {
1291
- backgroundColor: props.bgColor || void 0,
1292
- padding: props.padding || 16,
1293
- borderRadius: props.borderRadius || 0,
1653
+ backgroundColor: typeof props.bgColor === "string" && props.bgColor ? color(props.bgColor, "transparent") : void 0,
1654
+ padding: num(props.padding, 16),
1655
+ borderRadius: num(props.borderRadius, 0),
1294
1656
  marginVertical: 8
1295
1657
  };
1296
- const bgImage = props.bgImage || "";
1297
1658
  const content = children.map((child, index) => /* @__PURE__ */ jsxRuntime.jsx(
1298
1659
  PuckComponentRenderer,
1299
1660
  {
1300
1661
  component: child,
1301
1662
  messageId,
1302
- options
1663
+ options: { ...options, depth: depth + 1 }
1303
1664
  },
1304
- `${messageId}-section-${index}-${child.type}`
1665
+ `${messageId}-section-${index}-${child?.type}`
1305
1666
  ));
1667
+ const bgImage = props.bgImage || "";
1306
1668
  if (bgImage) {
1307
1669
  if (!isSafeUrl(bgImage)) {
1308
1670
  debugWarn(`Section background image URL blocked (unsafe protocol): ${bgImage}`);
@@ -1314,32 +1676,93 @@ function PuckComponentRenderer({ component, messageId, options }) {
1314
1676
  source: { uri: bgImage },
1315
1677
  style: containerStyle,
1316
1678
  resizeMode: props.bgSize === "contain" ? "contain" : "cover",
1317
- imageStyle: { borderRadius: props.borderRadius || 0 },
1679
+ imageStyle: { borderRadius: num(props.borderRadius, 0) },
1318
1680
  children: content
1319
1681
  }
1320
1682
  );
1321
1683
  }
1322
1684
  return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: containerStyle, children: content });
1323
1685
  }
1324
- case "Spacer": {
1325
- const style = {
1326
- height: props.height || 24
1327
- };
1328
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style });
1686
+ case "Spacer":
1687
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: { height: num(props.height, 24) } });
1688
+ case "Divider":
1689
+ return /* @__PURE__ */ jsxRuntime.jsx(
1690
+ reactNative.View,
1691
+ {
1692
+ style: {
1693
+ borderTopWidth: num(props.thickness, 1),
1694
+ borderTopColor: color(props.color, "#e5e5e5"),
1695
+ marginVertical: 8
1696
+ }
1697
+ }
1698
+ );
1699
+ case "AppIcon": {
1700
+ const size = num(props.size, 80);
1701
+ const borderRadius = num(props.borderRadius, 16);
1702
+ const iconUrl = app?.icon_url || "";
1703
+ if (!iconUrl || !isSafeUrl(iconUrl)) {
1704
+ return /* @__PURE__ */ jsxRuntime.jsx(
1705
+ reactNative.View,
1706
+ {
1707
+ style: { width: size, height: size, borderRadius, backgroundColor: "#f0f0f0", alignSelf: "center", marginBottom: 8 }
1708
+ }
1709
+ );
1710
+ }
1711
+ return /* @__PURE__ */ jsxRuntime.jsx(
1712
+ reactNative.Image,
1713
+ {
1714
+ source: { uri: iconUrl },
1715
+ style: { width: size, height: size, borderRadius, alignSelf: "center", marginBottom: 8 },
1716
+ resizeMode: "cover",
1717
+ accessibilityLabel: app?.name || "App icon"
1718
+ }
1719
+ );
1329
1720
  }
1330
- case "Divider": {
1331
- const style = {
1332
- borderTopWidth: props.thickness || 1,
1333
- borderTopColor: props.color || "#e5e5e5",
1334
- marginVertical: 8
1335
- };
1336
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style });
1721
+ case "StoreButtons": {
1722
+ const iosUrl = props.iosUrlOverride || app?.ios_store_url || "";
1723
+ const androidUrl = props.androidUrlOverride || app?.android_store_url || "";
1724
+ const showIos = props.showIos !== false && !!iosUrl;
1725
+ const showAndroid = props.showAndroid !== false && !!androidUrl;
1726
+ if (!showIos && !showAndroid) return null;
1727
+ const height = num(props.height, 44);
1728
+ const alignment2 = props.alignment;
1729
+ const justifyContent = alignment2 === "left" ? "flex-start" : alignment2 === "right" ? "flex-end" : "center";
1730
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: { flexDirection: "row", justifyContent, alignItems: "center", flexWrap: "wrap", marginVertical: 8 }, children: [
1731
+ showIos ? /* @__PURE__ */ jsxRuntime.jsx(
1732
+ StoreBadge,
1733
+ {
1734
+ uri: app?.ios_badge_url,
1735
+ height,
1736
+ label: "Download on the App Store",
1737
+ onPress: () => follow(iosUrl)
1738
+ },
1739
+ "ios"
1740
+ ) : null,
1741
+ showAndroid ? /* @__PURE__ */ jsxRuntime.jsx(
1742
+ StoreBadge,
1743
+ {
1744
+ uri: app?.android_badge_url,
1745
+ height,
1746
+ label: "Get it on Google Play",
1747
+ onPress: () => follow(androidUrl)
1748
+ },
1749
+ "android"
1750
+ ) : null
1751
+ ] });
1337
1752
  }
1338
1753
  default:
1754
+ debugWarn(`Message component "${component.type}" is not supported here; skipping it.`);
1339
1755
  return null;
1340
1756
  }
1341
1757
  }
1342
- function MessageModal({ message, visible, onClose, options }) {
1758
+ function gradientStartColor(gradient) {
1759
+ if (typeof gradient !== "string" || !gradient) return null;
1760
+ const match = /#[0-9a-f]{3,8}|rgba?\([^)]*\)/i.exec(gradient);
1761
+ if (!match) return null;
1762
+ const validated = color(match[0], "");
1763
+ return validated || null;
1764
+ }
1765
+ function MessageModal({ message, visible, onClose, options, app }) {
1343
1766
  if (!message) {
1344
1767
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
1345
1768
  }
@@ -1348,6 +1771,18 @@ function MessageModal({ message, visible, onClose, options }) {
1348
1771
  options.onDismiss?.(message.id);
1349
1772
  onClose();
1350
1773
  };
1774
+ const rootProps = message.content?.root?.props || {};
1775
+ const background = gradientStartColor(rootProps.bgGradient) || (typeof rootProps.bgColor === "string" && rootProps.bgColor ? color(rootProps.bgColor, "") : "") || message.background_color || "#ffffff";
1776
+ const cardStyle = {
1777
+ backgroundColor: background,
1778
+ padding: Math.max(0, num(rootProps.padding, 20)),
1779
+ // Clamped, unlike the other authored numbers. A padding of zero is a
1780
+ // choice; a width of zero is the whole message gone, and the field's own
1781
+ // minimum is zero. The bounds and the default match the server renderer.
1782
+ maxWidth: Math.min(2e3, Math.max(100, num(rootProps.contentWidth, 480)))
1783
+ };
1784
+ const content = message.content?.content || [];
1785
+ const hasDesignedContent = drawsAnything(content, app);
1351
1786
  return /* @__PURE__ */ jsxRuntime.jsx(
1352
1787
  reactNative.Modal,
1353
1788
  {
@@ -1355,7 +1790,7 @@ function MessageModal({ message, visible, onClose, options }) {
1355
1790
  transparent: true,
1356
1791
  animationType: "fade",
1357
1792
  onRequestClose: handleDismiss,
1358
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { style: styles.overlay, onPress: handleDismiss, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Pressable, { style: [styles.card, { backgroundColor: message.background_color || "#ffffff" }], onPress: () => {
1793
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { style: styles.overlay, onPress: handleDismiss, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Pressable, { style: [styles.card, cardStyle], onPress: () => {
1359
1794
  }, children: [
1360
1795
  /* @__PURE__ */ jsxRuntime.jsx(
1361
1796
  reactNative.TouchableOpacity,
@@ -1372,15 +1807,23 @@ function MessageModal({ message, visible, onClose, options }) {
1372
1807
  {
1373
1808
  style: styles.scrollContent,
1374
1809
  showsVerticalScrollIndicator: false,
1375
- children: message.content?.content?.map((component, index) => /* @__PURE__ */ jsxRuntime.jsx(
1810
+ children: hasDesignedContent ? content.map((component, index) => /* @__PURE__ */ jsxRuntime.jsx(
1376
1811
  PuckComponentRenderer,
1377
1812
  {
1378
1813
  component,
1379
1814
  messageId: message.id,
1380
- options
1815
+ options: {
1816
+ ...options,
1817
+ zones: message.content?.zones,
1818
+ app,
1819
+ onRequestClose: handleDismiss
1820
+ }
1381
1821
  },
1382
1822
  `${message.id}-${index}-${component.type}`
1383
- ))
1823
+ )) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1824
+ message.title ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles.fallbackTitle, children: message.title }) : null,
1825
+ message.body ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles.fallbackBody, children: message.body }) : null
1826
+ ] })
1384
1827
  }
1385
1828
  )
1386
1829
  ] }) })
@@ -1396,11 +1839,9 @@ var styles = reactNative.StyleSheet.create({
1396
1839
  },
1397
1840
  card: {
1398
1841
  position: "relative",
1399
- maxWidth: 375,
1400
1842
  width: "90%",
1401
1843
  maxHeight: "80%",
1402
1844
  borderRadius: 16,
1403
- padding: 24,
1404
1845
  shadowColor: "#000",
1405
1846
  shadowOffset: { width: 0, height: 20 },
1406
1847
  shadowOpacity: 0.3,
@@ -1426,6 +1867,19 @@ var styles = reactNative.StyleSheet.create({
1426
1867
  },
1427
1868
  scrollContent: {
1428
1869
  marginTop: 8
1870
+ },
1871
+ // Used only when a message has no designed content, so its title and body
1872
+ // are all there is to show.
1873
+ fallbackTitle: {
1874
+ fontSize: 20,
1875
+ fontWeight: "700",
1876
+ color: "#1B1B1B",
1877
+ marginBottom: 8
1878
+ },
1879
+ fallbackBody: {
1880
+ fontSize: 15,
1881
+ lineHeight: 22,
1882
+ color: "#555555"
1429
1883
  }
1430
1884
  });
1431
1885
  function TolinkuMessages({
@@ -1434,19 +1888,20 @@ function TolinkuMessages({
1434
1888
  onDismiss,
1435
1889
  onButtonPress
1436
1890
  }) {
1437
- const [message, setMessage] = react.useState(null);
1438
- const [visible, setVisible] = react.useState(false);
1439
- const onDismissRef = react.useRef(onDismiss);
1891
+ const [message, setMessage] = React.useState(null);
1892
+ const [visible, setVisible] = React.useState(false);
1893
+ const [app, setApp] = React.useState(null);
1894
+ const onDismissRef = React.useRef(onDismiss);
1440
1895
  onDismissRef.current = onDismiss;
1441
- const onButtonPressRef = react.useRef(onButtonPress);
1896
+ const onButtonPressRef = React.useRef(onButtonPress);
1442
1897
  onButtonPressRef.current = onButtonPress;
1443
- const options = react.useMemo(() => ({
1898
+ const options = React.useMemo(() => ({
1444
1899
  trigger,
1445
1900
  triggerValue,
1446
1901
  onDismiss: (messageId) => onDismissRef.current?.(messageId),
1447
1902
  onButtonPress: (action, messageId) => onButtonPressRef.current?.(action, messageId)
1448
1903
  }), [trigger, triggerValue]);
1449
- react.useEffect(() => {
1904
+ React.useEffect(() => {
1450
1905
  let cancelled = false;
1451
1906
  async function fetchMessages() {
1452
1907
  try {
@@ -1456,7 +1911,9 @@ function TolinkuMessages({
1456
1911
  const userId = Tolinku.getUserId();
1457
1912
  if (userId) params.user_id = userId;
1458
1913
  const data = await client.get("/v1/api/messages", params);
1459
- if (cancelled || !data.messages || data.messages.length === 0) return;
1914
+ if (cancelled) return;
1915
+ if (data.app) setApp(data.app);
1916
+ if (!data.messages || data.messages.length === 0) return;
1460
1917
  const candidates = [];
1461
1918
  for (const m of data.messages) {
1462
1919
  if (triggerValue && m.trigger_value !== triggerValue) continue;
@@ -1480,7 +1937,7 @@ function TolinkuMessages({
1480
1937
  cancelled = true;
1481
1938
  };
1482
1939
  }, [trigger, triggerValue]);
1483
- const handleClose = react.useCallback(() => {
1940
+ const handleClose = React.useCallback(() => {
1484
1941
  setVisible(false);
1485
1942
  setMessage(null);
1486
1943
  }, []);
@@ -1490,7 +1947,8 @@ function TolinkuMessages({
1490
1947
  message,
1491
1948
  visible,
1492
1949
  onClose: handleClose,
1493
- options
1950
+ options,
1951
+ app
1494
1952
  }
1495
1953
  );
1496
1954
  }