@tolinku/react-native-sdk 0.6.0 → 0.6.1

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