@trypattern/sdk 0.1.37 → 0.1.39

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.
Files changed (42) hide show
  1. package/dist/bookings.d.ts +1 -7
  2. package/dist/bookingsStore.d.ts +1 -7
  3. package/dist/cli/app.js +71 -2
  4. package/dist/cli/guidance.d.ts +8 -0
  5. package/dist/cli/guidance.js +121 -0
  6. package/dist/cli/instructions.d.ts +21 -0
  7. package/dist/cli/instructions.js +206 -0
  8. package/dist/components/Calendar.d.ts +3 -1
  9. package/dist/components/Calendar.js +5 -5
  10. package/dist/components/Checkbox.js +2 -2
  11. package/dist/components/Dialog.js +10 -1
  12. package/dist/components/ScrollArea.js +4 -2
  13. package/dist/components/Select.d.ts +2 -1
  14. package/dist/components/Select.js +14 -3
  15. package/dist/components/calendarDates.d.ts +4 -3
  16. package/dist/components/calendarDates.js +8 -7
  17. package/dist/inquiriesStore.d.ts +1 -7
  18. package/dist/publishWire.d.ts +37 -59
  19. package/dist/publishWire.js +4 -2
  20. package/dist/requests.d.ts +14 -32
  21. package/dist/requests.js +12 -5
  22. package/dist/rules/lintPlugin.js +4 -1
  23. package/dist/server/index.d.ts +2 -0
  24. package/dist/server/index.js +1 -0
  25. package/dist/server/inquiries.d.ts +7 -2
  26. package/dist/server/inquiries.js +2 -2
  27. package/dist/server/requestSources.d.ts +41 -0
  28. package/dist/server/requestSources.js +157 -0
  29. package/dist/server/requests.d.ts +7 -3
  30. package/dist/server/requests.js +130 -62
  31. package/dist/start.js +14 -0
  32. package/dist/theme/tokens.stylex.d.ts +1 -0
  33. package/dist/theme/tokens.stylex.js +2 -1
  34. package/docs/CHANGELOG.json +331 -0
  35. package/docs/PATTERN.md +87 -0
  36. package/docs/app.md +74 -0
  37. package/docs/data.md +109 -0
  38. package/docs/history/agents.json +1141 -0
  39. package/docs/look.md +147 -0
  40. package/docs/requests.md +115 -0
  41. package/docs/state.md +142 -0
  42. package/package.json +4 -3
@@ -1,22 +1,33 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Select as BaseSelect } from '@base-ui/react/select';
3
3
  import * as stylex from '@stylexjs/stylex';
4
- import { borders, colors, controls, iconSizes, layers, motion, radii, shadows, space } from "../theme/tokens.stylex.js";
4
+ import { borders, colors, controls, fontWeights, iconSizes, layers, motion, radii, shadows, space } from "../theme/tokens.stylex.js";
5
5
  import { fieldCorners, controlSizes } from "./controlLook.js";
6
6
  import { Icon } from "./Icon.js";
7
7
  import { interact } from "./interaction.js";
8
8
  import { Popup } from "./Popup.js";
9
9
  import { PopupItem } from "./PopupItem.js";
10
- export function Select({ label, value, options, size = 'md', disabled = false, onChange, style }) {
10
+ export function Select({ label, isLabelHidden = true, value, options, size = 'md', disabled = false, onChange, style }) {
11
+ const trigger = (_jsxs(BaseSelect.Trigger, { "aria-label": isLabelHidden ? label : undefined, className: (state) => stylex.props(styles.trigger, controlSizes[size], fieldCorners[size], triggerPaddings[size], styles.triggerLook, !disabled && styles.hoverable, state.open && styles.triggerOpen, disabled && styles.disabled, isLabelHidden && style).className, children: [_jsx("span", { ...stylex.props(styles.values), children: options.map((option) => (_jsx("span", { "aria-hidden": option.value !== value, ...stylex.props(styles.value, option.value !== value && styles.valueHidden), children: option.label }, option.value))) }), _jsx(BaseSelect.Icon, { className: stylex.props(styles.chevron).className, children: _jsx(Icon, { name: "chevronUpDown", size: size }) })] }));
11
12
  return (_jsxs(BaseSelect.Root, { items: options, value: value, disabled: disabled, onValueChange: (next) => {
12
13
  if (next === null)
13
14
  return;
14
15
  interact({ primitive: 'Select', event: 'change', label });
15
16
  onChange(next);
16
- }, children: [_jsxs(BaseSelect.Trigger, { "aria-label": label, className: (state) => stylex.props(styles.trigger, controlSizes[size], fieldCorners[size], triggerPaddings[size], styles.triggerLook, !disabled && styles.hoverable, state.open && styles.triggerOpen, disabled && styles.disabled, style).className, children: [_jsx("span", { ...stylex.props(styles.values), children: options.map((option) => (_jsx("span", { "aria-hidden": option.value !== value, ...stylex.props(styles.value, option.value !== value && styles.valueHidden), children: option.label }, option.value))) }), _jsx(BaseSelect.Icon, { className: stylex.props(styles.chevron).className, children: _jsx(Icon, { name: "chevronUpDown", size: size }) })] }), _jsx(BaseSelect.Portal, { children: _jsx(BaseSelect.Positioner, { alignItemWithTrigger: false, side: "bottom", align: "start", sideOffset: 4, className: stylex.props(styles.positioner).className, children: _jsx(BaseSelect.Popup, { render: (props, state) => (_jsx(Popup, { ...props, kind: "select", isOpen: state.open, transitionStatus: state.transitionStatus })), children: options.map((option) => (_jsxs(BaseSelect.Item, { value: option.value, render: (props, state) => (_jsx(PopupItem, { ...props, kind: "select", isHighlighted: state.highlighted })), children: [_jsx("span", { ...stylex.props(styles.indicator), children: _jsx(BaseSelect.ItemIndicator, { className: stylex.props(styles.check).className, children: _jsx(Icon, { name: "check" }) }) }), _jsx(BaseSelect.ItemText, { children: option.label })] }, option.value))) }) }) })] }));
17
+ }, children: [isLabelHidden ? (trigger) : (_jsxs("div", { ...stylex.props(styles.field, style), children: [_jsx(BaseSelect.Label, { className: stylex.props(styles.label).className, children: label }), trigger] })), _jsx(BaseSelect.Portal, { children: _jsx(BaseSelect.Positioner, { alignItemWithTrigger: false, side: "bottom", align: "start", sideOffset: 4, className: stylex.props(styles.positioner).className, children: _jsx(BaseSelect.Popup, { render: (props, state) => (_jsx(Popup, { ...props, kind: "select", isOpen: state.open, transitionStatus: state.transitionStatus })), children: options.map((option) => (_jsxs(BaseSelect.Item, { value: option.value, render: (props, state) => (_jsx(PopupItem, { ...props, kind: "select", isHighlighted: state.highlighted })), children: [_jsx("span", { ...stylex.props(styles.indicator), children: _jsx(BaseSelect.ItemIndicator, { className: stylex.props(styles.check).className, children: _jsx(Icon, { name: "check" }) }) }), _jsx(BaseSelect.ItemText, { children: option.label })] }, option.value))) }) }) })] }));
17
18
  }
18
19
  const focusRing = `inset 0 0 0 ${borders.hairline} ${colors.brandBorderFocus}, 0 0 0 ${borders.thin} ${colors.brandBorderFocus}, ${shadows.default}`;
19
20
  const styles = stylex.create({
21
+ field: {
22
+ display: 'flex',
23
+ flexDirection: 'column',
24
+ gap: space.xs,
25
+ minWidth: 0
26
+ },
27
+ label: {
28
+ fontWeight: fontWeights.medium,
29
+ color: colors.primaryForeground
30
+ },
20
31
  trigger: {
21
32
  display: 'flex',
22
33
  flexShrink: 0,
@@ -2,13 +2,14 @@ export declare function monthOf(date: string): string;
2
2
  export declare function addDays(date: string, days: number): string;
3
3
  export declare function addMonths(date: string, months: number): string;
4
4
  export declare function daysIn(month: string): number;
5
- export declare function weekdayIndex(date: string): number;
6
- export declare function weeksOf(month: string): readonly (readonly (string | null)[])[];
5
+ export type WeekStart = 'monday' | 'sunday';
6
+ export declare function weekdayIndex(date: string, weekStart?: WeekStart): number;
7
+ export declare function weeksOf(month: string, weekStart?: WeekStart): readonly (readonly (string | null)[])[];
7
8
  export declare function localToday(): string;
8
9
  export declare function monthTitle(month: string, locale: string | undefined): string;
9
10
  export declare function dayLabel(date: string, locale: string | undefined): string;
10
11
  export declare function dayNumber(date: string, locale: string | undefined): string;
11
- export declare function weekdayNames(locale: string | undefined): readonly {
12
+ export declare function weekdayNames(locale: string | undefined, weekStart?: WeekStart): readonly {
12
13
  short: string;
13
14
  long: string;
14
15
  }[];
@@ -22,13 +22,14 @@ export function daysIn(month) {
22
22
  const start = utc(`${month}-01`);
23
23
  return new Date(Date.UTC(start.getUTCFullYear(), start.getUTCMonth() + 1, 0)).getUTCDate();
24
24
  }
25
- export function weekdayIndex(date) {
26
- return (utc(date).getUTCDay() + 6) % 7;
25
+ const SHIFTS = { monday: 6, sunday: 0 };
26
+ export function weekdayIndex(date, weekStart = 'monday') {
27
+ return (utc(date).getUTCDay() + SHIFTS[weekStart]) % 7;
27
28
  }
28
- export function weeksOf(month) {
29
+ export function weeksOf(month, weekStart = 'monday') {
29
30
  const first = `${month}-01`;
30
31
  const cells = [
31
- ...Array.from({ length: weekdayIndex(first) }, () => null),
32
+ ...Array.from({ length: weekdayIndex(first, weekStart) }, () => null),
32
33
  ...Array.from({ length: daysIn(month) }, (_, index) => addDays(first, index))
33
34
  ];
34
35
  const weeks = [];
@@ -64,8 +65,8 @@ export function dayNumber(date, locale) {
64
65
  timeZone: 'UTC'
65
66
  }).format(utc(date));
66
67
  }
67
- export function weekdayNames(locale) {
68
- const monday = '2024-01-01';
68
+ export function weekdayNames(locale, weekStart = 'monday') {
69
+ const first = weekStart === 'sunday' ? '2023-12-31' : '2024-01-01';
69
70
  const short = new Intl.DateTimeFormat(locale, {
70
71
  weekday: 'short',
71
72
  timeZone: 'UTC'
@@ -75,7 +76,7 @@ export function weekdayNames(locale) {
75
76
  timeZone: 'UTC'
76
77
  });
77
78
  return Array.from({ length: 7 }, (_, index) => {
78
- const day = utc(addDays(monday, index));
79
+ const day = utc(addDays(first, index));
79
80
  return {
80
81
  short: [...short.format(day)].slice(0, 2).join(''),
81
82
  long: long.format(day)
@@ -56,13 +56,7 @@ export declare const inquiries: {
56
56
  readonly columns: {
57
57
  readonly source: z.ZodString;
58
58
  readonly requestId: z.ZodString;
59
- readonly kind: z.ZodEnum<{
60
- done: "done";
61
- accepted: "accepted";
62
- declined: "declined";
63
- replied: "replied";
64
- received: "received";
65
- }>;
59
+ readonly kind: z.ZodString;
66
60
  };
67
61
  readonly access: {
68
62
  readonly read: "server";
@@ -473,12 +473,8 @@ export declare const requestEntry: z.ZodObject<{
473
473
  replied: "replied";
474
474
  }>;
475
475
  needsAnswer: z.ZodBoolean;
476
- actions: z.ZodArray<z.ZodEnum<{
477
- done: "done";
478
- accept: "accept";
479
- decline: "decline";
480
- reply: "reply";
481
- }>>;
476
+ actions: z.ZodArray<z.ZodString>;
477
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
482
478
  revision: z.ZodNumber;
483
479
  receivedAt: z.ZodString;
484
480
  history: z.ZodArray<z.ZodObject<{
@@ -488,8 +484,10 @@ export declare const requestEntry: z.ZodObject<{
488
484
  declined: "declined";
489
485
  replied: "replied";
490
486
  received: "received";
487
+ acted: "acted";
491
488
  }>;
492
489
  at: z.ZodString;
490
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
493
491
  }, z.core.$strip>>;
494
492
  notice: z.ZodNullable<z.ZodObject<{
495
493
  status: z.ZodEnum<{
@@ -567,12 +565,8 @@ export declare const requestList: z.ZodObject<{
567
565
  replied: "replied";
568
566
  }>;
569
567
  needsAnswer: z.ZodBoolean;
570
- actions: z.ZodArray<z.ZodEnum<{
571
- done: "done";
572
- accept: "accept";
573
- decline: "decline";
574
- reply: "reply";
575
- }>>;
568
+ actions: z.ZodArray<z.ZodString>;
569
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
576
570
  revision: z.ZodNumber;
577
571
  receivedAt: z.ZodString;
578
572
  history: z.ZodArray<z.ZodObject<{
@@ -582,8 +576,10 @@ export declare const requestList: z.ZodObject<{
582
576
  declined: "declined";
583
577
  replied: "replied";
584
578
  received: "received";
579
+ acted: "acted";
585
580
  }>;
586
581
  at: z.ZodString;
582
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
587
583
  }, z.core.$strip>>;
588
584
  notice: z.ZodNullable<z.ZodObject<{
589
585
  status: z.ZodEnum<{
@@ -1291,12 +1287,8 @@ export declare const publishServices: {
1291
1287
  replied: "replied";
1292
1288
  }>;
1293
1289
  needsAnswer: z.ZodBoolean;
1294
- actions: z.ZodArray<z.ZodEnum<{
1295
- done: "done";
1296
- accept: "accept";
1297
- decline: "decline";
1298
- reply: "reply";
1299
- }>>;
1290
+ actions: z.ZodArray<z.ZodString>;
1291
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1300
1292
  revision: z.ZodNumber;
1301
1293
  receivedAt: z.ZodString;
1302
1294
  history: z.ZodArray<z.ZodObject<{
@@ -1306,8 +1298,10 @@ export declare const publishServices: {
1306
1298
  declined: "declined";
1307
1299
  replied: "replied";
1308
1300
  received: "received";
1301
+ acted: "acted";
1309
1302
  }>;
1310
1303
  at: z.ZodString;
1304
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1311
1305
  }, z.core.$strip>>;
1312
1306
  notice: z.ZodNullable<z.ZodObject<{
1313
1307
  status: z.ZodEnum<{
@@ -1386,12 +1380,8 @@ export declare const publishServices: {
1386
1380
  replied: "replied";
1387
1381
  }>;
1388
1382
  needsAnswer: z.ZodBoolean;
1389
- actions: z.ZodArray<z.ZodEnum<{
1390
- done: "done";
1391
- accept: "accept";
1392
- decline: "decline";
1393
- reply: "reply";
1394
- }>>;
1383
+ actions: z.ZodArray<z.ZodString>;
1384
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1395
1385
  revision: z.ZodNumber;
1396
1386
  receivedAt: z.ZodString;
1397
1387
  history: z.ZodArray<z.ZodObject<{
@@ -1401,8 +1391,10 @@ export declare const publishServices: {
1401
1391
  declined: "declined";
1402
1392
  replied: "replied";
1403
1393
  received: "received";
1394
+ acted: "acted";
1404
1395
  }>;
1405
1396
  at: z.ZodString;
1397
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1406
1398
  }, z.core.$strip>>;
1407
1399
  notice: z.ZodNullable<z.ZodObject<{
1408
1400
  status: z.ZodEnum<{
@@ -1475,12 +1467,8 @@ export declare const publishServices: {
1475
1467
  replied: "replied";
1476
1468
  }>;
1477
1469
  needsAnswer: z.ZodBoolean;
1478
- actions: z.ZodArray<z.ZodEnum<{
1479
- done: "done";
1480
- accept: "accept";
1481
- decline: "decline";
1482
- reply: "reply";
1483
- }>>;
1470
+ actions: z.ZodArray<z.ZodString>;
1471
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1484
1472
  revision: z.ZodNumber;
1485
1473
  receivedAt: z.ZodString;
1486
1474
  history: z.ZodArray<z.ZodObject<{
@@ -1490,8 +1478,10 @@ export declare const publishServices: {
1490
1478
  declined: "declined";
1491
1479
  replied: "replied";
1492
1480
  received: "received";
1481
+ acted: "acted";
1493
1482
  }>;
1494
1483
  at: z.ZodString;
1484
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1495
1485
  }, z.core.$strip>>;
1496
1486
  notice: z.ZodNullable<z.ZodObject<{
1497
1487
  status: z.ZodEnum<{
@@ -1530,11 +1520,7 @@ export declare const publishServices: {
1530
1520
  }, z.core.$strip>>;
1531
1521
  }, z.core.$strip>, false>>;
1532
1522
  readonly act: NoInfer<import("./services.ts").ServiceCall<"/apps/:name/requests/:source/:id/act", {
1533
- action: z.ZodEnum<{
1534
- done: "done";
1535
- accept: "accept";
1536
- decline: "decline";
1537
- }>;
1523
+ action: z.ZodString;
1538
1524
  revision: z.ZodNumber;
1539
1525
  operation: z.ZodString;
1540
1526
  }, z.ZodObject<{
@@ -1570,12 +1556,8 @@ export declare const publishServices: {
1570
1556
  replied: "replied";
1571
1557
  }>;
1572
1558
  needsAnswer: z.ZodBoolean;
1573
- actions: z.ZodArray<z.ZodEnum<{
1574
- done: "done";
1575
- accept: "accept";
1576
- decline: "decline";
1577
- reply: "reply";
1578
- }>>;
1559
+ actions: z.ZodArray<z.ZodString>;
1560
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1579
1561
  revision: z.ZodNumber;
1580
1562
  receivedAt: z.ZodString;
1581
1563
  history: z.ZodArray<z.ZodObject<{
@@ -1585,8 +1567,10 @@ export declare const publishServices: {
1585
1567
  declined: "declined";
1586
1568
  replied: "replied";
1587
1569
  received: "received";
1570
+ acted: "acted";
1588
1571
  }>;
1589
1572
  at: z.ZodString;
1573
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1590
1574
  }, z.core.$strip>>;
1591
1575
  notice: z.ZodNullable<z.ZodObject<{
1592
1576
  status: z.ZodEnum<{
@@ -1662,12 +1646,8 @@ export declare const publishServices: {
1662
1646
  replied: "replied";
1663
1647
  }>;
1664
1648
  needsAnswer: z.ZodBoolean;
1665
- actions: z.ZodArray<z.ZodEnum<{
1666
- done: "done";
1667
- accept: "accept";
1668
- decline: "decline";
1669
- reply: "reply";
1670
- }>>;
1649
+ actions: z.ZodArray<z.ZodString>;
1650
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1671
1651
  revision: z.ZodNumber;
1672
1652
  receivedAt: z.ZodString;
1673
1653
  history: z.ZodArray<z.ZodObject<{
@@ -1677,8 +1657,10 @@ export declare const publishServices: {
1677
1657
  declined: "declined";
1678
1658
  replied: "replied";
1679
1659
  received: "received";
1660
+ acted: "acted";
1680
1661
  }>;
1681
1662
  at: z.ZodString;
1663
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1682
1664
  }, z.core.$strip>>;
1683
1665
  notice: z.ZodNullable<z.ZodObject<{
1684
1666
  status: z.ZodEnum<{
@@ -1751,12 +1733,8 @@ export declare const publishServices: {
1751
1733
  replied: "replied";
1752
1734
  }>;
1753
1735
  needsAnswer: z.ZodBoolean;
1754
- actions: z.ZodArray<z.ZodEnum<{
1755
- done: "done";
1756
- accept: "accept";
1757
- decline: "decline";
1758
- reply: "reply";
1759
- }>>;
1736
+ actions: z.ZodArray<z.ZodString>;
1737
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1760
1738
  revision: z.ZodNumber;
1761
1739
  receivedAt: z.ZodString;
1762
1740
  history: z.ZodArray<z.ZodObject<{
@@ -1766,8 +1744,10 @@ export declare const publishServices: {
1766
1744
  declined: "declined";
1767
1745
  replied: "replied";
1768
1746
  received: "received";
1747
+ acted: "acted";
1769
1748
  }>;
1770
1749
  at: z.ZodString;
1750
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1771
1751
  }, z.core.$strip>>;
1772
1752
  notice: z.ZodNullable<z.ZodObject<{
1773
1753
  status: z.ZodEnum<{
@@ -1848,12 +1828,8 @@ export declare const publishServices: {
1848
1828
  replied: "replied";
1849
1829
  }>;
1850
1830
  needsAnswer: z.ZodBoolean;
1851
- actions: z.ZodArray<z.ZodEnum<{
1852
- done: "done";
1853
- accept: "accept";
1854
- decline: "decline";
1855
- reply: "reply";
1856
- }>>;
1831
+ actions: z.ZodArray<z.ZodString>;
1832
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
1857
1833
  revision: z.ZodNumber;
1858
1834
  receivedAt: z.ZodString;
1859
1835
  history: z.ZodArray<z.ZodObject<{
@@ -1863,8 +1839,10 @@ export declare const publishServices: {
1863
1839
  declined: "declined";
1864
1840
  replied: "replied";
1865
1841
  received: "received";
1842
+ acted: "acted";
1866
1843
  }>;
1867
1844
  at: z.ZodString;
1845
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1868
1846
  }, z.core.$strip>>;
1869
1847
  notice: z.ZodNullable<z.ZodObject<{
1870
1848
  status: z.ZodEnum<{
@@ -4,7 +4,7 @@ export { appTitle };
4
4
  export { ASSERTION_SECONDS, MEDIA_WRITE, NEXT_PAGE_HEADER, TABLES_READ, TABLES_WRITE, assertionKey, signAssertion } from "./patternAccess.js";
5
5
  export { REQUESTS_ACT, REQUESTS_READ } from "./patternAccess.js";
6
6
  export { REQUESTS_PATH, REQUEST_SYNC_PAGE, requestBound, requestCard, requestSync } from "./requests.js";
7
- import { requestCard } from "./requests.js";
7
+ import { requestActionName, requestCard } from "./requests.js";
8
8
  import { call, defineServices } from "./services.js";
9
9
  export const DASHBOARD_URL = 'https://onpattern.app';
10
10
  export const APPS_DOMAIN = 'onpattern.app';
@@ -455,7 +455,9 @@ export const publishServices = defineServices({
455
455
  act: call({
456
456
  post: '/apps/:name/requests/:source/:id/act',
457
457
  input: {
458
- action: z.enum(['accept', 'decline', 'done']),
458
+ action: requestActionName.refine((action) => action !== 'reply', {
459
+ message: 'Send a reply with requests.reply'
460
+ }),
459
461
  revision: z.number().int(),
460
462
  operation
461
463
  },
@@ -2,6 +2,8 @@ import { z } from 'zod';
2
2
  import type { Table } from './table.ts';
3
3
  export declare const REQUEST_KINDS: readonly ["booking", "inquiry"];
4
4
  export declare const REQUEST_ACTIONS: readonly ["accept", "decline", "reply", "done"];
5
+ export declare const REQUEST_ACTION_NAME: RegExp;
6
+ export declare const requestActionName: z.ZodString;
5
7
  export declare const REQUEST_STATUSES: readonly ["requested", "accepted", "declined", "cancelled", "open", "replied", "done"];
6
8
  export declare const REQUEST_EVENTS: readonly ["received", "accepted", "declined", "replied", "done"];
7
9
  export declare const NOTICE_STATUSES: readonly ["pending", "sending", "sent", "failed"];
@@ -31,13 +33,7 @@ export declare const requestEvents: import("./table.ts").TableOf<"requestEvents"
31
33
  readonly columns: {
32
34
  readonly source: z.ZodString;
33
35
  readonly requestId: z.ZodString;
34
- readonly kind: z.ZodEnum<{
35
- done: "done";
36
- accepted: "accepted";
37
- declined: "declined";
38
- replied: "replied";
39
- received: "received";
40
- }>;
36
+ readonly kind: z.ZodString;
41
37
  };
42
38
  readonly access: {
43
39
  readonly read: "server";
@@ -110,13 +106,7 @@ export declare const requestTables: {
110
106
  readonly columns: {
111
107
  readonly source: z.ZodString;
112
108
  readonly requestId: z.ZodString;
113
- readonly kind: z.ZodEnum<{
114
- done: "done";
115
- accepted: "accepted";
116
- declined: "declined";
117
- replied: "replied";
118
- received: "received";
119
- }>;
109
+ readonly kind: z.ZodString;
120
110
  };
121
111
  readonly access: {
122
112
  readonly read: "server";
@@ -204,12 +194,8 @@ export declare const requestCard: z.ZodObject<{
204
194
  replied: "replied";
205
195
  }>;
206
196
  needsAnswer: z.ZodBoolean;
207
- actions: z.ZodArray<z.ZodEnum<{
208
- done: "done";
209
- accept: "accept";
210
- decline: "decline";
211
- reply: "reply";
212
- }>>;
197
+ actions: z.ZodArray<z.ZodString>;
198
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
213
199
  revision: z.ZodNumber;
214
200
  receivedAt: z.ZodString;
215
201
  history: z.ZodArray<z.ZodObject<{
@@ -219,8 +205,10 @@ export declare const requestCard: z.ZodObject<{
219
205
  declined: "declined";
220
206
  replied: "replied";
221
207
  received: "received";
208
+ acted: "acted";
222
209
  }>;
223
210
  at: z.ZodString;
211
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
224
212
  }, z.core.$strip>>;
225
213
  notice: z.ZodNullable<z.ZodObject<{
226
214
  status: z.ZodEnum<{
@@ -269,12 +257,8 @@ export declare const requestSync: z.ZodObject<{
269
257
  replied: "replied";
270
258
  }>;
271
259
  needsAnswer: z.ZodBoolean;
272
- actions: z.ZodArray<z.ZodEnum<{
273
- done: "done";
274
- accept: "accept";
275
- decline: "decline";
276
- reply: "reply";
277
- }>>;
260
+ actions: z.ZodArray<z.ZodString>;
261
+ actionLabels: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
278
262
  revision: z.ZodNumber;
279
263
  receivedAt: z.ZodString;
280
264
  history: z.ZodArray<z.ZodObject<{
@@ -284,8 +268,10 @@ export declare const requestSync: z.ZodObject<{
284
268
  declined: "declined";
285
269
  replied: "replied";
286
270
  received: "received";
271
+ acted: "acted";
287
272
  }>;
288
273
  at: z.ZodString;
274
+ label: z.ZodDefault<z.ZodNullable<z.ZodString>>;
289
275
  }, z.core.$strip>>;
290
276
  notice: z.ZodNullable<z.ZodObject<{
291
277
  status: z.ZodEnum<{
@@ -303,12 +289,7 @@ export type RequestSync = z.output<typeof requestSync>;
303
289
  export declare const requestAct: z.ZodObject<{
304
290
  source: z.ZodString;
305
291
  id: z.ZodString;
306
- action: z.ZodEnum<{
307
- done: "done";
308
- accept: "accept";
309
- decline: "decline";
310
- reply: "reply";
311
- }>;
292
+ action: z.ZodString;
312
293
  revision: z.ZodNumber;
313
294
  operation: z.ZodString;
314
295
  }, z.core.$strip>;
@@ -347,6 +328,7 @@ export type Inquiry = {
347
328
  detail: string;
348
329
  } | null;
349
330
  };
331
+ export declare const SOURCE_NAME: RegExp;
350
332
  export declare function inquiry<T extends Table>(table: T, options: InquiryOptions<T>): Inquiry;
351
333
  export declare const inquiryValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
352
334
  export declare const inquiryServices: {
package/dist/requests.js CHANGED
@@ -3,6 +3,8 @@ import { call, defineServices } from "./services.js";
3
3
  import { patternTable } from "./table.js";
4
4
  export const REQUEST_KINDS = ['booking', 'inquiry'];
5
5
  export const REQUEST_ACTIONS = ['accept', 'decline', 'reply', 'done'];
6
+ export const REQUEST_ACTION_NAME = /^[a-z][a-zA-Z0-9]{0,39}$/;
7
+ export const requestActionName = z.string().regex(REQUEST_ACTION_NAME);
6
8
  export const REQUEST_STATUSES = [
7
9
  'requested',
8
10
  'accepted',
@@ -43,7 +45,7 @@ export const requestEvents = patternTable('requestEvents', {
43
45
  columns: {
44
46
  source: z.string(),
45
47
  requestId: z.string(),
46
- kind: z.enum(REQUEST_EVENTS)
48
+ kind: z.string()
47
49
  },
48
50
  access: {
49
51
  read: 'server',
@@ -107,10 +109,15 @@ export const requestCard = z.object({
107
109
  message: z.string(),
108
110
  status: z.enum(REQUEST_STATUSES),
109
111
  needsAnswer: z.boolean(),
110
- actions: z.array(z.enum(REQUEST_ACTIONS)),
112
+ actions: z.array(requestActionName),
113
+ actionLabels: z.record(z.string(), z.string()).default({}),
111
114
  revision: z.number().int(),
112
115
  receivedAt: z.string(),
113
- history: z.array(z.object({ kind: z.enum(REQUEST_EVENTS), at: z.string() })),
116
+ history: z.array(z.object({
117
+ kind: z.enum([...REQUEST_EVENTS, 'acted']),
118
+ at: z.string(),
119
+ label: z.string().nullable().default(null)
120
+ })),
114
121
  notice: z
115
122
  .object({
116
123
  status: z.enum(NOTICE_STATUSES),
@@ -126,7 +133,7 @@ export const requestSync = z.object({
126
133
  export const requestAct = z.object({
127
134
  source: z.string().min(1).max(60),
128
135
  id: z.string().min(1).max(200),
129
- action: z.enum(REQUEST_ACTIONS),
136
+ action: requestActionName,
130
137
  revision: z.number().int(),
131
138
  operation: z.string().min(8).max(100)
132
139
  });
@@ -142,7 +149,7 @@ export async function requestBound(act) {
142
149
  .map((byte) => byte.toString(16).padStart(2, '0'))
143
150
  .join('');
144
151
  }
145
- const SOURCE_NAME = /^[a-z][a-zA-Z0-9]{0,39}$/;
152
+ export const SOURCE_NAME = /^[a-z][a-zA-Z0-9]{0,39}$/;
146
153
  export function inquiry(table, options) {
147
154
  if (!SOURCE_NAME.test(options.source) || options.source === 'bookings') {
148
155
  throw new Error(`inquiry source '${options.source}' needs a short camelCase name of its own, like 'orders'`);
@@ -4,6 +4,7 @@ const APP_THEME_FILE = 'src/theme/theme.ts';
4
4
  const APP_COLORS_FILE = 'src/theme/colors.stylex.ts';
5
5
  const SCROLL_AREA_FILE = 'src/components/ScrollArea.tsx';
6
6
  const GALLERY_FILE = 'src/components/Gallery.tsx';
7
+ const DIALOG_FILE = 'src/components/Dialog.tsx';
7
8
  const SELECTABLE_FILE = 'src/components/Text.tsx';
8
9
  const PRIMITIVE_ELEMENTS = new Set([
9
10
  'button',
@@ -382,7 +383,9 @@ const hoverUsesHighlight = styleRule((declarations) => declarations
382
383
  message: HOVER_USES_HIGHLIGHT_MESSAGE
383
384
  })));
384
385
  const scrollViewOnly = styleRule((declarations, context) => {
385
- if (inFile(context, SCROLL_AREA_FILE) || inFile(context, GALLERY_FILE)) {
386
+ if (inFile(context, SCROLL_AREA_FILE) ||
387
+ inFile(context, GALLERY_FILE) ||
388
+ inFile(context, DIALOG_FILE)) {
386
389
  return [];
387
390
  }
388
391
  return declarations
@@ -4,6 +4,8 @@ export { notifyOwner } from './authService.ts';
4
4
  export type { OwnerNote } from './authService.ts';
5
5
  export { bookings } from './bookings.ts';
6
6
  export { inquiries } from './inquiries.ts';
7
+ export { deliverRequestNotices, recordRequest, requestSource, requestSources } from './requestSources.ts';
8
+ export type { CustomRequestSource, RequestActionContext, RequestRow, RequestSourceAction, RequestSourceOptions } from './requestSources.ts';
7
9
  export type { BookingsOptions } from './bookings.ts';
8
10
  export { seedSql, serveTables, sqlTable, sqlTables } from './tables.ts';
9
11
  export { refused } from '../services.ts';
@@ -2,6 +2,7 @@ export { createServer } from "./createServer.js";
2
2
  export { notifyOwner } from "./authService.js";
3
3
  export { bookings } from "./bookings.js";
4
4
  export { inquiries } from "./inquiries.js";
5
+ export { deliverRequestNotices, recordRequest, requestSource, requestSources } from "./requestSources.js";
5
6
  export { seedSql, serveTables, sqlTable, sqlTables } from "./tables.js";
6
7
  export { refused } from "../services.js";
7
8
  export { serveServices } from "./services.js";
@@ -2,8 +2,13 @@ import type { D1Database } from '@cloudflare/workers-types';
2
2
  import type { Inquiry } from '../requests.ts';
3
3
  import type { Table } from '../table.ts';
4
4
  import type { ServerBlock } from './env.ts';
5
- type Stored = Readonly<Record<string, unknown>>;
5
+ import type { OwnerNotice } from './requests.ts';
6
+ export type Stored = Readonly<Record<string, unknown>>;
6
7
  export declare function textOf(value: unknown): string;
7
8
  export declare function storedRows(d1: D1Database, table: Table, ids: readonly string[]): Promise<ReadonlyMap<string, Stored>>;
9
+ export declare function fieldsOf(inquiry: Inquiry, row: Stored): {
10
+ label: string;
11
+ value: string;
12
+ }[];
13
+ export declare function noticeOf(inquiry: Inquiry, row: Stored, link: string): OwnerNotice;
8
14
  export declare function inquiries(sources: readonly Inquiry[]): ServerBlock;
9
- export {};
@@ -28,7 +28,7 @@ export async function storedRows(d1, table, ids) {
28
28
  Object.fromEntries(keys.map((key) => [key, row[snakeCase(key)]]))
29
29
  ]));
30
30
  }
31
- function fieldsOf(inquiry, row) {
31
+ export function fieldsOf(inquiry, row) {
32
32
  return [
33
33
  ...inquiry.fields.flatMap(({ key, label }) => {
34
34
  const value = textOf(row[key]);
@@ -37,7 +37,7 @@ function fieldsOf(inquiry, row) {
37
37
  { label: 'Email', value: textOf(row[inquiry.email]) }
38
38
  ];
39
39
  }
40
- function noticeOf(inquiry, row, link) {
40
+ export function noticeOf(inquiry, row, link) {
41
41
  const name = textOf(row[inquiry.name]);
42
42
  const message = inquiry.message === null ? '' : textOf(row[inquiry.message]);
43
43
  const noun = inquiry.title.toLowerCase();
@@ -0,0 +1,41 @@
1
+ import type { D1Database, D1PreparedStatement } from '@cloudflare/workers-types';
2
+ import type { Context } from 'hono';
3
+ import type { Inquiry, InquiryOptions } from '../requests.ts';
4
+ import type { Table } from '../table.ts';
5
+ import type { ServerBlock, ServerEnv } from './env.ts';
6
+ import type { Stored } from './inquiries.ts';
7
+ export type RequestRow = Stored;
8
+ export type RequestActionContext = {
9
+ readonly d1: D1Database;
10
+ readonly id: string;
11
+ readonly row: RequestRow;
12
+ };
13
+ export type RequestSourceAction = {
14
+ readonly label?: string;
15
+ readonly resolves?: boolean;
16
+ readonly can?: (row: RequestRow) => boolean;
17
+ readonly run: (context: RequestActionContext) => readonly D1PreparedStatement[] | Promise<readonly D1PreparedStatement[]>;
18
+ };
19
+ export type RequestSourceOptions<T extends Table> = InquiryOptions<T> & {
20
+ readonly kind?: 'booking' | 'inquiry';
21
+ readonly actions?: Readonly<Record<string, RequestSourceAction>>;
22
+ };
23
+ type DeclaredAction = RequestSourceAction & {
24
+ readonly name: string;
25
+ readonly label: string;
26
+ readonly resolves: boolean;
27
+ };
28
+ export type CustomRequestSource = {
29
+ readonly source: string;
30
+ readonly table: Table;
31
+ readonly kind: 'booking' | 'inquiry';
32
+ readonly described: Inquiry;
33
+ readonly actions: readonly DeclaredAction[];
34
+ };
35
+ export declare function requestSource<T extends Table>(table: T, options: RequestSourceOptions<T>): CustomRequestSource;
36
+ export declare function recordRequest(c: Context<ServerEnv>, source: CustomRequestSource, row: RequestRow & {
37
+ readonly id: string;
38
+ }): D1PreparedStatement[];
39
+ export declare function deliverRequestNotices(c: Context<ServerEnv>): Promise<void>;
40
+ export declare function requestSources(sources: readonly CustomRequestSource[]): ServerBlock;
41
+ export {};