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