@buffcore/config 0.0.0-stage → 0.8.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +8 -2
- package/dist/agents.d.ts +25 -0
- package/dist/agents.js +12 -0
- package/dist/env.d.ts +73 -0
- package/dist/env.js +126 -0
- package/dist/extension-grants.d.ts +18 -0
- package/dist/extension-grants.js +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/processes.d.ts +45 -0
- package/dist/processes.js +91 -0
- package/dist/product.d.ts +218 -0
- package/dist/product.js +182 -0
- package/dist/scenes.d.ts +109 -0
- package/dist/scenes.js +56 -0
- package/package.json +36 -3
- package/tsconfig.preset.json +20 -0
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/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript, Biome and Vitest presets, the environment schema helper and `defineProduct` for BuffCore products.
|
|
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/agents.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `agents` in `buffcore.config.ts`: the limits for coding agents, as one list.
|
|
3
|
+
* `ape agents write` turns it into the agent's container, each agent's own settings (Claude Code,
|
|
4
|
+
* Codex, OpenCode) and the code owners; `ape agents check` fails when those files drift from it.
|
|
5
|
+
*
|
|
6
|
+
* Paths are gitignore patterns from the repository's root: `.env` matches at any depth, a pattern
|
|
7
|
+
* with a `/` (`/package.json`, `apps/api/.env`) only there, `dir/` everything under it, `*` within
|
|
8
|
+
* a name and `**` across folders.
|
|
9
|
+
*/
|
|
10
|
+
export interface AgentLimits {
|
|
11
|
+
/**
|
|
12
|
+
* What an agent may not read: secrets and the deploy approval key. `!pattern` keeps one
|
|
13
|
+
* readable again (`!.env.example` after `.env.*`).
|
|
14
|
+
*/
|
|
15
|
+
hidden: readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* What a person approves at merge: the checks that hold AGENTS.md's rules. The list itself
|
|
18
|
+
* (`buffcore.config.ts`) and the files ape writes from it always are.
|
|
19
|
+
*/
|
|
20
|
+
protected: readonly string[];
|
|
21
|
+
/** Who approves: GitHub handles (`@name`, `@org/team`) or emails, for the code owners file. */
|
|
22
|
+
owners: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
/** What is wrong with the list, one line each. */
|
|
25
|
+
export declare function agentProblems(agents: AgentLimits): string[];
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const isPatterns = (value) => Array.isArray(value) && value.every((v) => typeof v === 'string' && v.trim() === v && v !== '');
|
|
2
|
+
/** What is wrong with the list, one line each. */
|
|
3
|
+
export function agentProblems(agents) {
|
|
4
|
+
const problems = [];
|
|
5
|
+
for (const key of ['hidden', 'protected', 'owners']) {
|
|
6
|
+
if (!isPatterns(agents[key]))
|
|
7
|
+
problems.push(`agents.${key} is a list of non-empty names`);
|
|
8
|
+
}
|
|
9
|
+
if (isPatterns(agents.protected) && agents.protected.some((p) => p.startsWith('!')))
|
|
10
|
+
problems.push('agents.protected takes no exceptions (!): the code owners file has none');
|
|
11
|
+
return problems;
|
|
12
|
+
}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Thrown when environment variables are missing or invalid. Entry points print it and exit. */
|
|
3
|
+
export declare class EnvError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validate environment variables against a Zod object schema.
|
|
8
|
+
* A bad value stops the process with one clear line per problem.
|
|
9
|
+
*/
|
|
10
|
+
export declare function defineEnv<T extends z.ZodObject>(schema: T, source?: Record<string, string | undefined>): z.infer<T>;
|
|
11
|
+
export declare const isExampleSecret: (value: string) => boolean;
|
|
12
|
+
/** `APE_ENV`'s values. */
|
|
13
|
+
export declare const ENVIRONMENTS: readonly ['development', 'test', 'staging', 'production'];
|
|
14
|
+
/**
|
|
15
|
+
* Whether an environment runs production's setup: secure cookies, real email and push services,
|
|
16
|
+
* no pseudo-languages, no development pages. Staging is production's setup on another server,
|
|
17
|
+
* where sample data (`ape seed`) and providers' test keys are allowed.
|
|
18
|
+
*/
|
|
19
|
+
export declare const productionSetup: (environment: string) => boolean;
|
|
20
|
+
/** The variables every BuffCore app reads. Products add their own (e.g. ACME_*). */
|
|
21
|
+
export declare const coreEnvSchema: z.ZodObject<{
|
|
22
|
+
APE_ENV: z.ZodDefault<z.ZodEnum<{
|
|
23
|
+
development: "development";
|
|
24
|
+
production: "production";
|
|
25
|
+
staging: "staging";
|
|
26
|
+
test: "test";
|
|
27
|
+
}>>;
|
|
28
|
+
APE_RELEASE: z.ZodDefault<z.ZodString>;
|
|
29
|
+
APE_LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
30
|
+
debug: "debug";
|
|
31
|
+
error: "error";
|
|
32
|
+
fatal: "fatal";
|
|
33
|
+
info: "info";
|
|
34
|
+
trace: "trace";
|
|
35
|
+
warn: "warn";
|
|
36
|
+
}>>;
|
|
37
|
+
DATABASE_URL: z.ZodURL;
|
|
38
|
+
REDIS_URL: z.ZodURL;
|
|
39
|
+
APE_REDIS_PREFIX: z.ZodOptional<z.ZodString>;
|
|
40
|
+
APE_API_PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
41
|
+
APE_API_URL: z.ZodDefault<z.ZodURL>;
|
|
42
|
+
APE_WORKER_CONCURRENCY: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
43
|
+
APE_ADMIN_URL: z.ZodDefault<z.ZodURL>;
|
|
44
|
+
APE_APP_URL: z.ZodDefault<z.ZodURL>;
|
|
45
|
+
APE_HOST: z.ZodDefault<z.ZodString>;
|
|
46
|
+
APE_AUTH_SECRET: z.ZodString;
|
|
47
|
+
APE_ENCRYPTION_KEY: z.ZodString;
|
|
48
|
+
APE_S3_ENDPOINT: z.ZodOptional<z.ZodURL>;
|
|
49
|
+
APE_S3_REGION: z.ZodDefault<z.ZodString>;
|
|
50
|
+
APE_S3_BUCKET: z.ZodDefault<z.ZodString>;
|
|
51
|
+
APE_S3_ACCESS_KEY: z.ZodOptional<z.ZodString>;
|
|
52
|
+
APE_S3_SECRET_KEY: z.ZodOptional<z.ZodString>;
|
|
53
|
+
APE_AI_MODE: z.ZodDefault<z.ZodEnum<{
|
|
54
|
+
fixture: "fixture";
|
|
55
|
+
live: "live";
|
|
56
|
+
record: "record";
|
|
57
|
+
}>>;
|
|
58
|
+
APE_ALLOW_LIVE_AI: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
0: "0";
|
|
60
|
+
1: "1";
|
|
61
|
+
false: "false";
|
|
62
|
+
true: "true";
|
|
63
|
+
}>>, z.ZodTransform<boolean, "0" | "1" | "false" | "true" | undefined>>;
|
|
64
|
+
ANTHROPIC_API_KEY: z.ZodOptional<z.ZodString>;
|
|
65
|
+
OPENAI_API_KEY: z.ZodOptional<z.ZodString>;
|
|
66
|
+
GOOGLE_VERTEX_API_KEY: z.ZodOptional<z.ZodString>;
|
|
67
|
+
GOOGLE_VERTEX_PROJECT: z.ZodOptional<z.ZodString>;
|
|
68
|
+
GOOGLE_VERTEX_LOCATION: z.ZodDefault<z.ZodString>;
|
|
69
|
+
APE_BACKUP_KEY: z.ZodOptional<z.ZodString>;
|
|
70
|
+
TURNSTILE_SITE_KEY: z.ZodOptional<z.ZodString>;
|
|
71
|
+
TURNSTILE_SECRET_KEY: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
export type CoreEnv = z.infer<typeof coreEnvSchema>;
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Thrown when environment variables are missing or invalid. Entry points print it and exit. */
|
|
3
|
+
export class EnvError extends Error {
|
|
4
|
+
name = 'EnvError';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validate environment variables against a Zod object schema.
|
|
8
|
+
* A bad value stops the process with one clear line per problem.
|
|
9
|
+
*/
|
|
10
|
+
export function defineEnv(schema, source = process.env) {
|
|
11
|
+
const result = schema.safeParse(source);
|
|
12
|
+
if (result.success)
|
|
13
|
+
return result.data;
|
|
14
|
+
const lines = result.error.issues.map((issue) => ` ${issue.path.join('.')}: ${issue.message}`);
|
|
15
|
+
throw new EnvError(`Invalid environment variables:\n${lines.join('\n')}`);
|
|
16
|
+
}
|
|
17
|
+
const flag = z
|
|
18
|
+
.enum(['0', '1', 'true', 'false'])
|
|
19
|
+
.optional()
|
|
20
|
+
.transform((v) => v === '1' || v === 'true');
|
|
21
|
+
/**
|
|
22
|
+
* What BuffCore's own examples hold (`.env.example`, the template's CI, the test kit): fine on a
|
|
23
|
+
* laptop, never a production secret. A key is also read as base64, which is how keys are written.
|
|
24
|
+
*/
|
|
25
|
+
const EXAMPLE = /development-only|ci-only|test-only|change-me|-dev-secret$/;
|
|
26
|
+
export const isExampleSecret = (value) => EXAMPLE.test(value) || EXAMPLE.test(Buffer.from(value, 'base64').toString('latin1'));
|
|
27
|
+
/** The secrets the production check reads; the database's password is in `DATABASE_URL`. */
|
|
28
|
+
const SECRETS = ['APE_AUTH_SECRET', 'APE_ENCRYPTION_KEY', 'APE_BACKUP_KEY', 'APE_S3_SECRET_KEY'];
|
|
29
|
+
/** `APE_ENV`'s values. */
|
|
30
|
+
export const ENVIRONMENTS = ['development', 'test', 'staging', 'production'];
|
|
31
|
+
/**
|
|
32
|
+
* Whether an environment runs production's setup: secure cookies, real email and push services,
|
|
33
|
+
* no pseudo-languages, no development pages. Staging is production's setup on another server,
|
|
34
|
+
* where sample data (`ape seed`) and providers' test keys are allowed.
|
|
35
|
+
*/
|
|
36
|
+
export const productionSetup = (environment) => environment === 'production' || environment === 'staging';
|
|
37
|
+
/** Sign-up's bot check (Cloudflare Turnstile): production refuses to start without its keys. */
|
|
38
|
+
const BOT_CHECK_KEYS = ['TURNSTILE_SITE_KEY', 'TURNSTILE_SECRET_KEY'];
|
|
39
|
+
/**
|
|
40
|
+
* The production check, on staging too (a server others reach): no secret from an example, and
|
|
41
|
+
* no development database password (`<name>-dev`, as `ape create` writes it). Production alone
|
|
42
|
+
* also needs sign-up's bot check, since sign-up is public (identity, E2); staging may go without.
|
|
43
|
+
*/
|
|
44
|
+
function productionCheck(env, ctx) {
|
|
45
|
+
if (!productionSetup(String(env.APE_ENV)))
|
|
46
|
+
return;
|
|
47
|
+
const example = `is an example value: ${env.APE_ENV} needs its own (ape server setup makes one)`;
|
|
48
|
+
for (const key of SECRETS) {
|
|
49
|
+
const value = env[key];
|
|
50
|
+
if (typeof value === 'string' && isExampleSecret(value))
|
|
51
|
+
ctx.addIssue({ code: 'custom', path: [key], message: example });
|
|
52
|
+
}
|
|
53
|
+
if (env.APE_ENV === 'production') {
|
|
54
|
+
for (const key of BOT_CHECK_KEYS.filter((k) => !env[k]))
|
|
55
|
+
ctx.addIssue({
|
|
56
|
+
code: 'custom',
|
|
57
|
+
path: [key],
|
|
58
|
+
message: 'is needed in production: sign-up is public and asks for its bot check (Cloudflare Turnstile)',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const url = String(env.DATABASE_URL);
|
|
62
|
+
const password = URL.canParse(url) ? decodeURIComponent(new URL(url).password) : '';
|
|
63
|
+
if (password.endsWith('-dev') || isExampleSecret(password))
|
|
64
|
+
ctx.addIssue({
|
|
65
|
+
code: 'custom',
|
|
66
|
+
path: ['DATABASE_URL'],
|
|
67
|
+
message: `has a password that ${example}`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** The variables every BuffCore app reads. Products add their own (e.g. ACME_*). */
|
|
71
|
+
export const coreEnvSchema = z
|
|
72
|
+
.object({
|
|
73
|
+
APE_ENV: z.enum(ENVIRONMENTS).default('development'),
|
|
74
|
+
/** The release this process runs: a git tag or commit, shown on errors. */
|
|
75
|
+
APE_RELEASE: z.string().default('dev'),
|
|
76
|
+
APE_LOG_LEVEL: z.enum(['fatal', 'error', 'warn', 'info', 'debug', 'trace']).default('info'),
|
|
77
|
+
DATABASE_URL: z.url(),
|
|
78
|
+
REDIS_URL: z.url(),
|
|
79
|
+
/**
|
|
80
|
+
* What every Redis key and channel of this app starts with, for a Redis shared by several
|
|
81
|
+
* apps, each held to its own by an ACL (`~<prefix>* &<prefix>*`). Unset: `defaultKeyPrefix`.
|
|
82
|
+
*/
|
|
83
|
+
APE_REDIS_PREFIX: z
|
|
84
|
+
.string()
|
|
85
|
+
.regex(/^[A-Za-z0-9][A-Za-z0-9_:-]{0,62}:$/, 'must be letters, digits, _, - or :, start with a letter or digit, end with : and be at most 64 characters (for example acme:)')
|
|
86
|
+
.optional(),
|
|
87
|
+
APE_API_PORT: z.coerce.number().int().default(4300),
|
|
88
|
+
APE_API_URL: z.url().default('http://localhost:4300'),
|
|
89
|
+
/** How many jobs the worker runs at once. */
|
|
90
|
+
APE_WORKER_CONCURRENCY: z.coerce.number().int().min(1).default(4),
|
|
91
|
+
APE_ADMIN_URL: z.url().default('http://localhost:4301'),
|
|
92
|
+
APE_APP_URL: z.url().default('http://localhost:4302'),
|
|
93
|
+
/** Where the API and the product's processes listen: this computer only, or `0.0.0.0` in a container. */
|
|
94
|
+
APE_HOST: z.string().default('127.0.0.1'),
|
|
95
|
+
/** Signs sessions and tokens. At least 32 characters. */
|
|
96
|
+
APE_AUTH_SECRET: z.string().min(32),
|
|
97
|
+
/** Encrypts secret fields at rest: 32 bytes, base64. */
|
|
98
|
+
APE_ENCRYPTION_KEY: z
|
|
99
|
+
.string()
|
|
100
|
+
.refine((v) => Buffer.from(v, 'base64').length === 32, 'must be 32 bytes, base64-encoded'),
|
|
101
|
+
APE_S3_ENDPOINT: z.url().optional(),
|
|
102
|
+
APE_S3_REGION: z.string().default('us-east-1'),
|
|
103
|
+
APE_S3_BUCKET: z.string().default('buffcore'),
|
|
104
|
+
APE_S3_ACCESS_KEY: z.string().optional(),
|
|
105
|
+
APE_S3_SECRET_KEY: z.string().optional(),
|
|
106
|
+
APE_AI_MODE: z.enum(['fixture', 'record', 'live']).default('fixture'),
|
|
107
|
+
APE_ALLOW_LIVE_AI: flag,
|
|
108
|
+
ANTHROPIC_API_KEY: z.string().optional(),
|
|
109
|
+
OPENAI_API_KEY: z.string().optional(),
|
|
110
|
+
/**
|
|
111
|
+
* Google Vertex AI: an express-mode API key, or a project and location with Google's
|
|
112
|
+
* Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS` or `gcloud auth`).
|
|
113
|
+
*/
|
|
114
|
+
GOOGLE_VERTEX_API_KEY: z.string().optional(),
|
|
115
|
+
GOOGLE_VERTEX_PROJECT: z.string().optional(),
|
|
116
|
+
GOOGLE_VERTEX_LOCATION: z.string().default('us-central1'),
|
|
117
|
+
/** Encrypts backups (`ape backup`): 32 random bytes, base64; checked when a backup runs. */
|
|
118
|
+
APE_BACKUP_KEY: z.string().optional(),
|
|
119
|
+
/**
|
|
120
|
+
* Sign-up's bot check (Cloudflare Turnstile): the widget's site key and the server's secret
|
|
121
|
+
* key. Development uses Cloudflare's test keys when they are unset.
|
|
122
|
+
*/
|
|
123
|
+
TURNSTILE_SITE_KEY: z.string().optional(),
|
|
124
|
+
TURNSTILE_SECRET_KEY: z.string().optional(),
|
|
125
|
+
})
|
|
126
|
+
.superRefine(productionCheck);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What a product lets one extension do. A grant wider than what it declares is fine. */
|
|
2
|
+
export interface ExtensionGrant {
|
|
3
|
+
/** Its package, e.g. `@buffcore/feedback`. */
|
|
4
|
+
package: string;
|
|
5
|
+
/** The sensitive kinds it may hold or receive (e.g. `content`). */
|
|
6
|
+
reads?: readonly string[];
|
|
7
|
+
/** The hosts it may call, through `outbound(ctx)`. */
|
|
8
|
+
hosts?: readonly string[];
|
|
9
|
+
/** The hosts granted to receive people's data (its manifest's `places`). */
|
|
10
|
+
places?: readonly string[];
|
|
11
|
+
/** The account upload kinds it may store through `storeUpload(ctx, input)`. */
|
|
12
|
+
uploads?: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/** A kind's name is a path segment in `POST /v1/uploads/<kind>`. */
|
|
15
|
+
export declare const isUploadKind: (value: unknown) => value is string;
|
|
16
|
+
/** Upload kinds in an extension's declaration or grant, either optional or listed. */
|
|
17
|
+
export declare const uploadKindsFit: (value: unknown) => boolean;
|
|
18
|
+
export declare function grantProblems(grants: Readonly<Record<string, ExtensionGrant>>): string[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A kind's name is a path segment in `POST /v1/uploads/<kind>`. */
|
|
2
|
+
export const isUploadKind = (value) => typeof value === 'string' && /^[a-z][a-z0-9_-]{0,39}$/.test(value);
|
|
3
|
+
/** Upload kinds in an extension's declaration or grant, either optional or listed. */
|
|
4
|
+
export const uploadKindsFit = (value) => value === undefined || (Array.isArray(value) && Array.from(value).every(isUploadKind));
|
|
5
|
+
const isStrings = (value) => value === undefined || (Array.isArray(value) && value.every((v) => typeof v === 'string'));
|
|
6
|
+
export function grantProblems(grants) {
|
|
7
|
+
return Object.entries(grants).flatMap(([key, grant]) => {
|
|
8
|
+
const problems = [];
|
|
9
|
+
if (typeof grant?.package !== 'string' || !grant.package)
|
|
10
|
+
problems.push(`extensions.${key} needs its package, e.g. package: '@acme/${key}'`);
|
|
11
|
+
if (!isStrings(grant?.reads) || !isStrings(grant?.hosts))
|
|
12
|
+
problems.push(`extensions.${key}: reads and hosts are lists of names`);
|
|
13
|
+
if (!isStrings(grant?.places))
|
|
14
|
+
problems.push(`extensions.${key}: places is a list of hosts`);
|
|
15
|
+
if (!uploadKindsFit(grant?.uploads))
|
|
16
|
+
problems.push(`extensions.${key}: uploads is a list of upload kind names`);
|
|
17
|
+
return problems;
|
|
18
|
+
});
|
|
19
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { AgentLimits } from './agents.ts';
|
|
2
|
+
export { type CoreEnv, coreEnvSchema, defineEnv, ENVIRONMENTS, EnvError, productionSetup, } from './env.ts';
|
|
3
|
+
export { isUploadKind, uploadKindsFit } from './extension-grants.ts';
|
|
4
|
+
export { type ContainerProcess, DEFAULT_PROCESS_SIZE, isContainer, type NodeProcess, type ProcessSize, type ProductProcess, } from './processes.ts';
|
|
5
|
+
export { CATALOG_KEY, type ConnectConfig, defineProduct, type ExtensionGrant, FEATURES, type Feature, isEnabled, LEAKED_PASSWORDS, type LeakedPasswords, OPERATOR_PASSKEYS, type OperatorPasskeys, PLATFORMS, type Platform, type ProductConfig, ProductConfigError, type SessionLength, SIGN_IN_METHODS, type SignInConfig, type SignInMethod, sessionHours, signInSettings, } from './product.ts';
|
|
6
|
+
export { defineScenes, type Flow, FRAME_SIZES, FRAMES, type Frame, type Scene, type SceneInput, type Scenes, ScenesError, type SceneViews, SURFACES, type Surface, sceneUrl, } from './scenes.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { coreEnvSchema, defineEnv, ENVIRONMENTS, EnvError, productionSetup, } from './env.js';
|
|
2
|
+
export { isUploadKind, uploadKindsFit } from './extension-grants.js';
|
|
3
|
+
export { DEFAULT_PROCESS_SIZE, isContainer, } from './processes.js';
|
|
4
|
+
export { CATALOG_KEY, defineProduct, FEATURES, isEnabled, LEAKED_PASSWORDS, OPERATOR_PASSKEYS, PLATFORMS, ProductConfigError, SIGN_IN_METHODS, sessionHours, signInSettings, } from './product.js';
|
|
5
|
+
export { defineScenes, FRAME_SIZES, FRAMES, ScenesError, SURFACES, sceneUrl, } from './scenes.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `processes` in `buffcore.config.ts`: what runs beside the API, declared once. A Node process
|
|
3
|
+
* runs a file of the API's package; a container runs an image pinned by digest, or one built from
|
|
4
|
+
* a folder with a Dockerfile. `ape dev`, CI (`ape services up`), `ape server setup` and `ape deploy`
|
|
5
|
+
* run them from this declaration, `ape services` sizes them, and backups hold their volumes.
|
|
6
|
+
*/
|
|
7
|
+
/** What a process may use: CPUs (a fraction is fine) and memory in MB. */
|
|
8
|
+
export interface ProcessSize {
|
|
9
|
+
cpus: number;
|
|
10
|
+
memoryMb: number;
|
|
11
|
+
}
|
|
12
|
+
/** What a Node process that declares no size is counted as: an estimate, never a limit. */
|
|
13
|
+
export declare const DEFAULT_PROCESS_SIZE: ProcessSize;
|
|
14
|
+
interface ProcessBase {
|
|
15
|
+
/** Its name: its output's prefix in `ape dev` (`[worker]`) and its service on the server. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** How many run in production (1 when left out); development and CI run one. */
|
|
18
|
+
count?: number;
|
|
19
|
+
}
|
|
20
|
+
/** A Node process: `entry` is a TypeScript file relative to the API's folder, e.g. `src/worker.ts`. */
|
|
21
|
+
export interface NodeProcess extends ProcessBase {
|
|
22
|
+
entry: string;
|
|
23
|
+
/** Its limit on the server. Left out, it is counted as `DEFAULT_PROCESS_SIZE` and not limited. */
|
|
24
|
+
size?: ProcessSize;
|
|
25
|
+
}
|
|
26
|
+
/** A container: an image pinned by digest, or one built from a folder of the product. */
|
|
27
|
+
export interface ContainerProcess extends ProcessBase {
|
|
28
|
+
/** An image pinned by digest, e.g. `python:3.13.9-alpine@sha256:…`. */
|
|
29
|
+
image?: string;
|
|
30
|
+
/** A folder of the product with a Dockerfile, its build context: `services/<name>`. */
|
|
31
|
+
build?: string;
|
|
32
|
+
/** The port it listens on, which only this computer reaches: `http://127.0.0.1:<port>`. */
|
|
33
|
+
port?: number;
|
|
34
|
+
/** A command run inside it that exits 0 once it is healthy, e.g. `['python', 'health.py']`. */
|
|
35
|
+
health: readonly string[];
|
|
36
|
+
/** Where it keeps data inside, e.g. `/data`: a volume, which backups hold. */
|
|
37
|
+
volume?: string;
|
|
38
|
+
/** Its limit, wherever it runs. */
|
|
39
|
+
size: ProcessSize;
|
|
40
|
+
}
|
|
41
|
+
export type ProductProcess = NodeProcess | ContainerProcess;
|
|
42
|
+
export declare const isContainer: (process: ProductProcess) => process is ContainerProcess;
|
|
43
|
+
/** What is wrong with the declared processes, each problem naming its process. */
|
|
44
|
+
export declare function processProblems(processes: readonly ProductProcess[]): string[];
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `processes` in `buffcore.config.ts`: what runs beside the API, declared once. A Node process
|
|
3
|
+
* runs a file of the API's package; a container runs an image pinned by digest, or one built from
|
|
4
|
+
* a folder with a Dockerfile. `ape dev`, CI (`ape services up`), `ape server setup` and `ape deploy`
|
|
5
|
+
* run them from this declaration, `ape services` sizes them, and backups hold their volumes.
|
|
6
|
+
*/
|
|
7
|
+
/** What a Node process that declares no size is counted as: an estimate, never a limit. */
|
|
8
|
+
export const DEFAULT_PROCESS_SIZE = { cpus: 0.5, memoryMb: 512 };
|
|
9
|
+
export const isContainer = (process) => !('entry' in process);
|
|
10
|
+
/** Names taken by `ape dev` (`api`, `admin`, `app`) and by the services beside them. */
|
|
11
|
+
const RESERVED = ['api', 'admin', 'app', 'postgres', 'redis', 'rustfs', 'caddy', 'ape'];
|
|
12
|
+
/** Ports the server's own services use on 127.0.0.1 (the API, Postgres, Redis, Caddy's admin). */
|
|
13
|
+
const SERVER_PORTS = [4300, 5432, 6379, 2019];
|
|
14
|
+
const inside = (path) => !/^([a-zA-Z]:)?[\\/]/.test(path) && !path.split(/[\\/]/).includes('..');
|
|
15
|
+
function sizeProblems(name, size) {
|
|
16
|
+
if (!size)
|
|
17
|
+
return [];
|
|
18
|
+
const ok = size.cpus > 0 && Number.isInteger(size.memoryMb) && size.memoryMb >= 16;
|
|
19
|
+
return ok
|
|
20
|
+
? []
|
|
21
|
+
: [`process "${name}" size needs cpus above 0 and memoryMb, a whole number of at least 16`];
|
|
22
|
+
}
|
|
23
|
+
function containerProblems(p, ports) {
|
|
24
|
+
const problems = [];
|
|
25
|
+
const say = (problem) => problems.push(`process "${p.name}" ${problem}`);
|
|
26
|
+
if (p.image && p.build)
|
|
27
|
+
say('takes an image or a build folder, not both');
|
|
28
|
+
if (!p.image && !p.build)
|
|
29
|
+
say('needs an entry, an image or a build folder');
|
|
30
|
+
if (p.image && !/^[a-z0-9][\w./:-]*@sha256:[a-f0-9]{64}$/.test(p.image)) {
|
|
31
|
+
say(`image "${p.image}" must be pinned by its digest, e.g. python:3.13.9-alpine@sha256:…`);
|
|
32
|
+
}
|
|
33
|
+
if (p.build !== undefined && (!p.build || !inside(p.build))) {
|
|
34
|
+
say(`build "${p.build}" must be a folder inside the product, e.g. services/${p.name}`);
|
|
35
|
+
}
|
|
36
|
+
if (p.port !== undefined) {
|
|
37
|
+
if (!Number.isInteger(p.port) || p.port < 1024 || p.port > 65535) {
|
|
38
|
+
say(`port ${p.port} must be a whole number from 1024 to 65535`);
|
|
39
|
+
}
|
|
40
|
+
else if (SERVER_PORTS.includes(p.port))
|
|
41
|
+
say(`port ${p.port} is taken on the server`);
|
|
42
|
+
else if (ports.has(p.port))
|
|
43
|
+
say(`port ${p.port} is another process's`);
|
|
44
|
+
ports.add(p.port);
|
|
45
|
+
if ((p.count ?? 1) > 1)
|
|
46
|
+
say('has a port, so it runs once (count 1)');
|
|
47
|
+
}
|
|
48
|
+
if (!p.health?.length || p.health.some((part) => !part)) {
|
|
49
|
+
say("needs a health check: a command run inside it, e.g. ['python', 'health.py']");
|
|
50
|
+
}
|
|
51
|
+
if (p.volume !== undefined && !/^\/[\w./-]+$/.test(p.volume)) {
|
|
52
|
+
say(`volume "${p.volume}" must be a folder inside the container, e.g. /data`);
|
|
53
|
+
}
|
|
54
|
+
if (!p.size)
|
|
55
|
+
say('needs a size, e.g. { cpus: 0.5, memoryMb: 256 }');
|
|
56
|
+
return problems;
|
|
57
|
+
}
|
|
58
|
+
/** What is wrong with the declared processes, each problem naming its process. */
|
|
59
|
+
export function processProblems(processes) {
|
|
60
|
+
const problems = [];
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
const ports = new Set();
|
|
63
|
+
for (const p of processes) {
|
|
64
|
+
const { name } = p;
|
|
65
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
66
|
+
problems.push(`process name "${name}" must be lowercase letters, digits and dashes`);
|
|
67
|
+
}
|
|
68
|
+
else if (RESERVED.includes(name)) {
|
|
69
|
+
problems.push(`process name "${name}" is taken by ape dev or the services beside it`);
|
|
70
|
+
}
|
|
71
|
+
else if (seen.has(name))
|
|
72
|
+
problems.push(`process "${name}" is declared twice`);
|
|
73
|
+
seen.add(name);
|
|
74
|
+
const count = p.count ?? 1;
|
|
75
|
+
if (!Number.isInteger(count) || count < 1) {
|
|
76
|
+
problems.push(`process "${name}" count must be a whole number of at least 1`);
|
|
77
|
+
}
|
|
78
|
+
problems.push(...sizeProblems(name, p.size));
|
|
79
|
+
if (!isContainer(p)) {
|
|
80
|
+
if ('image' in p || 'build' in p) {
|
|
81
|
+
problems.push(`process "${name}" has an entry, so it is a Node process: no image or build`);
|
|
82
|
+
}
|
|
83
|
+
if (!p.entry.endsWith('.ts') || !inside(p.entry)) {
|
|
84
|
+
problems.push(`process "${name}" entry "${p.entry}" must be a .ts file inside the API's folder, e.g. src/worker.ts`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
problems.push(...containerProblems(p, ports));
|
|
89
|
+
}
|
|
90
|
+
return problems;
|
|
91
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { type AgentLimits } from './agents.ts';
|
|
2
|
+
import { type ExtensionGrant } from './extension-grants.ts';
|
|
3
|
+
import { type ProductProcess } from './processes.ts';
|
|
4
|
+
export type { ExtensionGrant } from './extension-grants.ts';
|
|
5
|
+
export declare const PLATFORMS: readonly ['web', 'ios', 'android'];
|
|
6
|
+
export type Platform = (typeof PLATFORMS)[number];
|
|
7
|
+
/** The feature catalog: what each needs, and the BuffCore release that brings it. */
|
|
8
|
+
export declare const FEATURES: {
|
|
9
|
+
readonly profiles: {
|
|
10
|
+
readonly requires: readonly [];
|
|
11
|
+
readonly since: '0.2';
|
|
12
|
+
};
|
|
13
|
+
readonly devices: {
|
|
14
|
+
readonly requires: readonly ["profiles"];
|
|
15
|
+
readonly since: '0.5';
|
|
16
|
+
};
|
|
17
|
+
readonly consent: {
|
|
18
|
+
readonly requires: readonly [];
|
|
19
|
+
readonly since: '0.5';
|
|
20
|
+
};
|
|
21
|
+
readonly safety: {
|
|
22
|
+
readonly requires: readonly [];
|
|
23
|
+
readonly since: '0.6';
|
|
24
|
+
};
|
|
25
|
+
readonly ai: {
|
|
26
|
+
readonly requires: readonly [];
|
|
27
|
+
readonly since: '0.1';
|
|
28
|
+
};
|
|
29
|
+
readonly generation: {
|
|
30
|
+
readonly requires: readonly ["ai"];
|
|
31
|
+
readonly since: '0.4';
|
|
32
|
+
};
|
|
33
|
+
readonly realtime: {
|
|
34
|
+
readonly requires: readonly [];
|
|
35
|
+
readonly since: '0.3';
|
|
36
|
+
};
|
|
37
|
+
readonly push: {
|
|
38
|
+
readonly requires: readonly [];
|
|
39
|
+
readonly since: '0.5';
|
|
40
|
+
};
|
|
41
|
+
readonly 'in-app-notifications': {
|
|
42
|
+
readonly requires: readonly [];
|
|
43
|
+
readonly since: '0.5';
|
|
44
|
+
};
|
|
45
|
+
readonly 'lifecycle-messages': {
|
|
46
|
+
readonly requires: readonly [];
|
|
47
|
+
readonly since: '0.7';
|
|
48
|
+
};
|
|
49
|
+
readonly uploads: {
|
|
50
|
+
readonly requires: readonly [];
|
|
51
|
+
readonly since: '0.5';
|
|
52
|
+
};
|
|
53
|
+
readonly automation: {
|
|
54
|
+
readonly requires: readonly ["ai"];
|
|
55
|
+
readonly since: '0.6';
|
|
56
|
+
};
|
|
57
|
+
readonly assistant: {
|
|
58
|
+
readonly requires: readonly ["ai", "automation"];
|
|
59
|
+
readonly since: '0.8';
|
|
60
|
+
};
|
|
61
|
+
readonly analytics: {
|
|
62
|
+
readonly requires: readonly [];
|
|
63
|
+
readonly since: '0.6';
|
|
64
|
+
};
|
|
65
|
+
readonly billing: {
|
|
66
|
+
readonly requires: readonly [];
|
|
67
|
+
readonly since: '0.7';
|
|
68
|
+
};
|
|
69
|
+
readonly support: {
|
|
70
|
+
readonly requires: readonly [];
|
|
71
|
+
readonly since: '0.7';
|
|
72
|
+
};
|
|
73
|
+
readonly site: {
|
|
74
|
+
readonly requires: readonly [];
|
|
75
|
+
readonly since: '0.8';
|
|
76
|
+
};
|
|
77
|
+
readonly help: {
|
|
78
|
+
readonly requires: readonly [];
|
|
79
|
+
readonly since: '0.8';
|
|
80
|
+
};
|
|
81
|
+
readonly 'api-keys': {
|
|
82
|
+
readonly requires: readonly [];
|
|
83
|
+
readonly since: '0.6';
|
|
84
|
+
};
|
|
85
|
+
readonly 'mcp-server': {
|
|
86
|
+
readonly requires: readonly [];
|
|
87
|
+
readonly since: '0.6';
|
|
88
|
+
};
|
|
89
|
+
readonly 'ai-gateway': {
|
|
90
|
+
readonly requires: readonly ["ai", "api-keys"];
|
|
91
|
+
readonly since: '0.6';
|
|
92
|
+
};
|
|
93
|
+
readonly webhooks: {
|
|
94
|
+
readonly requires: readonly ["api-keys"];
|
|
95
|
+
readonly since: '0.7';
|
|
96
|
+
};
|
|
97
|
+
readonly 'connected-apps': {
|
|
98
|
+
readonly requires: readonly ["api-keys"];
|
|
99
|
+
readonly since: '0.7';
|
|
100
|
+
};
|
|
101
|
+
readonly 'machine-keys': {
|
|
102
|
+
readonly requires: readonly [];
|
|
103
|
+
readonly since: '0.7';
|
|
104
|
+
};
|
|
105
|
+
readonly mailboxes: {
|
|
106
|
+
readonly requires: readonly ["notifications"];
|
|
107
|
+
readonly since: '0.8';
|
|
108
|
+
};
|
|
109
|
+
readonly 'user-door': {
|
|
110
|
+
readonly requires: readonly ["mcp-server", "api-keys", "in-app-notifications"];
|
|
111
|
+
readonly since: '0.7';
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export type Feature = keyof typeof FEATURES;
|
|
115
|
+
/** Ways members sign in with their email. Apple and Google are the Owner's, in Admin › Services (E2). */
|
|
116
|
+
export declare const SIGN_IN_METHODS: readonly ['password', 'email-code'];
|
|
117
|
+
export type SignInMethod = (typeof SIGN_IN_METHODS)[number];
|
|
118
|
+
/**
|
|
119
|
+
* How long a session lasts: until the person signs out (renewed while it's used), or a fixed
|
|
120
|
+
* time from sign-in.
|
|
121
|
+
*/
|
|
122
|
+
export type SessionLength = 'until-sign-out' | {
|
|
123
|
+
hours: number;
|
|
124
|
+
} | {
|
|
125
|
+
days: number;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* A new password found in known leaks: `refuse` it (the screen says so as it's typed, and the
|
|
129
|
+
* server refuses it), `warn` (the screen says so; it's taken), or `off` (no check at all).
|
|
130
|
+
*/
|
|
131
|
+
export declare const LEAKED_PASSWORDS: readonly ['refuse', 'warn', 'off'];
|
|
132
|
+
export type LeakedPasswords = (typeof LEAKED_PASSWORDS)[number];
|
|
133
|
+
/** Operators' passkeys in the console: beside the password, or in its place (`SignInConfig`). */
|
|
134
|
+
export declare const OPERATOR_PASSKEYS: readonly ['offer', 'require'];
|
|
135
|
+
export type OperatorPasskeys = (typeof OPERATOR_PASSKEYS)[number];
|
|
136
|
+
export interface SignInConfig {
|
|
137
|
+
/** Default `['password']`. `email-code`: a 6-digit code by email, instead of the password. */
|
|
138
|
+
methods?: readonly SignInMethod[];
|
|
139
|
+
/** Default: members stay signed in until they sign out; operators for 12 hours. */
|
|
140
|
+
sessions?: {
|
|
141
|
+
members?: SessionLength;
|
|
142
|
+
operators?: SessionLength;
|
|
143
|
+
};
|
|
144
|
+
/** Default `'refuse'`. For members and operators alike, on sign-up, a reset and a change. */
|
|
145
|
+
leakedPasswords?: LeakedPasswords;
|
|
146
|
+
/** Operators' own sign-in. */
|
|
147
|
+
operators?: {
|
|
148
|
+
/**
|
|
149
|
+
* Passkeys in the console. `offer` (the default): beside the password. `require`: the passkey
|
|
150
|
+
* only, once an operator has one; one with none signs in with password and two-step sign-in,
|
|
151
|
+
* then adds one before the console opens.
|
|
152
|
+
*/
|
|
153
|
+
passkeys?: OperatorPasskeys;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export interface ProductConfig {
|
|
157
|
+
/** The product's name, e.g. 'acme'. */
|
|
158
|
+
name: string;
|
|
159
|
+
/** The pinned BuffCore version, e.g. '0.1.0'. */
|
|
160
|
+
buffcore: string;
|
|
161
|
+
platforms: readonly Platform[];
|
|
162
|
+
/** BCP 47 tags; the first is the default. A right-to-left locale turns right-to-left on. */
|
|
163
|
+
locales: readonly string[];
|
|
164
|
+
features: readonly Feature[];
|
|
165
|
+
/** Proxy IP addresses or CIDRs whose forwarded client address is trusted, plus loopback. */
|
|
166
|
+
trustedProxies?: readonly string[];
|
|
167
|
+
/** How people sign in and how long they stay signed in. */
|
|
168
|
+
signIn?: SignInConfig;
|
|
169
|
+
/** What runs beside the API: Node processes (a worker) and containers (`processes.ts`). */
|
|
170
|
+
processes?: readonly ProductProcess[];
|
|
171
|
+
/** What machines (API keys, MCP clients) and agents may receive (CONNECT.md). */
|
|
172
|
+
connect?: ConnectConfig;
|
|
173
|
+
/**
|
|
174
|
+
* The extensions it composes, by key, and what each may do: written by `ape add` after showing
|
|
175
|
+
* it (EXTENSIONS.md). The app refuses to start when one declares more than this.
|
|
176
|
+
*/
|
|
177
|
+
extensions?: Readonly<Record<string, ExtensionGrant>>;
|
|
178
|
+
/**
|
|
179
|
+
* The signed catalog outside extensions come from (EXTENSIONS.md, "The catalog"): `ape add`
|
|
180
|
+
* installs only from it and `ape deploy` checks every installed one against it. Unset, the
|
|
181
|
+
* distribution's; until that exists, a product names one here. Never an environment variable.
|
|
182
|
+
*/
|
|
183
|
+
catalog?: {
|
|
184
|
+
url: string;
|
|
185
|
+
key: string;
|
|
186
|
+
};
|
|
187
|
+
/** The limits for coding agents: what they may not read, what a person approves at merge (`agents.ts`). */
|
|
188
|
+
agents?: AgentLimits;
|
|
189
|
+
}
|
|
190
|
+
export interface ConnectConfig {
|
|
191
|
+
/**
|
|
192
|
+
* The sensitive kinds that may leave through machine doors (e.g. `contact`). None by default: a
|
|
193
|
+
* route that `carries` a kind not listed here stays closed to machines and agents.
|
|
194
|
+
*/
|
|
195
|
+
allowOut: readonly string[];
|
|
196
|
+
}
|
|
197
|
+
/** An Ed25519 public key as a catalog names it: `ed25519:` and its 32 bytes, base64url. */
|
|
198
|
+
export declare const CATALOG_KEY: RegExp;
|
|
199
|
+
/** The sign-in settings, with BuffCore's defaults filled in. */
|
|
200
|
+
export declare function signInSettings(config: Pick<ProductConfig, 'signIn'>): {
|
|
201
|
+
methods: readonly ("email-code" | "password")[];
|
|
202
|
+
sessions: {
|
|
203
|
+
members: SessionLength;
|
|
204
|
+
operators: SessionLength;
|
|
205
|
+
};
|
|
206
|
+
leakedPasswords: "off" | "refuse" | "warn";
|
|
207
|
+
operators: {
|
|
208
|
+
passkeys: "offer" | "require";
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/** A session length in hours; `null` for "until sign-out". */
|
|
212
|
+
export declare function sessionHours(length: SessionLength): number | null;
|
|
213
|
+
export declare class ProductConfigError extends Error {
|
|
214
|
+
name: string;
|
|
215
|
+
}
|
|
216
|
+
/** Check what's turned on: known features, their requirements, and that this release has them. */
|
|
217
|
+
export declare function defineProduct(config: ProductConfig): ProductConfig;
|
|
218
|
+
export declare function isEnabled(config: ProductConfig, feature: Feature): boolean;
|
package/dist/product.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buffcore.config.ts`: what a product uses. The core is always on; everything else is a
|
|
3
|
+
* feature the product turns on (FEATURES.md).
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { agentProblems } from './agents.js';
|
|
7
|
+
import { grantProblems } from './extension-grants.js';
|
|
8
|
+
import { processProblems } from './processes.js';
|
|
9
|
+
export const PLATFORMS = ['web', 'ios', 'android'];
|
|
10
|
+
/** The feature catalog: what each needs, and the BuffCore release that brings it. */
|
|
11
|
+
export const FEATURES = {
|
|
12
|
+
profiles: { requires: [], since: '0.2' },
|
|
13
|
+
devices: { requires: ['profiles'], since: '0.5' },
|
|
14
|
+
consent: { requires: [], since: '0.5' },
|
|
15
|
+
safety: { requires: [], since: '0.6' },
|
|
16
|
+
ai: { requires: [], since: '0.1' },
|
|
17
|
+
generation: { requires: ['ai'], since: '0.4' },
|
|
18
|
+
realtime: { requires: [], since: '0.3' },
|
|
19
|
+
push: { requires: [], since: '0.5' },
|
|
20
|
+
'in-app-notifications': { requires: [], since: '0.5' },
|
|
21
|
+
'lifecycle-messages': { requires: [], since: '0.7' },
|
|
22
|
+
uploads: { requires: [], since: '0.5' },
|
|
23
|
+
automation: { requires: ['ai'], since: '0.6' },
|
|
24
|
+
assistant: { requires: ['ai', 'automation'], since: '0.8' },
|
|
25
|
+
analytics: { requires: [], since: '0.6' },
|
|
26
|
+
billing: { requires: [], since: '0.7' },
|
|
27
|
+
support: { requires: [], since: '0.7' },
|
|
28
|
+
site: { requires: [], since: '0.8' },
|
|
29
|
+
help: { requires: [], since: '0.8' },
|
|
30
|
+
'api-keys': { requires: [], since: '0.6' },
|
|
31
|
+
'mcp-server': { requires: [], since: '0.6' },
|
|
32
|
+
'ai-gateway': { requires: ['ai', 'api-keys'], since: '0.6' },
|
|
33
|
+
webhooks: { requires: ['api-keys'], since: '0.7' },
|
|
34
|
+
'connected-apps': { requires: ['api-keys'], since: '0.7' },
|
|
35
|
+
// Keys an account holds for the machines of one of its parts (`connect`).
|
|
36
|
+
'machine-keys': { requires: [], since: '0.7' },
|
|
37
|
+
// Connected mailboxes read through notifications' inbound hook.
|
|
38
|
+
mailboxes: { requires: ['notifications'], since: '0.8' },
|
|
39
|
+
// Members connect their own AI clients and keys, one account each (`connect`).
|
|
40
|
+
'user-door': { requires: ['mcp-server', 'api-keys', 'in-app-notifications'], since: '0.7' },
|
|
41
|
+
};
|
|
42
|
+
/** Ways members sign in with their email. Apple and Google are the Owner's, in Admin › Services (E2). */
|
|
43
|
+
export const SIGN_IN_METHODS = ['password', 'email-code'];
|
|
44
|
+
/**
|
|
45
|
+
* A new password found in known leaks: `refuse` it (the screen says so as it's typed, and the
|
|
46
|
+
* server refuses it), `warn` (the screen says so; it's taken), or `off` (no check at all).
|
|
47
|
+
*/
|
|
48
|
+
export const LEAKED_PASSWORDS = ['refuse', 'warn', 'off'];
|
|
49
|
+
/** Operators' passkeys in the console: beside the password, or in its place (`SignInConfig`). */
|
|
50
|
+
export const OPERATOR_PASSKEYS = ['offer', 'require'];
|
|
51
|
+
function proxyProblems(value) {
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
return [];
|
|
54
|
+
if (value === true)
|
|
55
|
+
return ['trustedProxies: true trusts everyone; name IP addresses or CIDRs'];
|
|
56
|
+
if (!Array.isArray(value))
|
|
57
|
+
return ['trustedProxies: must be a list of IP addresses or CIDRs'];
|
|
58
|
+
return Array.from(value).flatMap((entry, index) => {
|
|
59
|
+
const at = `trustedProxies[${index}]`;
|
|
60
|
+
if (typeof entry !== 'string')
|
|
61
|
+
return [`${at}: must be an IP address or CIDR`];
|
|
62
|
+
const label = `${at} (${entry})`;
|
|
63
|
+
const [ip = '', prefix, ...extra] = entry.split('/');
|
|
64
|
+
// IPv6 may end in dotted IPv4; validate that tail before checking its IPv6 shape.
|
|
65
|
+
const embedded = ip.match(/^(.*:)(\d+\.\d+\.\d+\.\d+)$/);
|
|
66
|
+
const v6 = embedded && z.regexes.ipv4.test(embedded[2] ?? '') ? `${embedded[1]}0:0` : ip;
|
|
67
|
+
const bits = z.regexes.ipv4.test(ip) ? 32 : z.regexes.ipv6.test(v6) ? 128 : 0;
|
|
68
|
+
if (!bits || extra.length)
|
|
69
|
+
return [`${label}: must be an IPv4 or IPv6 address or CIDR`];
|
|
70
|
+
if (prefix === undefined)
|
|
71
|
+
return [];
|
|
72
|
+
if (!/^\d+$/.test(prefix) || Number(prefix) > bits)
|
|
73
|
+
return [`${label}: CIDR prefix must be between 1 and ${bits}`];
|
|
74
|
+
if (Number(prefix) === 0)
|
|
75
|
+
return [`${label}: prefix 0 trusts everyone`];
|
|
76
|
+
const family = bits === 32 ? 'IPv4' : 'IPv6';
|
|
77
|
+
const minimum = bits === 32 ? 8 : 32;
|
|
78
|
+
if (Number(prefix) < minimum)
|
|
79
|
+
return [`${label}: ${family} CIDR prefix must be at least /${minimum}`];
|
|
80
|
+
// A mapped ::ffff:a.b.c.d/(96+k) is an IPv4 /k: hold it to the IPv4 minimum (/8 is /104).
|
|
81
|
+
const mapped = bits === 128 &&
|
|
82
|
+
Number(prefix) >= 96 &&
|
|
83
|
+
new URL(`http://[${ip}]/`).hostname.startsWith('[::ffff:');
|
|
84
|
+
if (mapped && Number(prefix) === 96)
|
|
85
|
+
return [`${label}: mapped /96 trusts every IPv4 address`];
|
|
86
|
+
if (mapped && Number(prefix) < 104)
|
|
87
|
+
return [`${label}: a mapped IPv4 range must be at least /104 (IPv4 /8)`];
|
|
88
|
+
return [];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** An Ed25519 public key as a catalog names it: `ed25519:` and its 32 bytes, base64url. */
|
|
92
|
+
export const CATALOG_KEY = /^ed25519:[A-Za-z0-9_-]{43}$/;
|
|
93
|
+
function catalogProblems(catalog) {
|
|
94
|
+
if (!catalog)
|
|
95
|
+
return [];
|
|
96
|
+
const problems = [];
|
|
97
|
+
if (typeof catalog.url !== 'string' || !/^https:\/\/[^\s/]+/.test(catalog.url))
|
|
98
|
+
problems.push("catalog.url is the catalog's https:// address");
|
|
99
|
+
if (typeof catalog.key !== 'string' || !CATALOG_KEY.test(catalog.key))
|
|
100
|
+
problems.push("catalog.key is its signing key's public half: 'ed25519:' and 43 characters");
|
|
101
|
+
return problems;
|
|
102
|
+
}
|
|
103
|
+
/** The sign-in settings, with BuffCore's defaults filled in. */
|
|
104
|
+
export function signInSettings(config) {
|
|
105
|
+
return {
|
|
106
|
+
methods: config.signIn?.methods ?? ['password'],
|
|
107
|
+
sessions: {
|
|
108
|
+
members: config.signIn?.sessions?.members ?? 'until-sign-out',
|
|
109
|
+
operators: config.signIn?.sessions?.operators ?? { hours: 12 },
|
|
110
|
+
},
|
|
111
|
+
leakedPasswords: config.signIn?.leakedPasswords ?? 'refuse',
|
|
112
|
+
operators: { passkeys: config.signIn?.operators?.passkeys ?? 'offer' },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** A session length in hours; `null` for "until sign-out". */
|
|
116
|
+
export function sessionHours(length) {
|
|
117
|
+
if (length === 'until-sign-out')
|
|
118
|
+
return null;
|
|
119
|
+
return 'days' in length ? length.days * 24 : length.hours;
|
|
120
|
+
}
|
|
121
|
+
export class ProductConfigError extends Error {
|
|
122
|
+
name = 'ProductConfigError';
|
|
123
|
+
}
|
|
124
|
+
const minor = (version) => {
|
|
125
|
+
const [major = '0', min = '0'] = version.split('.');
|
|
126
|
+
return Number(major) * 1000 + Number(min);
|
|
127
|
+
};
|
|
128
|
+
/** Check what's turned on: known features, their requirements, and that this release has them. */
|
|
129
|
+
export function defineProduct(config) {
|
|
130
|
+
const problems = [];
|
|
131
|
+
if (config.locales.length === 0)
|
|
132
|
+
problems.push('list at least one locale');
|
|
133
|
+
if (!config.platforms.includes('web'))
|
|
134
|
+
problems.push('list "web": the admin console and the web app need it');
|
|
135
|
+
for (const feature of config.features) {
|
|
136
|
+
const entry = FEATURES[feature];
|
|
137
|
+
if (!entry) {
|
|
138
|
+
problems.push(`unknown feature "${feature}"`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (minor(entry.since) > minor(config.buffcore)) {
|
|
142
|
+
problems.push(`"${feature}" arrives in BuffCore ${entry.since}; this product pins ${config.buffcore}`);
|
|
143
|
+
}
|
|
144
|
+
for (const needed of entry.requires) {
|
|
145
|
+
// Notifications is a core module, present without a feature flag.
|
|
146
|
+
if (needed !== 'notifications' && !config.features.includes(needed))
|
|
147
|
+
problems.push(`"${feature}" needs "${needed}"`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const signIn = signInSettings(config);
|
|
151
|
+
for (const method of signIn.methods) {
|
|
152
|
+
if (!SIGN_IN_METHODS.includes(method))
|
|
153
|
+
problems.push(`unknown sign-in method "${method}"`);
|
|
154
|
+
}
|
|
155
|
+
if (!LEAKED_PASSWORDS.includes(signIn.leakedPasswords)) {
|
|
156
|
+
problems.push(`unknown signIn.leakedPasswords "${signIn.leakedPasswords}": refuse, warn or off`);
|
|
157
|
+
}
|
|
158
|
+
if (!OPERATOR_PASSKEYS.includes(signIn.operators.passkeys)) {
|
|
159
|
+
problems.push(`unknown signIn.operators.passkeys "${signIn.operators.passkeys}": offer or require`);
|
|
160
|
+
}
|
|
161
|
+
if (!signIn.methods.includes('password')) {
|
|
162
|
+
problems.push('sign-in methods need "password" until passwordless accounts arrive (v0.7)');
|
|
163
|
+
}
|
|
164
|
+
for (const [kind, length] of Object.entries(signIn.sessions)) {
|
|
165
|
+
const hours = sessionHours(length);
|
|
166
|
+
if (hours !== null && !(hours > 0))
|
|
167
|
+
problems.push(`${kind} sessions need a length above zero`);
|
|
168
|
+
}
|
|
169
|
+
problems.push(...processProblems(config.processes ?? []));
|
|
170
|
+
problems.push(...grantProblems(config.extensions ?? {}));
|
|
171
|
+
problems.push(...catalogProblems(config.catalog));
|
|
172
|
+
problems.push(...proxyProblems(config.trustedProxies));
|
|
173
|
+
if (config.agents)
|
|
174
|
+
problems.push(...agentProblems(config.agents));
|
|
175
|
+
if (problems.length > 0) {
|
|
176
|
+
throw new ProductConfigError(`buffcore.config.ts:\n${problems.map((p) => ` ${p}`).join('\n')}`);
|
|
177
|
+
}
|
|
178
|
+
return config;
|
|
179
|
+
}
|
|
180
|
+
export function isEnabled(config, feature) {
|
|
181
|
+
return config.features.includes(feature);
|
|
182
|
+
}
|
package/dist/scenes.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prototype's scenes and flows, in the product's `prototype/scenes.ts` (PROTOTYPE.md).
|
|
3
|
+
* A scene is one view with sample props; a flow is scenes in order, each with a caption.
|
|
4
|
+
*
|
|
5
|
+
* A scene names its view (`view: 'NotesView'`) instead of importing it: the admin console can't
|
|
6
|
+
* load the app's views, nor the app the admin's. Each surface's `/_scene` route is given its
|
|
7
|
+
* views by name, and the type argument checks each scene's props against its view's props:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import type * as app from '../app/src/prototype/views.ts';
|
|
11
|
+
* export default defineScenes<{ app: typeof app }>({
|
|
12
|
+
* scenes: [{ key: 'notes-empty', title: 'Notes · empty', surface: 'app', view: 'NotesView', props }],
|
|
13
|
+
* flows: [{ key: 'first-note', title: 'A first note', steps: [{ scene: 'notes-empty', caption: '…' }] }],
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import type { Theme } from '@buffcore/tokens';
|
|
18
|
+
export declare const SURFACES: readonly ['app', 'admin'];
|
|
19
|
+
export type Surface = (typeof SURFACES)[number];
|
|
20
|
+
/** Where a scene shows: the app on a phone, a tablet or a desktop browser, or the admin console. */
|
|
21
|
+
export declare const FRAMES: readonly ['phone', 'tablet', 'desktop', 'admin'];
|
|
22
|
+
export type Frame = (typeof FRAMES)[number];
|
|
23
|
+
/** Each frame in CSS pixels: a common phone, tablet and laptop, and a usual console window. */
|
|
24
|
+
export declare const FRAME_SIZES: Record<Frame, {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* The bare page that shows one scene in a theme, mode and language, on its surface's server
|
|
30
|
+
* (`base` empty: the page's own): the viewer frames it, `ape prototype snapshot` screenshots it.
|
|
31
|
+
* A `scale` shows an app scene at that scale instead of its own; without one, the scene's own.
|
|
32
|
+
*/
|
|
33
|
+
export declare function sceneUrl(base: string, key: string, { scale, ...look }: {
|
|
34
|
+
theme: string;
|
|
35
|
+
mode: string;
|
|
36
|
+
locale: string;
|
|
37
|
+
scale?: number;
|
|
38
|
+
}): string;
|
|
39
|
+
/** Each surface's views by name (`typeof` a module of views): what its `/_scene` route renders. */
|
|
40
|
+
export type SceneViews = {
|
|
41
|
+
[S in Surface]?: Record<string, unknown>;
|
|
42
|
+
};
|
|
43
|
+
type PropsOf<V> = V extends (props: infer P) => unknown ? P : unknown;
|
|
44
|
+
/** A scene as written: one view of one surface, with that view's props. */
|
|
45
|
+
export type SceneInput<V extends SceneViews> = {
|
|
46
|
+
[S in Surface]: {
|
|
47
|
+
[N in keyof V[S] & string]: {
|
|
48
|
+
/** Unique among the scenes; the scene's URL carries it. */
|
|
49
|
+
key: string;
|
|
50
|
+
/** What the viewer lists, e.g. "Notes · empty". */
|
|
51
|
+
title: string;
|
|
52
|
+
surface: S;
|
|
53
|
+
/** Default: `phone` for the app, `admin` for the admin console. */
|
|
54
|
+
frame?: Frame;
|
|
55
|
+
/**
|
|
56
|
+
* The viewer's rail group for this scene, as plain words ("Notes", "Reference"). Scenes with
|
|
57
|
+
* the same group sit together, in first appearance order; without one, the surface's own.
|
|
58
|
+
*/
|
|
59
|
+
group?: string;
|
|
60
|
+
/**
|
|
61
|
+
* An app scene at a person's scale (the app shell's `setScale`), e.g. 1.3. Default 1. The
|
|
62
|
+
* viewer's scale menu, once picked, shows it at that scale instead.
|
|
63
|
+
*/
|
|
64
|
+
scale?: number;
|
|
65
|
+
view: N;
|
|
66
|
+
/** Sample props: synthetic data only, never copied from real people. */
|
|
67
|
+
props: PropsOf<NonNullable<V[S]>[N]>;
|
|
68
|
+
};
|
|
69
|
+
}[keyof V[S] & string];
|
|
70
|
+
}[Surface];
|
|
71
|
+
/** A checked scene: what the viewer and the `/_scene` routes read. */
|
|
72
|
+
export interface Scene {
|
|
73
|
+
key: string;
|
|
74
|
+
title: string;
|
|
75
|
+
surface: Surface;
|
|
76
|
+
frame: Frame;
|
|
77
|
+
/** The viewer's rail group, as plain words; when unset, the surface's own. */
|
|
78
|
+
group?: string;
|
|
79
|
+
scale?: number;
|
|
80
|
+
view: string;
|
|
81
|
+
props: unknown;
|
|
82
|
+
}
|
|
83
|
+
/** Scenes in the order a person meets them, each step with a caption. */
|
|
84
|
+
export interface Flow {
|
|
85
|
+
key: string;
|
|
86
|
+
title: string;
|
|
87
|
+
steps: readonly {
|
|
88
|
+
scene: string;
|
|
89
|
+
caption: string;
|
|
90
|
+
}[];
|
|
91
|
+
}
|
|
92
|
+
export interface Scenes {
|
|
93
|
+
scenes: readonly Scene[];
|
|
94
|
+
flows: readonly Flow[];
|
|
95
|
+
/** The product's theme: `ape prototype snapshot` shows each scene in it beside the starter themes, and checks it. */
|
|
96
|
+
theme?: Theme;
|
|
97
|
+
}
|
|
98
|
+
export declare class ScenesError extends Error {
|
|
99
|
+
name: string;
|
|
100
|
+
}
|
|
101
|
+
/** Check the scenes and flows: unique keys, and every flow step shows a scene that exists. */
|
|
102
|
+
export declare function defineScenes<V extends SceneViews = {
|
|
103
|
+
[S in Surface]: Record<string, unknown>;
|
|
104
|
+
}>(input: {
|
|
105
|
+
scenes: readonly SceneInput<V>[];
|
|
106
|
+
flows?: readonly Flow[];
|
|
107
|
+
theme?: Theme;
|
|
108
|
+
}): Scenes;
|
|
109
|
+
export {};
|
package/dist/scenes.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const SURFACES = ['app', 'admin'];
|
|
2
|
+
/** Where a scene shows: the app on a phone, a tablet or a desktop browser, or the admin console. */
|
|
3
|
+
export const FRAMES = ['phone', 'tablet', 'desktop', 'admin'];
|
|
4
|
+
/** Each frame in CSS pixels: a common phone, tablet and laptop, and a usual console window. */
|
|
5
|
+
export const FRAME_SIZES = {
|
|
6
|
+
phone: { width: 390, height: 844 },
|
|
7
|
+
tablet: { width: 820, height: 1180 },
|
|
8
|
+
desktop: { width: 1280, height: 800 },
|
|
9
|
+
admin: { width: 1440, height: 900 },
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The bare page that shows one scene in a theme, mode and language, on its surface's server
|
|
13
|
+
* (`base` empty: the page's own): the viewer frames it, `ape prototype snapshot` screenshots it.
|
|
14
|
+
* A `scale` shows an app scene at that scale instead of its own; without one, the scene's own.
|
|
15
|
+
*/
|
|
16
|
+
export function sceneUrl(base, key, { scale, ...look }) {
|
|
17
|
+
const query = new URLSearchParams({ key, ...look, ...(scale ? { scale: String(scale) } : {}) });
|
|
18
|
+
return `${base}/_scene?${query}`;
|
|
19
|
+
}
|
|
20
|
+
export class ScenesError extends Error {
|
|
21
|
+
name = 'ScenesError';
|
|
22
|
+
}
|
|
23
|
+
/** Check the scenes and flows: unique keys, and every flow step shows a scene that exists. */
|
|
24
|
+
export function defineScenes(input) {
|
|
25
|
+
const problems = [];
|
|
26
|
+
const keys = new Set();
|
|
27
|
+
for (const scene of input.scenes) {
|
|
28
|
+
if (keys.has(scene.key))
|
|
29
|
+
problems.push(`two scenes are called "${scene.key}"`);
|
|
30
|
+
keys.add(scene.key);
|
|
31
|
+
}
|
|
32
|
+
const flows = input.flows ?? [];
|
|
33
|
+
const flowKeys = new Set();
|
|
34
|
+
for (const flow of flows) {
|
|
35
|
+
if (flowKeys.has(flow.key))
|
|
36
|
+
problems.push(`two flows are called "${flow.key}"`);
|
|
37
|
+
flowKeys.add(flow.key);
|
|
38
|
+
if (flow.steps.length === 0)
|
|
39
|
+
problems.push(`flow "${flow.key}" has no steps`);
|
|
40
|
+
for (const step of flow.steps) {
|
|
41
|
+
if (!keys.has(step.scene))
|
|
42
|
+
problems.push(`flow "${flow.key}" shows "${step.scene}", no scene`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (problems.length > 0) {
|
|
46
|
+
throw new ScenesError(`prototype/scenes.ts:\n${problems.map((p) => ` ${p}`).join('\n')}`);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
scenes: input.scenes.map((scene) => ({
|
|
50
|
+
...scene,
|
|
51
|
+
frame: scene.frame ?? (scene.surface === 'admin' ? 'admin' : 'phone'),
|
|
52
|
+
})),
|
|
53
|
+
flows,
|
|
54
|
+
...(input.theme ? { theme: input.theme } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buffcore/config",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.8.39",
|
|
4
|
+
"description": "TypeScript, Biome and Vitest presets, the environment schema helper and `defineProduct` for BuffCore products.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "BuffApe",
|
|
7
|
+
"homepage": "https://buffape.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/buffape/buffape.git",
|
|
11
|
+
"directory": "packages/config"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/buffape/buffape/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/index.js",
|
|
19
|
+
"./tsconfig.json": "./tsconfig.preset.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"tsconfig.preset.json",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"NOTICE"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"zod": "4.6.5",
|
|
32
|
+
"@buffcore/tokens": "0.8.39"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
37
|
+
"test": "vitest run --coverage"
|
|
38
|
+
}
|
|
6
39
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2024",
|
|
4
|
+
"lib": ["es2024"],
|
|
5
|
+
"module": "preserve",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"allowImportingTsExtensions": true,
|
|
8
|
+
"rewriteRelativeImportExtensions": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"noImplicitOverride": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"jsx": "react-jsx",
|
|
18
|
+
"types": ["node"]
|
|
19
|
+
}
|
|
20
|
+
}
|