@buffcore/server 0.0.0-stage → 0.8.40
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +8 -2
- package/dist/access.d.ts +71 -0
- package/dist/access.js +192 -0
- package/dist/acting-account.d.ts +8 -0
- package/dist/acting-account.js +35 -0
- package/dist/action-input.d.ts +9 -0
- package/dist/action-input.js +27 -0
- package/dist/actions.d.ts +60 -0
- package/dist/actions.js +20 -0
- package/dist/actor-kinds.d.ts +37 -0
- package/dist/actor-kinds.js +38 -0
- package/dist/added.d.ts +20 -0
- package/dist/added.js +81 -0
- package/dist/address-guard.d.ts +52 -0
- package/dist/address-guard.js +163 -0
- package/dist/address-ranges.d.ts +2 -0
- package/dist/address-ranges.js +65 -0
- package/dist/address-redirect.d.ts +20 -0
- package/dist/address-redirect.js +64 -0
- package/dist/ai-doors.d.ts +14 -0
- package/dist/ai-doors.js +25 -0
- package/dist/app.d.ts +80 -0
- package/dist/app.js +118 -0
- package/dist/body-validation.d.ts +5 -0
- package/dist/body-validation.js +13 -0
- package/dist/compose.d.ts +47 -0
- package/dist/compose.js +56 -0
- package/dist/composition-extensions.d.ts +22 -0
- package/dist/composition-extensions.js +206 -0
- package/dist/composition-jobs.d.ts +7 -0
- package/dist/composition-jobs.js +39 -0
- package/dist/composition-names.d.ts +24 -0
- package/dist/composition-names.js +68 -0
- package/dist/composition-order.d.ts +8 -0
- package/dist/composition-order.js +59 -0
- package/dist/composition.d.ts +40 -0
- package/dist/composition.js +45 -0
- package/dist/contributions.d.ts +26 -0
- package/dist/contributions.js +80 -0
- package/dist/cors.d.ts +3 -0
- package/dist/cors.js +31 -0
- package/dist/dead-jobs.d.ts +41 -0
- package/dist/dead-jobs.js +87 -0
- package/dist/doors.d.ts +41 -0
- package/dist/doors.js +230 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.js +68 -0
- package/dist/every-minute.d.ts +7 -0
- package/dist/every-minute.js +38 -0
- package/dist/extension-handler.d.ts +23 -0
- package/dist/extension-handler.js +60 -0
- package/dist/extension-manifest.d.ts +35 -0
- package/dist/extension-manifest.js +20 -0
- package/dist/extension-offers.d.ts +4 -0
- package/dist/extension-offers.en.d.ts +10 -0
- package/dist/extension-offers.en.js +10 -0
- package/dist/extension-offers.es.json +10 -0
- package/dist/extension-offers.js +55 -0
- package/dist/extension-uses.d.ts +13 -0
- package/dist/extension-uses.js +32 -0
- package/dist/flow-context.d.ts +30 -0
- package/dist/flow-context.js +72 -0
- package/dist/flow-member-check.d.ts +3 -0
- package/dist/flow-member-check.js +3 -0
- package/dist/flow-member.d.ts +11 -0
- package/dist/flow-member.js +15 -0
- package/dist/flow-run.d.ts +18 -0
- package/dist/flow-run.js +62 -0
- package/dist/flow-system.d.ts +8 -0
- package/dist/flow-system.js +24 -0
- package/dist/headers.d.ts +7 -0
- package/dist/headers.js +16 -0
- package/dist/health.d.ts +26 -0
- package/dist/health.js +58 -0
- package/dist/heartbeat.d.ts +35 -0
- package/dist/heartbeat.js +55 -0
- package/dist/hooks.d.ts +60 -0
- package/dist/hooks.js +0 -0
- package/dist/http.d.ts +41 -0
- package/dist/http.js +160 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +36 -0
- package/dist/job-context.d.ts +3 -0
- package/dist/job-context.js +39 -0
- package/dist/job-run.d.ts +11 -0
- package/dist/job-run.js +100 -0
- package/dist/jobs-table.d.ts +14 -0
- package/dist/jobs-table.js +42 -0
- package/dist/jobs.d.ts +34 -0
- package/dist/jobs.js +91 -0
- package/dist/key-prefix.d.ts +13 -0
- package/dist/key-prefix.js +18 -0
- package/dist/limits.d.ts +23 -0
- package/dist/limits.js +35 -0
- package/dist/mail-from.d.ts +33 -0
- package/dist/mail-from.js +63 -0
- package/dist/mail.d.ts +61 -0
- package/dist/mail.js +132 -0
- package/dist/messages.d.ts +64 -0
- package/dist/messages.js +0 -0
- package/dist/module.d.ts +243 -0
- package/dist/module.js +8 -0
- package/dist/openapi.d.ts +9 -0
- package/dist/openapi.js +23 -0
- package/dist/outbound.d.ts +11 -0
- package/dist/outbound.js +23 -0
- package/dist/page.d.ts +17 -0
- package/dist/page.js +5 -0
- package/dist/privacy.d.ts +26 -0
- package/dist/privacy.js +1 -0
- package/dist/redact.d.ts +7 -0
- package/dist/redact.js +58 -0
- package/dist/registry.d.ts +53 -0
- package/dist/registry.js +69 -0
- package/dist/route-names.d.ts +8 -0
- package/dist/route-names.js +42 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.js +235 -0
- package/dist/services.d.ts +59 -0
- package/dist/services.js +2 -0
- package/dist/settings.d.ts +12 -0
- package/dist/settings.js +30 -0
- package/dist/system-context.d.ts +12 -0
- package/dist/system-context.js +37 -0
- package/dist/test-actor.d.ts +9 -0
- package/dist/test-actor.js +12 -0
- package/dist/testing-redis.d.ts +7 -0
- package/dist/testing-redis.js +41 -0
- package/dist/testing.d.ts +95 -0
- package/dist/testing.js +170 -0
- package/dist/version.d.ts +12 -0
- package/dist/version.js +37 -0
- package/dist/webhooks.d.ts +27 -0
- package/dist/webhooks.js +68 -0
- package/dist/worker.d.ts +28 -0
- package/dist/worker.js +96 -0
- package/package.json +48 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @buffcore/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The BuffCore server: `createApp`, manifest loading, Fastify plugins, the OpenAPI document, jobs and the worker.
|
|
4
|
+
|
|
5
|
+
Part of [BuffApe](https://github.com/buffape/buffape), the open-source way to build a product with AI agents. Start one with `npm create @buffcore@latest my-app`.
|
|
6
|
+
|
|
7
|
+
## License
|
|
8
|
+
|
|
9
|
+
Apache-2.0. Copyright © 2026 BuffApe. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type RouteDef } from '@buffcore/contracts';
|
|
2
|
+
import type { Actor, AuditEntry, Ctx, Subject } from './module.ts';
|
|
3
|
+
/** Who may call a route, and which calls are audited (IDENTITY_ACCESS.md, CONNECT.md). */
|
|
4
|
+
/**
|
|
5
|
+
* A machine door (an API key, an MCP client) or an agent: it reaches only routes a module offers
|
|
6
|
+
* (`mcp: true`). A person, in the console or the app, never comes through a door.
|
|
7
|
+
*/
|
|
8
|
+
export declare const throughDoor: (actor: Actor | null) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Owner may do everything; other operators, and their API keys (`client`), need one of the route's
|
|
11
|
+
* roles. A preview reads, and writes only where a route opts in (`preview: true`); never an admin
|
|
12
|
+
* route. A kind a package adds reaches only routes that name it (their `actors`), and never one
|
|
13
|
+
* with roles. A machine door or an agent reaches only offered
|
|
14
|
+
* routes, and only when the product lets out (`allowOut`, `connect.allowOut`) every sensitive kind
|
|
15
|
+
* the route `carries`. An agent has no roles: its code names its tools. A route that acts on a
|
|
16
|
+
* part of an account then needs the right there (`checkRights`), and every call to an action meets
|
|
17
|
+
* its rule (`doors.ts`).
|
|
18
|
+
*/
|
|
19
|
+
export declare function checkAccess(def: RouteDef, actor: Actor | null, allowOut?: readonly string[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the caller holds the right to run the action `key` on a part of an account (its role
|
|
22
|
+
* there, or a right given to them on the account or that part). Identity answers it, as
|
|
23
|
+
* `identity.rights`; the pipeline reads identity's answer and no other.
|
|
24
|
+
*/
|
|
25
|
+
export type RightsCheck = (ctx: Ctx, key: string, part: Subject, memberDoorDefault?: true) => Promise<boolean>;
|
|
26
|
+
/** The hook point the rights step is read from: identity's own answer. */
|
|
27
|
+
export declare const RIGHTS_CHECK = "identity.rights";
|
|
28
|
+
/** The part a route acts on, from its path parameter (`part: { type, param }`); else undefined. */
|
|
29
|
+
export declare function partOf(def: RouteDef, params: unknown): Subject | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The rights step, after `checkAccess`: a route that acts on a part of an account (`part`) needs
|
|
32
|
+
* the caller to hold the right to its key there. A route without a part needs the right on the
|
|
33
|
+
* selected or credential-bound account when it differs from the member's default. Public and
|
|
34
|
+
* person routes skip this implicit check. Either refusal is `forbidden` with `{ right }`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkRights(ctx: Ctx, key: string, def: RouteDef, part: Subject | undefined): Promise<void>;
|
|
37
|
+
export declare function hasRight(ctx: Ctx, key: string, part: Subject, memberDoorDefault?: true): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* The access check every door's call meets, before its rule (CONNECT.md): the door rules and
|
|
40
|
+
* roles (`checkAccess`), then the right on the part of an account the route acts on, read from its
|
|
41
|
+
* checked input (`checkRights`). `allowOut` as `checkAccess` takes it.
|
|
42
|
+
*/
|
|
43
|
+
/** An intake actor reaches only its own extension's actions (`intakeOf` against the key's module). */
|
|
44
|
+
export declare const outsideIntake: (actor: Actor | null, key: string) => boolean;
|
|
45
|
+
export declare function checkCall(ctx: Ctx, key: string, def: RouteDef, params: unknown, allowOut: readonly string[]): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Operator writes, every write by a machine (through a door, or an added kind not read as people)
|
|
48
|
+
* or an agent, a call a person approved, and named sensitive reads are recorded. Routine machine
|
|
49
|
+
* calls may omit the automatic row on success only; explicit audit entries are unchanged.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isAudited(def: RouteDef, ctx: Pick<Ctx, 'app' | 'actor' | 'approval'>, result?: AuditEntry['result']): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The account the caller acts for: the account bound to an added kind or system flow, or the
|
|
54
|
+
* selected account if the server validated a member's choice. Defaults to the first membership.
|
|
55
|
+
*/
|
|
56
|
+
export declare function callerAccountId(ctx: {
|
|
57
|
+
actor: Actor | null;
|
|
58
|
+
}): string | undefined;
|
|
59
|
+
/** An account named explicitly in a route's path. */
|
|
60
|
+
export declare function pathAccountId(params: unknown): string | undefined;
|
|
61
|
+
/** The door and the credential a call came through, for its audit row: `mcp:<client>`, `api-key:<key>`. */
|
|
62
|
+
export declare function viaOf(actor: Actor | null): string | undefined;
|
|
63
|
+
/** A refused or failed call's audit result. */
|
|
64
|
+
export declare const failedResult: (status: number) => "denied" | "error";
|
|
65
|
+
/** A flow keeps a reference only when the route has one path parameter, a UUID named `id` or ending `Id`. */
|
|
66
|
+
export declare function routeAuditObject(params: unknown, flow: boolean): Pick<AuditEntry, 'objectType' | 'objectId'>;
|
|
67
|
+
/**
|
|
68
|
+
* One audit row for a call to the route with this key (`<package>.<name>`): the object it acts
|
|
69
|
+
* on, the door it came through, and who approved it if it ran with approval.
|
|
70
|
+
*/
|
|
71
|
+
export declare function auditEntry(key: string, ctx: Pick<Ctx, 'actor' | 'approval' | 'flow'>, params: unknown, result: AuditEntry['result'], detail?: Record<string, unknown>): AuditEntry;
|
package/dist/access.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { zId } from '@buffcore/contracts';
|
|
2
|
+
import { actsAsMachine, isAddedKind } from './actor-kinds.js';
|
|
3
|
+
import { AppError } from './errors.js';
|
|
4
|
+
import { systemFlowAccount } from './flow-context.js';
|
|
5
|
+
import { entriesOf } from './registry.js';
|
|
6
|
+
/** Who may call a route, and which calls are audited (IDENTITY_ACCESS.md, CONNECT.md). */
|
|
7
|
+
/**
|
|
8
|
+
* A machine door (an API key, an MCP client) or an agent: it reaches only routes a module offers
|
|
9
|
+
* (`mcp: true`). A person, in the console or the app, never comes through a door.
|
|
10
|
+
*/
|
|
11
|
+
export const throughDoor = (actor) => actor !== null && (actor.via !== undefined || actor.kind === 'client' || actor.kind === 'agent');
|
|
12
|
+
/**
|
|
13
|
+
* Owner may do everything; other operators, and their API keys (`client`), need one of the route's
|
|
14
|
+
* roles. A preview reads, and writes only where a route opts in (`preview: true`); never an admin
|
|
15
|
+
* route. A kind a package adds reaches only routes that name it (their `actors`), and never one
|
|
16
|
+
* with roles. A machine door or an agent reaches only offered
|
|
17
|
+
* routes, and only when the product lets out (`allowOut`, `connect.allowOut`) every sensitive kind
|
|
18
|
+
* the route `carries`. An agent has no roles: its code names its tools. A route that acts on a
|
|
19
|
+
* part of an account then needs the right there (`checkRights`), and every call to an action meets
|
|
20
|
+
* its rule (`doors.ts`).
|
|
21
|
+
*/
|
|
22
|
+
export function checkAccess(def, actor, allowOut = []) {
|
|
23
|
+
checkIntake(def, actor);
|
|
24
|
+
const closedWrite = def.method !== 'GET' && !def.preview;
|
|
25
|
+
if (actor?.preview && (def.roles || closedWrite))
|
|
26
|
+
throw new AppError('forbidden');
|
|
27
|
+
if (throughDoor(actor))
|
|
28
|
+
checkDoor(def, allowOut);
|
|
29
|
+
if (def.access === 'public')
|
|
30
|
+
return;
|
|
31
|
+
if (!actor)
|
|
32
|
+
throw new AppError('unauthenticated');
|
|
33
|
+
if (isAddedKind(actor)) {
|
|
34
|
+
if (def.roles || !def.actors?.includes(actor.kind))
|
|
35
|
+
throw new AppError('forbidden');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!def.roles || actor.kind === 'agent')
|
|
39
|
+
return;
|
|
40
|
+
if (actor.needsTwoFactor)
|
|
41
|
+
throw new AppError('two_factor_required');
|
|
42
|
+
const roles = actor.kind === 'operator' || actor.kind === 'client' ? (actor.roles ?? []) : [];
|
|
43
|
+
if (!roles.includes('owner') && !def.roles.some((r) => roles.includes(r))) {
|
|
44
|
+
throw new AppError('forbidden', { needs: def.roles });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Intake credentials remain confined even through runAction, approval replay and public reads. */
|
|
48
|
+
function checkIntake(def, actor) {
|
|
49
|
+
if ((actor?.intakeOf !== undefined && !def.intake) ||
|
|
50
|
+
(def.intake && isAddedKind(actor) && actor?.intakeOf === undefined)) {
|
|
51
|
+
throw new AppError('forbidden');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The door rules: offered to machines, and carrying nothing the product keeps in. */
|
|
55
|
+
function checkDoor(def, allowOut) {
|
|
56
|
+
if (!def.mcp)
|
|
57
|
+
throw new AppError('forbidden', { offered: false });
|
|
58
|
+
const kept = (def.carries ?? []).filter((kind) => !allowOut.includes(kind));
|
|
59
|
+
if (kept.length > 0)
|
|
60
|
+
throw new AppError('forbidden', { carries: kept });
|
|
61
|
+
}
|
|
62
|
+
/** The hook point the rights step is read from: identity's own answer. */
|
|
63
|
+
export const RIGHTS_CHECK = 'identity.rights';
|
|
64
|
+
/** The part a route acts on, from its path parameter (`part: { type, param }`); else undefined. */
|
|
65
|
+
export function partOf(def, params) {
|
|
66
|
+
if (!def.part)
|
|
67
|
+
return undefined;
|
|
68
|
+
const id = params?.[def.part.param];
|
|
69
|
+
return typeof id === 'string' && id !== '' ? { type: def.part.type, id } : undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The rights step, after `checkAccess`: a route that acts on a part of an account (`part`) needs
|
|
73
|
+
* the caller to hold the right to its key there. A route without a part needs the right on the
|
|
74
|
+
* selected or credential-bound account when it differs from the member's default. Public and
|
|
75
|
+
* person routes skip this implicit check. Either refusal is `forbidden` with `{ right }`.
|
|
76
|
+
*/
|
|
77
|
+
export async function checkRights(ctx, key, def, part) {
|
|
78
|
+
let named = part;
|
|
79
|
+
let memberDoorDefault;
|
|
80
|
+
if (ctx.actor?.kind === 'system' && ctx.actor.accountId !== undefined) {
|
|
81
|
+
const accountId = systemFlowAccount(ctx, key);
|
|
82
|
+
if (!accountId || !def.flow || def.person || def.roles || def.intake) {
|
|
83
|
+
throw new AppError('forbidden', { right: key });
|
|
84
|
+
}
|
|
85
|
+
if (!def.part)
|
|
86
|
+
named = { type: 'account', id: accountId };
|
|
87
|
+
}
|
|
88
|
+
else if (!def.part) {
|
|
89
|
+
if (def.access === 'public' || def.person)
|
|
90
|
+
return;
|
|
91
|
+
const actor = ctx.actor;
|
|
92
|
+
const memberDoor = actor?.kind === 'member' && actor.via !== undefined;
|
|
93
|
+
const accountId = actor?.actingAccountId ?? (memberDoor ? actor.accountIds?.[0] : undefined);
|
|
94
|
+
if (!accountId || (!memberDoor && accountId === actor?.accountIds?.[0]))
|
|
95
|
+
return;
|
|
96
|
+
named = { type: 'account', id: accountId };
|
|
97
|
+
memberDoorDefault = memberDoor ? true : undefined;
|
|
98
|
+
}
|
|
99
|
+
if (def.part && part?.type !== def.part.type)
|
|
100
|
+
named = undefined;
|
|
101
|
+
if (!named || !(await hasRight(ctx, key, named, memberDoorDefault))) {
|
|
102
|
+
throw new AppError('forbidden', { right: key });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export async function hasRight(ctx, key, part, memberDoorDefault) {
|
|
106
|
+
const held = entriesOf(ctx.app, RIGHTS_CHECK).get('identity');
|
|
107
|
+
return held ? held(ctx, key, part, memberDoorDefault) : false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The access check every door's call meets, before its rule (CONNECT.md): the door rules and
|
|
111
|
+
* roles (`checkAccess`), then the right on the part of an account the route acts on, read from its
|
|
112
|
+
* checked input (`checkRights`). `allowOut` as `checkAccess` takes it.
|
|
113
|
+
*/
|
|
114
|
+
/** An intake actor reaches only its own extension's actions (`intakeOf` against the key's module). */
|
|
115
|
+
export const outsideIntake = (actor, key) => actor?.intakeOf !== undefined && key.split('.')[0] !== actor.intakeOf;
|
|
116
|
+
export async function checkCall(ctx, key, def, params, allowOut) {
|
|
117
|
+
if (outsideIntake(ctx.actor, key))
|
|
118
|
+
throw new AppError('forbidden');
|
|
119
|
+
checkAccess(def, ctx.actor, allowOut);
|
|
120
|
+
await checkRights(ctx, key, def, partOf(def, params));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Operator writes, every write by a machine (through a door, or an added kind not read as people)
|
|
124
|
+
* or an agent, a call a person approved, and named sensitive reads are recorded. Routine machine
|
|
125
|
+
* calls may omit the automatic row on success only; explicit audit entries are unchanged.
|
|
126
|
+
*/
|
|
127
|
+
export function isAudited(def, ctx, result = 'ok') {
|
|
128
|
+
if (def.audit === 'none-for-machines' && actsAsMachine(ctx.app, ctx.actor)) {
|
|
129
|
+
return result !== 'ok';
|
|
130
|
+
}
|
|
131
|
+
return (def.audit === 'sensitive-read' ||
|
|
132
|
+
ctx.approval !== undefined ||
|
|
133
|
+
(def.method !== 'GET' && (Boolean(def.roles) || actsAsMachine(ctx.app, ctx.actor))));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The account the caller acts for: the account bound to an added kind or system flow, or the
|
|
137
|
+
* selected account if the server validated a member's choice. Defaults to the first membership.
|
|
138
|
+
*/
|
|
139
|
+
export function callerAccountId(ctx) {
|
|
140
|
+
const actor = ctx.actor;
|
|
141
|
+
if (actor?.kind === 'system' && actor.accountId !== undefined)
|
|
142
|
+
return actor.accountId;
|
|
143
|
+
if (isAddedKind(actor))
|
|
144
|
+
return actor?.accountId;
|
|
145
|
+
return actor?.actingAccountId ?? actor?.accountIds?.[0];
|
|
146
|
+
}
|
|
147
|
+
/** An account named explicitly in a route's path. */
|
|
148
|
+
export function pathAccountId(params) {
|
|
149
|
+
const id = params?.accountId;
|
|
150
|
+
return typeof id === 'string' && zId.safeParse(id).success ? id : undefined;
|
|
151
|
+
}
|
|
152
|
+
/** The door and the credential a call came through, for its audit row: `mcp:<client>`, `api-key:<key>`. */
|
|
153
|
+
export function viaOf(actor) {
|
|
154
|
+
if (!actor?.via)
|
|
155
|
+
return undefined;
|
|
156
|
+
return actor.credentialId ? `${actor.via}:${actor.credentialId}` : actor.via;
|
|
157
|
+
}
|
|
158
|
+
/** A refused or failed call's audit result. */
|
|
159
|
+
export const failedResult = (status) => status === 401 || status === 403 ? 'denied' : 'error';
|
|
160
|
+
/** A flow keeps a reference only when the route has one path parameter, a UUID named `id` or ending `Id`. */
|
|
161
|
+
export function routeAuditObject(params, flow) {
|
|
162
|
+
const entries = Object.entries((params ?? {}));
|
|
163
|
+
const [name, value] = entries[0] ?? [];
|
|
164
|
+
if (!name)
|
|
165
|
+
return {};
|
|
166
|
+
if (flow && (entries.length > 1 || !/^(id|.+Id)$/.test(name) || !zId.safeParse(value).success)) {
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
return { objectType: name.replace(/Id$/, ''), objectId: String(value) };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* One audit row for a call to the route with this key (`<package>.<name>`): the object it acts
|
|
173
|
+
* on, the door it came through, and who approved it if it ran with approval.
|
|
174
|
+
*/
|
|
175
|
+
export function auditEntry(key, ctx, params, result, detail) {
|
|
176
|
+
const via = ctx.flow ? `flow:${ctx.flow.flowId}` : viaOf(ctx.actor);
|
|
177
|
+
const approval = ctx.approval && {
|
|
178
|
+
approval: ctx.approval.itemId,
|
|
179
|
+
approvedBy: ctx.approval.approvedBy,
|
|
180
|
+
};
|
|
181
|
+
const accountId = ctx.flow ? undefined : (pathAccountId(params) ?? ctx.actor?.actingAccountId);
|
|
182
|
+
const said = approval || detail || accountId
|
|
183
|
+
? { ...(accountId ? { accountId } : {}), ...approval, ...detail }
|
|
184
|
+
: undefined;
|
|
185
|
+
return {
|
|
186
|
+
action: key,
|
|
187
|
+
...routeAuditObject(params, ctx.flow !== undefined),
|
|
188
|
+
result,
|
|
189
|
+
...(via ? { via } : {}),
|
|
190
|
+
...(said ? { detail: said } : {}),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Actor, Ctx } from './module.ts';
|
|
2
|
+
export declare const namesPathAccount: (params: unknown) => boolean;
|
|
3
|
+
/** Resolve a member's choice from their authenticated memberships, without a lookup. */
|
|
4
|
+
export declare function selectAccount(actor: Actor | null, header: string | string[] | undefined): Actor | null;
|
|
5
|
+
/** A person route receives the caller and their memberships, without an acting account. */
|
|
6
|
+
export declare function withoutActingAccount(ctx: Ctx): Ctx;
|
|
7
|
+
/** A member's writes are replayed by account, unless the URL already names the account. */
|
|
8
|
+
export declare function replayCaller(actor: Actor | null, ip: string, params: unknown): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { zId } from '@buffcore/contracts';
|
|
2
|
+
import { callerAccountId, throughDoor } from './access.js';
|
|
3
|
+
import { isAddedKind } from './actor-kinds.js';
|
|
4
|
+
import { forbidden } from './errors.js';
|
|
5
|
+
export const namesPathAccount = (params) => Object.hasOwn(params ?? {}, 'accountId');
|
|
6
|
+
/** Resolve a member's choice from their authenticated memberships, without a lookup. */
|
|
7
|
+
export function selectAccount(actor, header) {
|
|
8
|
+
if (header === undefined || isAddedKind(actor) || throughDoor(actor))
|
|
9
|
+
return actor;
|
|
10
|
+
if (actor?.kind !== 'member' || actor.preview || typeof header !== 'string')
|
|
11
|
+
throw forbidden();
|
|
12
|
+
const accountId = header.toLowerCase();
|
|
13
|
+
if (!zId.safeParse(accountId).success || !actor.accountIds?.includes(accountId))
|
|
14
|
+
throw forbidden();
|
|
15
|
+
// Copy the actor for this request and preserve private authentication metadata.
|
|
16
|
+
return Object.defineProperties({}, {
|
|
17
|
+
...Object.getOwnPropertyDescriptors(actor),
|
|
18
|
+
actingAccountId: { value: accountId, enumerable: true },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** A person route receives the caller and their memberships, without an acting account. */
|
|
22
|
+
export function withoutActingAccount(ctx) {
|
|
23
|
+
if (ctx.actor?.actingAccountId === undefined)
|
|
24
|
+
return ctx;
|
|
25
|
+
const { actingAccountId: _selection, ...claims } = Object.getOwnPropertyDescriptors(ctx.actor);
|
|
26
|
+
return { ...ctx, actor: Object.defineProperties({}, claims) };
|
|
27
|
+
}
|
|
28
|
+
/** A member's writes are replayed by account, unless the URL already names the account. */
|
|
29
|
+
export function replayCaller(actor, ip, params) {
|
|
30
|
+
const caller = actor?.id ?? ip;
|
|
31
|
+
if (actor?.kind !== 'member' || namesPathAccount(params))
|
|
32
|
+
return caller;
|
|
33
|
+
const accountId = callerAccountId({ actor });
|
|
34
|
+
return accountId ? `${caller}:${accountId}` : caller;
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RouteDef, RouteRequest } from '@buffcore/contracts';
|
|
2
|
+
/** What a caller sends to `runAction`: the route's parts, checked against its schemas. */
|
|
3
|
+
export interface ActionInput {
|
|
4
|
+
params?: unknown;
|
|
5
|
+
query?: unknown;
|
|
6
|
+
body?: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** The input as the route's schemas read it, or `validation_failed` naming each problem. */
|
|
9
|
+
export declare function parseInput(route: RouteDef, input: ActionInput, locale: string): RouteRequest<RouteDef>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { validationErrors } from '@buffcore/i18n';
|
|
2
|
+
import { AppError } from './errors.js';
|
|
3
|
+
/** The input as the route's schemas read it, or `validation_failed` naming each problem. */
|
|
4
|
+
export function parseInput(route, input, locale) {
|
|
5
|
+
const issues = [];
|
|
6
|
+
const error = validationErrors(locale);
|
|
7
|
+
const read = (part, fallback) => {
|
|
8
|
+
const schema = route[part];
|
|
9
|
+
if (!schema)
|
|
10
|
+
return fallback;
|
|
11
|
+
const parsed = schema.safeParse(input[part] ?? fallback, { error });
|
|
12
|
+
if (parsed.success)
|
|
13
|
+
return parsed.data;
|
|
14
|
+
for (const issue of parsed.error.issues) {
|
|
15
|
+
issues.push({ path: [part, ...issue.path].join('/'), message: issue.message });
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
const request = {
|
|
20
|
+
params: read('params', {}),
|
|
21
|
+
query: read('query', {}),
|
|
22
|
+
body: read('body', undefined),
|
|
23
|
+
};
|
|
24
|
+
if (issues.length > 0)
|
|
25
|
+
throw new AppError('validation_failed', { issues });
|
|
26
|
+
return request;
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ActionMark, RouteDef, RouteRequest } from '@buffcore/contracts';
|
|
2
|
+
import type { T } from '@buffcore/i18n';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import type { Actor, Ctx } from './module.ts';
|
|
5
|
+
/** A call to an action that waits for a person in the inbox: HTTP 202. */
|
|
6
|
+
export declare const Waiting: z.ZodObject<{
|
|
7
|
+
waiting: z.ZodObject<{
|
|
8
|
+
itemId: z.ZodString;
|
|
9
|
+
displayId: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export type Waiting = z.infer<typeof Waiting>;
|
|
13
|
+
/** Whether an answer is a call waiting for a person (`{ waiting }` alone). */
|
|
14
|
+
export declare const isWaiting: (value: unknown) => value is Waiting;
|
|
15
|
+
/** A call to an action, as the rule step sees it: after access, before the handler. */
|
|
16
|
+
export interface ActionCall {
|
|
17
|
+
/** `<package>.<name>`: the action's key. */
|
|
18
|
+
action: string;
|
|
19
|
+
mark: ActionMark;
|
|
20
|
+
/** What the caller sent, as the route checked it: only the parts it declares. */
|
|
21
|
+
input: {
|
|
22
|
+
params: unknown;
|
|
23
|
+
query: unknown;
|
|
24
|
+
body: unknown;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The rule step: null runs the call; `{ waiting }` holds it for a person (an approval in the
|
|
29
|
+
* inbox); a refusal throws `rule_refused`. The `rules` package answers it, as `rules.step`.
|
|
30
|
+
*/
|
|
31
|
+
export type RuleStep = (ctx: Ctx, call: ActionCall) => Promise<Waiting | null>;
|
|
32
|
+
/** The hook point the rule step is read from: the `rules` package's own answer, and no other. */
|
|
33
|
+
export declare const RULE_STEP = "rules.step";
|
|
34
|
+
/**
|
|
35
|
+
* A call a person approved (`ctx.approval`), running as who asked (`ctx.actor`, as they asked):
|
|
36
|
+
* the rule step lets it through, and its audit row names the approver beside them (BC-D23).
|
|
37
|
+
*/
|
|
38
|
+
export interface ApprovalRun {
|
|
39
|
+
/** The approval's inbox item. */
|
|
40
|
+
itemId: string;
|
|
41
|
+
/** The action approved: only this action runs past the rule step. */
|
|
42
|
+
action: string;
|
|
43
|
+
/** Who approved it, by ID (an operator, in the console); its audit row's time is when. */
|
|
44
|
+
approvedBy: Actor['id'];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What running an action changes, one line each, and how to undo it (null when it can't be), in
|
|
48
|
+
* the reader's language (`ctx.t`): a waiting call shows them (AUTOMATION.md).
|
|
49
|
+
*/
|
|
50
|
+
export interface ActionEffects {
|
|
51
|
+
effects: readonly string[];
|
|
52
|
+
undo: string | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An action's effects for one input, read when a person opens a call waiting for them. An action
|
|
56
|
+
* says what it changes where it is bound: `handle(lendBook, handler, { describe })`.
|
|
57
|
+
*/
|
|
58
|
+
export type Describe<R extends RouteDef> = (req: RouteRequest<R>, ctx: Ctx) => Promise<ActionEffects>;
|
|
59
|
+
/** The action in the reader's language, from its package's `<package>.actions.<name>`; else its key. */
|
|
60
|
+
export declare function actionTitle(t: T, key: string): string;
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// What the pipeline asks about a call to an action (the kernel contract, §5 and §6): the rule
|
|
3
|
+
// step, which the `rules` package answers, and an action's effects, which its draft shows.
|
|
4
|
+
/** A call to an action that waits for a person in the inbox: HTTP 202. */
|
|
5
|
+
export const Waiting = z.object({
|
|
6
|
+
waiting: z.object({ itemId: z.string(), displayId: z.string() }),
|
|
7
|
+
});
|
|
8
|
+
/** Whether an answer is a call waiting for a person (`{ waiting }` alone). */
|
|
9
|
+
export const isWaiting = (value) => typeof value === 'object' &&
|
|
10
|
+
value !== null &&
|
|
11
|
+
'waiting' in value &&
|
|
12
|
+
Object.keys(value).length === 1;
|
|
13
|
+
/** The hook point the rule step is read from: the `rules` package's own answer, and no other. */
|
|
14
|
+
export const RULE_STEP = 'rules.step';
|
|
15
|
+
/** The action in the reader's language, from its package's `<package>.actions.<name>`; else its key. */
|
|
16
|
+
export function actionTitle(t, key) {
|
|
17
|
+
const message = key.replace('.', '.actions.');
|
|
18
|
+
const title = t(message);
|
|
19
|
+
return title === message ? key : title;
|
|
20
|
+
}
|