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