@trypattern/sdk 0.1.38 → 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.
- package/dist/bookings.d.ts +1 -7
- package/dist/bookingsStore.d.ts +1 -7
- package/dist/cli/app.js +71 -2
- package/dist/cli/guidance.d.ts +8 -0
- package/dist/cli/guidance.js +121 -0
- package/dist/cli/instructions.d.ts +21 -0
- package/dist/cli/instructions.js +206 -0
- package/dist/inquiriesStore.d.ts +1 -7
- package/dist/publishWire.d.ts +37 -59
- package/dist/publishWire.js +4 -2
- package/dist/requests.d.ts +14 -32
- package/dist/requests.js +12 -5
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1 -0
- package/dist/server/inquiries.d.ts +7 -2
- package/dist/server/inquiries.js +2 -2
- package/dist/server/requestSources.d.ts +41 -0
- package/dist/server/requestSources.js +157 -0
- package/dist/server/requests.d.ts +7 -3
- package/dist/server/requests.js +130 -62
- package/docs/CHANGELOG.json +331 -0
- package/docs/PATTERN.md +87 -0
- package/docs/app.md +74 -0
- package/docs/data.md +109 -0
- package/docs/history/agents.json +1141 -0
- package/docs/look.md +147 -0
- package/docs/requests.md +115 -0
- package/docs/state.md +142 -0
- package/package.json +4 -3
package/dist/publishWire.d.ts
CHANGED
|
@@ -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.
|
|
477
|
-
|
|
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.
|
|
571
|
-
|
|
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.
|
|
1295
|
-
|
|
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.
|
|
1390
|
-
|
|
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.
|
|
1479
|
-
|
|
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.
|
|
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.
|
|
1574
|
-
|
|
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.
|
|
1666
|
-
|
|
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.
|
|
1755
|
-
|
|
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.
|
|
1852
|
-
|
|
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<{
|
package/dist/publishWire.js
CHANGED
|
@@ -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:
|
|
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
|
},
|
package/dist/requests.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
208
|
-
|
|
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.
|
|
273
|
-
|
|
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.
|
|
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.
|
|
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(
|
|
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({
|
|
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:
|
|
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'`);
|
package/dist/server/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/server/index.js
CHANGED
|
@@ -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
|
|
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 {};
|
package/dist/server/inquiries.js
CHANGED
|
@@ -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 {};
|