@naculus/connect-appkit-core 0.10.0 → 0.11.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.cjs CHANGED
@@ -1430,6 +1430,25 @@ function relativeExpiry(expiresAt, now, locale) {
1430
1430
  }
1431
1431
  return new Intl.RelativeTimeFormat(locale).format(value, unit);
1432
1432
  }
1433
+ function absoluteUtc(timestamp, locale) {
1434
+ return new Intl.DateTimeFormat(locale, {
1435
+ year: "numeric",
1436
+ month: "short",
1437
+ day: "numeric",
1438
+ hour: "2-digit",
1439
+ minute: "2-digit",
1440
+ hourCycle: "h23",
1441
+ timeZone: "UTC",
1442
+ timeZoneName: "short"
1443
+ }).format(timestamp * 1e3);
1444
+ }
1445
+ function formatPeriodLength(seconds) {
1446
+ const [amount, unit] = seconds % 604800 === 0 ? [seconds / 604800, "week"] : seconds % 86400 === 0 ? [seconds / 86400, "day"] : seconds % 3600 === 0 ? [seconds / 3600, "hour"] : seconds % 60 === 0 ? [seconds / 60, "minute"] : [seconds, "second"];
1447
+ return `${amount} ${unit}${amount === 1 ? "" : "s"}`;
1448
+ }
1449
+ function formatAuthorizationEnforcement(enforcement) {
1450
+ return enforcement === "on-chain" ? "Limits enforced by the blockchain" : enforcement === "device" ? "Limits enforced by this device" : null;
1451
+ }
1433
1452
  function describeAuthorization(input, options = {}) {
1434
1453
  const now = options.now ?? Math.floor(Date.now() / 1e3);
1435
1454
  const locale = options.locale ?? "en";
@@ -1451,23 +1470,23 @@ function describeAuthorization(input, options = {}) {
1451
1470
  perPayment: formatAuthorizationAmount(grant.maxPerPayment, metadata),
1452
1471
  total: formatAuthorizationAmount(grant.maxTotal, metadata),
1453
1472
  count: grant.maxCount ?? null,
1473
+ period: grant.period ? {
1474
+ amount: formatAuthorizationAmount(grant.period.amount, metadata),
1475
+ every: formatPeriodLength(grant.period.seconds),
1476
+ startsAt: absoluteUtc(grant.period.start, locale)
1477
+ } : null,
1454
1478
  rails: grant.rails.map((r) => r.replace("-", " "))
1455
1479
  };
1456
1480
  }),
1457
1481
  expiry: {
1458
1482
  timestamp: input.expiresAt,
1459
- absolute: new Intl.DateTimeFormat(locale, {
1460
- year: "numeric",
1461
- month: "short",
1462
- day: "numeric",
1463
- hour: "2-digit",
1464
- minute: "2-digit",
1465
- hourCycle: "h23",
1466
- timeZone: "UTC",
1467
- timeZoneName: "short"
1468
- }).format(input.expiresAt * 1e3),
1483
+ absolute: absoluteUtc(input.expiresAt, locale),
1469
1484
  relative: relativeExpiry(input.expiresAt, now, locale)
1470
1485
  },
1486
+ enforcement: options.enforcement ?? null,
1487
+ enforcementLabel: formatAuthorizationEnforcement(
1488
+ options.enforcement ?? null
1489
+ ),
1471
1490
  warnings: flags.map(
1472
1491
  (flag) => flag === "unrestricted-recipient-legacy" ? "This key can pay any recipient." : "This key can do more than shown here."
1473
1492
  )
@@ -1481,6 +1500,7 @@ var REFUSAL_SENTENCES = {
1481
1500
  "over-per-payment": "This amount exceeds the per-payment limit.",
1482
1501
  "over-total": "This amount exceeds the remaining total limit.",
1483
1502
  "over-count": "This authorization has reached its payment count limit.",
1503
+ "period-limit-exceeded": "This amount exceeds the limit for the current period.",
1484
1504
  "rail-not-allowed": "This payment rail is not allowed.",
1485
1505
  "invalid-authorization": "The authorization or spend request is invalid."
1486
1506
  };