@composable-os/client 0.1.0-beta.11 → 0.1.0-beta.13

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.
@@ -0,0 +1,686 @@
1
+ import type { ClientHolding, PackClient } from "./hooks.ts";
2
+ /** How an item's value reads. Money is only ever the host's own items (stage 52's figures). */
3
+ export type TodayFormat = "count" | "percent" | "money";
4
+ /** What tapping an item opens. */
5
+ export type TodayTarget =
6
+ /** Its drill-in rows (`today.rows`). */
7
+ {
8
+ kind: "rows";
9
+ }
10
+ /** The approvals waiting for this person. */
11
+ | {
12
+ kind: "approvals";
13
+ }
14
+ /** The notice inbox. */
15
+ | {
16
+ kind: "notices";
17
+ }
18
+ /** On the web, a pack's staff screen (stage 47); a phone opens the rows instead. */
19
+ | {
20
+ kind: "screen";
21
+ pack: string;
22
+ screen: string;
23
+ };
24
+ /** One number on Today (`today.get`'s `items`). */
25
+ export interface TodayItem {
26
+ /** `host.takings`, `bookings.cameToday`: stable, for keys and drill-in. */
27
+ key: string;
28
+ label: string;
29
+ format: TodayFormat;
30
+ /** A count; a percent as 0 to 100; money in the currency's minor unit. */
31
+ value: number;
32
+ /** A money item's currency; null otherwise. */
33
+ currency: string | null;
34
+ /** A second line the host words (`3 payments`), or null. */
35
+ detail: string | null;
36
+ /** The same figure at the same time yesterday or last week, when the item compares. */
37
+ compare: {
38
+ against: "yesterday" | "lastWeek";
39
+ value: number;
40
+ } | null;
41
+ state: "ok" | "attention";
42
+ target: TodayTarget;
43
+ }
44
+ /** Today for the signed-in person: the business's local day and its items, in the host's order. */
45
+ export interface TodayAnswer {
46
+ /** The local date, `YYYY-MM-DD`. */
47
+ day: string;
48
+ /** The business's time zone (IANA). */
49
+ zone: string;
50
+ items: TodayItem[];
51
+ }
52
+ /** One row behind an item (`today.rows`): a name and a line, and the record it opens, if any. */
53
+ export interface TodayRow {
54
+ label: string;
55
+ detail: string | null;
56
+ record: {
57
+ object: string;
58
+ id: string;
59
+ } | null;
60
+ }
61
+ /** One alert a person receives, and on which channels (`today.alerts`). */
62
+ export interface TodayAlertSetting {
63
+ key: string;
64
+ label: string;
65
+ on: boolean;
66
+ channels: string[];
67
+ }
68
+ /** A person's alerts and overnight hours (local `HH:MM`, the business's zone). */
69
+ export interface TodayAlerts {
70
+ alerts: TodayAlertSetting[];
71
+ overnight: {
72
+ from: string;
73
+ to: string;
74
+ };
75
+ }
76
+ export type ActionStatus = "pending" | "applied" | "failed" | "skipped" | "rejected" | "expired";
77
+ /** A change set in the queue (`approval.list`'s items), as far as Today reads it. */
78
+ export interface WaitingChangeSet {
79
+ id: string;
80
+ title: string | null;
81
+ userName: string | null;
82
+ actor: string;
83
+ status: "awaiting_review" | "done" | "empty";
84
+ counts: {
85
+ pending: number;
86
+ total: number;
87
+ };
88
+ createdAt: string;
89
+ }
90
+ /** What the host asks before a high-risk approval (ADR 0345). */
91
+ export interface SecondStep {
92
+ label: string;
93
+ confirmLabel: string;
94
+ phrase: string;
95
+ }
96
+ /** One pending action of a change set (`approval.get`'s actions), as far as Today reads it. */
97
+ export interface WaitingAction {
98
+ id: string;
99
+ changeSetId: string;
100
+ operation: string;
101
+ risk: string;
102
+ reason: string;
103
+ status: ActionStatus;
104
+ /** What it changes; with `operation`, what `actionTitle` (core's) words it from. */
105
+ preview: {
106
+ object: string;
107
+ id: string;
108
+ action: string;
109
+ diff: Record<string, unknown>;
110
+ }[];
111
+ /** For a send through a connection: the gatekeeper's own title and description of it. */
112
+ outbound: {
113
+ title: string;
114
+ description: string;
115
+ } | null;
116
+ secondStep: SecondStep | null;
117
+ }
118
+ /** A change set with its actions (`approval.get`). */
119
+ export interface ChangeSetDetail extends WaitingChangeSet {
120
+ actions: WaitingAction[];
121
+ }
122
+ /** What a decision answers. */
123
+ export interface DecisionResult {
124
+ results: {
125
+ actionId: string;
126
+ operation: string;
127
+ status: ActionStatus;
128
+ }[];
129
+ counts: {
130
+ pending: number;
131
+ total: number;
132
+ };
133
+ }
134
+ /** One notice in the inbox (`notification.list`), as far as Today reads it. */
135
+ export interface Notice {
136
+ id: string;
137
+ type: string;
138
+ title: string;
139
+ body: string | null;
140
+ readAt: string | null;
141
+ createdAt: string;
142
+ }
143
+ /** The operations this entry calls, as the generated client types them. */
144
+ export type OwnerOperations = {
145
+ "today.get": {
146
+ kind: "query";
147
+ input: Record<string, never>;
148
+ output: TodayAnswer;
149
+ };
150
+ "today.rows": {
151
+ kind: "query";
152
+ input: {
153
+ key: string;
154
+ };
155
+ output: {
156
+ items: TodayRow[];
157
+ };
158
+ };
159
+ "today.alerts": {
160
+ kind: "query";
161
+ input: Record<string, never>;
162
+ output: TodayAlerts;
163
+ };
164
+ "today.setAlerts": {
165
+ kind: "mutation";
166
+ input: {
167
+ key?: string;
168
+ on?: boolean;
169
+ overnight?: {
170
+ from: string;
171
+ to: string;
172
+ };
173
+ };
174
+ output: TodayAlerts;
175
+ };
176
+ "approval.list": {
177
+ kind: "query";
178
+ input: {
179
+ status?: "awaiting_review" | "all";
180
+ limit?: number;
181
+ };
182
+ output: {
183
+ items: WaitingChangeSet[];
184
+ pendingCount: number;
185
+ };
186
+ };
187
+ "approval.get": {
188
+ kind: "query";
189
+ input: {
190
+ changeSetId: string;
191
+ };
192
+ output: ChangeSetDetail;
193
+ };
194
+ "approval.approve": {
195
+ kind: "mutation";
196
+ input: {
197
+ actionIds?: string[];
198
+ changeSetId?: string;
199
+ note?: string;
200
+ confirm?: string;
201
+ };
202
+ output: DecisionResult;
203
+ };
204
+ "approval.reject": {
205
+ kind: "mutation";
206
+ input: {
207
+ actionIds?: string[];
208
+ changeSetId?: string;
209
+ note?: string;
210
+ };
211
+ output: DecisionResult;
212
+ };
213
+ "notification.list": {
214
+ kind: "query";
215
+ input: {
216
+ unreadOnly?: boolean;
217
+ limit?: number;
218
+ cursor?: string;
219
+ };
220
+ output: {
221
+ items: Notice[];
222
+ unread: number;
223
+ nextCursor: string | null;
224
+ };
225
+ };
226
+ "notification.unreadCount": {
227
+ kind: "query";
228
+ input: Record<string, never>;
229
+ output: {
230
+ unread: number;
231
+ };
232
+ };
233
+ "notification.markRead": {
234
+ kind: "mutation";
235
+ input: {
236
+ ids?: string[];
237
+ all?: boolean;
238
+ };
239
+ output: {
240
+ updated: number;
241
+ };
242
+ };
243
+ "user.me": {
244
+ kind: "query";
245
+ input: Record<string, never>;
246
+ output: {
247
+ id: string;
248
+ name: string;
249
+ role: string;
250
+ permissions: string[];
251
+ };
252
+ };
253
+ };
254
+ export type OwnerClient = PackClient<OwnerOperations>;
255
+ /** An item's value as it reads: `12`, `85%`, or money in the host's currency. */
256
+ export declare function todayValueWords(item: TodayItem, locale?: string): string;
257
+ /** The comparison under a value: `5 yesterday`, `$90.00 last week`, or null when there is none. */
258
+ export declare function todayCompareWords(item: TodayItem, locale?: string): string | null;
259
+ /** The day at the top of the screen, in the business's zone: `Tuesday 24 November`. */
260
+ export declare function todayDayWords(answer: Pick<TodayAnswer, "day" | "zone">, locale?: string): string;
261
+ /** What a setup change says on a phone: the host refuses it there (decision 8). */
262
+ export declare const REVIEW_ON_COMPUTER_WORDS = "Review on a computer";
263
+ /**
264
+ * Whether an action changes how the system is set up (an extension, new fields): listed on the
265
+ * phone with "Review on a computer", never offered Approve. The host refuses it from the app
266
+ * whatever the screen shows.
267
+ */
268
+ export declare function needsComputer(action: Pick<WaitingAction, "risk">): boolean;
269
+ /** The actions still waiting in a change set, in the host's order. */
270
+ export declare function waitingActions(detail: Pick<ChangeSetDetail, "actions">): WaitingAction[];
271
+ /**
272
+ * The input that approves one action. `confirmed` is true once the person pressed the second
273
+ * step's button: its words are sent as the host gave them (ADR 0345); the host decides whether
274
+ * one was needed.
275
+ */
276
+ export declare function approveInput(action: Pick<WaitingAction, "id" | "secondStep">, confirmed?: boolean): OwnerOperations["approval.approve"]["input"];
277
+ /** The input that rejects one action. */
278
+ export declare function rejectInput(action: Pick<WaitingAction, "id">, note?: string): OwnerOperations["approval.reject"]["input"];
279
+ /** What a failed call on Today means, for the screen. */
280
+ export type OwnerFailure = {
281
+ kind: "secondStep";
282
+ step: SecondStep;
283
+ message: string;
284
+ } | {
285
+ kind: "reviewOnComputer";
286
+ message: string;
287
+ } | {
288
+ kind: "notAllowed";
289
+ message: string;
290
+ } | {
291
+ kind: "signIn";
292
+ message: string;
293
+ } | {
294
+ kind: "offline";
295
+ message: string;
296
+ } | {
297
+ kind: "other";
298
+ message: string;
299
+ };
300
+ /** A failed call in the screen's words, keeping the host's message where it has one. */
301
+ export declare function ownerFailure(error: unknown): OwnerFailure;
302
+ /** The reads that carry money, names or an approval's detail: never kept off screen. */
303
+ export declare const TODAY_PRIVATE_QUERIES: readonly ["today.get", "today.rows", "approval.get"];
304
+ /**
305
+ * Drops Today's private reads from the app's query cache: call it when the app goes to the
306
+ * background (`AppState` on a phone) and on sign-out.
307
+ */
308
+ export declare function forgetToday(queryClient: {
309
+ removeQueries(filters: {
310
+ queryKey: readonly unknown[];
311
+ }): unknown;
312
+ }): void;
313
+ /** The app's `useQuery`, as far as these hooks use it. */
314
+ export type OwnerUseQuery = <T>(options: {
315
+ queryKey: readonly unknown[];
316
+ queryFn: () => Promise<T>;
317
+ enabled?: boolean;
318
+ gcTime?: number;
319
+ }) => {
320
+ data: T | undefined;
321
+ isPending: boolean;
322
+ error: unknown;
323
+ refetch?: () => unknown;
324
+ };
325
+ /** The app's `useMutation`, as far as these hooks use it. */
326
+ export type OwnerUseMutation = <I, O>(options: {
327
+ mutationKey: readonly unknown[];
328
+ mutationFn: (input: I) => Promise<O>;
329
+ gcTime?: number;
330
+ }) => {
331
+ mutate(input: I): void;
332
+ mutateAsync(input: I): Promise<O>;
333
+ data: O | undefined;
334
+ isPending: boolean;
335
+ error: unknown;
336
+ reset?: () => void;
337
+ };
338
+ /**
339
+ * The operations each hook calls (ADR 0453). The owner's client holds them all once its release
340
+ * serves them; a release without Today's own operations yet offers the approvals and the inbox.
341
+ */
342
+ export declare const OWNER_HOOKS_CALL: {
343
+ readonly useToday: readonly ["today.get"];
344
+ readonly useTodayRows: readonly ["today.rows"];
345
+ readonly useAlerts: readonly ["today.alerts"];
346
+ readonly useSetAlerts: readonly ["today.setAlerts"];
347
+ readonly useWaiting: readonly ["approval.list"];
348
+ readonly useChangeSet: readonly ["approval.get"];
349
+ readonly useApprove: readonly ["approval.approve"];
350
+ readonly useReject: readonly ["approval.reject"];
351
+ readonly useNotices: readonly ["notification.list"];
352
+ readonly useUnreadCount: readonly ["notification.unreadCount"];
353
+ readonly useMarkRead: readonly ["notification.markRead"];
354
+ readonly useMe: readonly ["user.me"];
355
+ };
356
+ /**
357
+ * Hooks for a React or React Native app:
358
+ * `const today = createOwnerHooks({ useQuery, useMutation }, api)`, with the owner's client (or
359
+ * the staff client, on the web). The hooks it cannot back are not there.
360
+ */
361
+ export declare function createOwnerHooks<C extends ClientHolding>(react: {
362
+ useQuery: OwnerUseQuery;
363
+ useMutation: OwnerUseMutation;
364
+ }, client: C): import("./hooks.ts").HooksFor<{
365
+ /** Today's items for the signed-in person: money among them, so on screen only. */
366
+ useToday(): {
367
+ data: TodayAnswer | undefined;
368
+ isPending: boolean;
369
+ error: unknown;
370
+ refetch?: () => unknown;
371
+ };
372
+ /** One item's rows (they name people): on screen only. `null` reads nothing. */
373
+ useTodayRows(key: string | null): {
374
+ data: {
375
+ items: TodayRow[];
376
+ } | undefined;
377
+ isPending: boolean;
378
+ error: unknown;
379
+ refetch?: () => unknown;
380
+ };
381
+ /** The alerts this person receives and their overnight hours. */
382
+ useAlerts(): {
383
+ data: TodayAlerts | undefined;
384
+ isPending: boolean;
385
+ error: unknown;
386
+ refetch?: () => unknown;
387
+ };
388
+ /** Turn one of their own alerts on or off, or set their overnight hours. */
389
+ useSetAlerts(): {
390
+ mutate(input: {
391
+ key?: string;
392
+ on?: boolean;
393
+ overnight?: {
394
+ from: string;
395
+ to: string;
396
+ };
397
+ }): void;
398
+ mutateAsync(input: {
399
+ key?: string;
400
+ on?: boolean;
401
+ overnight?: {
402
+ from: string;
403
+ to: string;
404
+ };
405
+ }): Promise<TodayAlerts>;
406
+ data: TodayAlerts | undefined;
407
+ isPending: boolean;
408
+ error: unknown;
409
+ reset?: () => void;
410
+ };
411
+ /** The change sets waiting for review that this person sees. */
412
+ useWaiting(): {
413
+ data: {
414
+ items: WaitingChangeSet[];
415
+ pendingCount: number;
416
+ } | undefined;
417
+ isPending: boolean;
418
+ error: unknown;
419
+ refetch?: () => unknown;
420
+ };
421
+ /** One change set with its actions, previews and second steps: on screen only. */
422
+ useChangeSet(changeSetId: string | null): {
423
+ data: ChangeSetDetail | undefined;
424
+ isPending: boolean;
425
+ error: unknown;
426
+ refetch?: () => unknown;
427
+ };
428
+ /** Approve one action (`approveInput`); the host may answer with its second step. */
429
+ useApprove(): {
430
+ mutate(input: {
431
+ actionIds?: string[];
432
+ changeSetId?: string;
433
+ note?: string;
434
+ confirm?: string;
435
+ }): void;
436
+ mutateAsync(input: {
437
+ actionIds?: string[];
438
+ changeSetId?: string;
439
+ note?: string;
440
+ confirm?: string;
441
+ }): Promise<DecisionResult>;
442
+ data: DecisionResult | undefined;
443
+ isPending: boolean;
444
+ error: unknown;
445
+ reset?: () => void;
446
+ };
447
+ /** Reject one action (`rejectInput`). */
448
+ useReject(): {
449
+ mutate(input: {
450
+ actionIds?: string[];
451
+ changeSetId?: string;
452
+ note?: string;
453
+ }): void;
454
+ mutateAsync(input: {
455
+ actionIds?: string[];
456
+ changeSetId?: string;
457
+ note?: string;
458
+ }): Promise<DecisionResult>;
459
+ data: DecisionResult | undefined;
460
+ isPending: boolean;
461
+ error: unknown;
462
+ reset?: () => void;
463
+ };
464
+ /** The notice inbox, newest first. */
465
+ useNotices(unreadOnly?: boolean): {
466
+ data: {
467
+ items: Notice[];
468
+ unread: number;
469
+ nextCursor: string | null;
470
+ } | undefined;
471
+ isPending: boolean;
472
+ error: unknown;
473
+ refetch?: () => unknown;
474
+ };
475
+ /** How many notices are unread. */
476
+ useUnreadCount(): {
477
+ data: {
478
+ unread: number;
479
+ } | undefined;
480
+ isPending: boolean;
481
+ error: unknown;
482
+ refetch?: () => unknown;
483
+ };
484
+ /** Mark notices read: some by id, or all. */
485
+ useMarkRead(): {
486
+ mutate(input: {
487
+ ids?: string[];
488
+ all?: boolean;
489
+ }): void;
490
+ mutateAsync(input: {
491
+ ids?: string[];
492
+ all?: boolean;
493
+ }): Promise<{
494
+ updated: number;
495
+ }>;
496
+ data: {
497
+ updated: number;
498
+ } | undefined;
499
+ isPending: boolean;
500
+ error: unknown;
501
+ reset?: () => void;
502
+ };
503
+ /** Who is signed in. */
504
+ useMe(): {
505
+ data: {
506
+ id: string;
507
+ name: string;
508
+ role: string;
509
+ permissions: string[];
510
+ } | undefined;
511
+ isPending: boolean;
512
+ error: unknown;
513
+ refetch?: () => unknown;
514
+ };
515
+ }, {
516
+ readonly useToday: readonly ["today.get"];
517
+ readonly useTodayRows: readonly ["today.rows"];
518
+ readonly useAlerts: readonly ["today.alerts"];
519
+ readonly useSetAlerts: readonly ["today.setAlerts"];
520
+ readonly useWaiting: readonly ["approval.list"];
521
+ readonly useChangeSet: readonly ["approval.get"];
522
+ readonly useApprove: readonly ["approval.approve"];
523
+ readonly useReject: readonly ["approval.reject"];
524
+ readonly useNotices: readonly ["notification.list"];
525
+ readonly useUnreadCount: readonly ["notification.unreadCount"];
526
+ readonly useMarkRead: readonly ["notification.markRead"];
527
+ readonly useMe: readonly ["user.me"];
528
+ }, import("./hooks.ts").OperationsOf<C>>;
529
+ declare function allOwnerHooks(react: {
530
+ useQuery: OwnerUseQuery;
531
+ useMutation: OwnerUseMutation;
532
+ }, api: OwnerClient): {
533
+ /** Today's items for the signed-in person: money among them, so on screen only. */
534
+ useToday(): {
535
+ data: TodayAnswer | undefined;
536
+ isPending: boolean;
537
+ error: unknown;
538
+ refetch?: () => unknown;
539
+ };
540
+ /** One item's rows (they name people): on screen only. `null` reads nothing. */
541
+ useTodayRows(key: string | null): {
542
+ data: {
543
+ items: TodayRow[];
544
+ } | undefined;
545
+ isPending: boolean;
546
+ error: unknown;
547
+ refetch?: () => unknown;
548
+ };
549
+ /** The alerts this person receives and their overnight hours. */
550
+ useAlerts(): {
551
+ data: TodayAlerts | undefined;
552
+ isPending: boolean;
553
+ error: unknown;
554
+ refetch?: () => unknown;
555
+ };
556
+ /** Turn one of their own alerts on or off, or set their overnight hours. */
557
+ useSetAlerts(): {
558
+ mutate(input: {
559
+ key?: string;
560
+ on?: boolean;
561
+ overnight?: {
562
+ from: string;
563
+ to: string;
564
+ };
565
+ }): void;
566
+ mutateAsync(input: {
567
+ key?: string;
568
+ on?: boolean;
569
+ overnight?: {
570
+ from: string;
571
+ to: string;
572
+ };
573
+ }): Promise<TodayAlerts>;
574
+ data: TodayAlerts | undefined;
575
+ isPending: boolean;
576
+ error: unknown;
577
+ reset?: () => void;
578
+ };
579
+ /** The change sets waiting for review that this person sees. */
580
+ useWaiting(): {
581
+ data: {
582
+ items: WaitingChangeSet[];
583
+ pendingCount: number;
584
+ } | undefined;
585
+ isPending: boolean;
586
+ error: unknown;
587
+ refetch?: () => unknown;
588
+ };
589
+ /** One change set with its actions, previews and second steps: on screen only. */
590
+ useChangeSet(changeSetId: string | null): {
591
+ data: ChangeSetDetail | undefined;
592
+ isPending: boolean;
593
+ error: unknown;
594
+ refetch?: () => unknown;
595
+ };
596
+ /** Approve one action (`approveInput`); the host may answer with its second step. */
597
+ useApprove(): {
598
+ mutate(input: {
599
+ actionIds?: string[];
600
+ changeSetId?: string;
601
+ note?: string;
602
+ confirm?: string;
603
+ }): void;
604
+ mutateAsync(input: {
605
+ actionIds?: string[];
606
+ changeSetId?: string;
607
+ note?: string;
608
+ confirm?: string;
609
+ }): Promise<DecisionResult>;
610
+ data: DecisionResult | undefined;
611
+ isPending: boolean;
612
+ error: unknown;
613
+ reset?: () => void;
614
+ };
615
+ /** Reject one action (`rejectInput`). */
616
+ useReject(): {
617
+ mutate(input: {
618
+ actionIds?: string[];
619
+ changeSetId?: string;
620
+ note?: string;
621
+ }): void;
622
+ mutateAsync(input: {
623
+ actionIds?: string[];
624
+ changeSetId?: string;
625
+ note?: string;
626
+ }): Promise<DecisionResult>;
627
+ data: DecisionResult | undefined;
628
+ isPending: boolean;
629
+ error: unknown;
630
+ reset?: () => void;
631
+ };
632
+ /** The notice inbox, newest first. */
633
+ useNotices(unreadOnly?: boolean): {
634
+ data: {
635
+ items: Notice[];
636
+ unread: number;
637
+ nextCursor: string | null;
638
+ } | undefined;
639
+ isPending: boolean;
640
+ error: unknown;
641
+ refetch?: () => unknown;
642
+ };
643
+ /** How many notices are unread. */
644
+ useUnreadCount(): {
645
+ data: {
646
+ unread: number;
647
+ } | undefined;
648
+ isPending: boolean;
649
+ error: unknown;
650
+ refetch?: () => unknown;
651
+ };
652
+ /** Mark notices read: some by id, or all. */
653
+ useMarkRead(): {
654
+ mutate(input: {
655
+ ids?: string[];
656
+ all?: boolean;
657
+ }): void;
658
+ mutateAsync(input: {
659
+ ids?: string[];
660
+ all?: boolean;
661
+ }): Promise<{
662
+ updated: number;
663
+ }>;
664
+ data: {
665
+ updated: number;
666
+ } | undefined;
667
+ isPending: boolean;
668
+ error: unknown;
669
+ reset?: () => void;
670
+ };
671
+ /** Who is signed in. */
672
+ useMe(): {
673
+ data: {
674
+ id: string;
675
+ name: string;
676
+ role: string;
677
+ permissions: string[];
678
+ } | undefined;
679
+ isPending: boolean;
680
+ error: unknown;
681
+ refetch?: () => unknown;
682
+ };
683
+ };
684
+ /** Every hook of this entry. A block takes the ones it calls: `Pick<OwnerHooks, "useToday">`. */
685
+ export type OwnerHooks = ReturnType<typeof allOwnerHooks>;
686
+ export {};