@o3co/auth-provider-scaffold 0.0.0-stage → 0.18.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +4 -2
  3. package/combinations/README.md +42 -0
  4. package/combinations/src/composed.d.ts +18 -0
  5. package/combinations/src/composed.js +132 -0
  6. package/combinations/src/contract.d.ts +13 -0
  7. package/combinations/src/contract.js +26 -0
  8. package/combinations/src/declared.d.ts +38 -0
  9. package/combinations/src/declared.js +75 -0
  10. package/combinations/src/kinds.d.ts +12 -0
  11. package/combinations/src/kinds.js +11 -0
  12. package/create-app/README.md +54 -0
  13. package/create-app/src/audit-events.d.ts +22 -0
  14. package/create-app/src/audit-events.js +76 -0
  15. package/create-app/src/command.d.ts +5 -0
  16. package/create-app/src/command.js +69 -0
  17. package/create-app/src/configuration.d.ts +44 -0
  18. package/create-app/src/configuration.js +161 -0
  19. package/create-app/src/contract.d.ts +6 -0
  20. package/create-app/src/contract.js +4 -0
  21. package/create-app/src/deployment.d.ts +8 -0
  22. package/create-app/src/deployment.js +100 -0
  23. package/create-app/src/fragments.d.ts +41 -0
  24. package/create-app/src/fragments.js +109 -0
  25. package/create-app/src/full.d.ts +2 -0
  26. package/create-app/src/full.js +18 -0
  27. package/create-app/src/generate.d.ts +21 -0
  28. package/create-app/src/generate.js +33 -0
  29. package/create-app/src/main.d.ts +2 -0
  30. package/create-app/src/main.js +3 -0
  31. package/create-app/src/packages.d.ts +17 -0
  32. package/create-app/src/packages.js +40 -0
  33. package/create-app/src/pattern.d.ts +9 -0
  34. package/create-app/src/pattern.js +31 -0
  35. package/create-app/src/patterns/README.md +26 -0
  36. package/create-app/src/patterns/a2a.d.ts +2 -0
  37. package/create-app/src/patterns/a2a.js +18 -0
  38. package/create-app/src/patterns/a2a.md +7 -0
  39. package/create-app/src/patterns/chosen.d.ts +2 -0
  40. package/create-app/src/patterns/chosen.js +35 -0
  41. package/create-app/src/patterns/device.d.ts +2 -0
  42. package/create-app/src/patterns/device.js +14 -0
  43. package/create-app/src/patterns/device.md +6 -0
  44. package/create-app/src/patterns/mfa-web.d.ts +2 -0
  45. package/create-app/src/patterns/mfa-web.js +25 -0
  46. package/create-app/src/patterns/mfa-web.md +8 -0
  47. package/create-app/src/patterns/native-app.d.ts +2 -0
  48. package/create-app/src/patterns/native-app.js +11 -0
  49. package/create-app/src/patterns/native-app.md +6 -0
  50. package/create-app/src/patterns/pattern.d.ts +28 -0
  51. package/create-app/src/patterns/pattern.js +31 -0
  52. package/create-app/src/patterns/patterns.d.ts +15 -0
  53. package/create-app/src/patterns/patterns.js +49 -0
  54. package/create-app/src/patterns/simple-web.d.ts +2 -0
  55. package/create-app/src/patterns/simple-web.js +34 -0
  56. package/create-app/src/patterns/simple-web.md +6 -0
  57. package/create-app/src/patterns/sso-federated.d.ts +2 -0
  58. package/create-app/src/patterns/sso-federated.js +23 -0
  59. package/create-app/src/patterns/sso-federated.md +6 -0
  60. package/create-app/src/project.d.ts +19 -0
  61. package/create-app/src/project.js +76 -0
  62. package/create-app/src/trial.d.ts +17 -0
  63. package/create-app/src/trial.js +93 -0
  64. package/create-app/src/write-configuration.d.ts +2 -0
  65. package/create-app/src/write-configuration.js +10 -0
  66. package/create-app/templates/full-readme.md +67 -0
  67. package/create-app/templates/main.ts.template +28 -0
  68. package/create-app/templates/pattern-readme.md +70 -0
  69. package/index.json +2709 -0
  70. package/package.json +28 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 1o1 Co. Ltd.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @o3co/auth-provider-scaffold
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Part of auth-provider 0.18.0-rc.1, built from `modules/scaffold` of https://github.com/o3co/auth.provider. Its modules, settings and documentation are there.
4
+
5
+ Copyright 2026 1o1 Co. Ltd. Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,42 @@
1
+ # combinations
2
+
3
+ ## Responsibilities
4
+ - Completes a list of modules with what comes with them by default: each feature's wirings, and the bridges whose modules are all composed.
5
+ - Composes a selection, and the full template, from what the packages need to run and the axes their adapters declare.
6
+ - Reads all of it from the package.json of each package the workspace definition lists or, built into a bundle, from the index at the bundle's root (those manifests as written); adding a wiring, a bridge or an adapter needs no change here.
7
+
8
+ ## Not here
9
+ - Whether a composition boots: the kernel's refusals.
10
+ - What each kind may depend on, and the checks on it: `guard`.
11
+ - Generating an app: `create-app`.
12
+ - Running scenes: the conformance areas.
13
+ - Checking that each feature declaring `storeWiring` has a wiring: `guard`.
14
+
15
+ ## Offers
16
+ - `completed`: the modules given, each owner whose declared default replaces it swapped for that default and each adapter's owner counted for bridges, then the wirings and bridges they come with, including those of what is brought in, each once, in the order first named.
17
+ - `composed` (features in named groups, an adapter or the owner by axis owner, modules added): the selection, what it needs to run (a foundation or feature among its dependencies, in turn), each composed axis's chosen adapter or default, then `completed`.
18
+ - `composed` refuses, naming each: a name the workspace lacks, a group value that is not a feature, an addition that is not a feature or adapter with a module, an axis key that owns no axis, an axis value that is neither its adapter nor its owner, and an owner chosen for its own axis that has no module.
19
+ - `needed` (modules): the modules given, what they need to run, then `completed`, as `composed` reaches them but with no axis default other than one declared to replace its owner; owners a reached adapter replaces are left out.
20
+ - `full` (modules added): every foundation and feature with a module that does not opt in, composed alike. `optIns`: the features that opt in.
21
+ - `kinds`: the kinds a package's manifest may name, the one place their words are written.
22
+
23
+ ## Invariants
24
+ - A wiring names the feature it `wires`; it comes with the feature, whether given or brought in.
25
+ - A bridge names the modules it `joins`, a non-empty list of names; it comes once every one of them is composed, whether given or brought in. An axis owner reached counts, with a module or not.
26
+ - A `joins` that is not a non-empty list of names, or a `wires` that is not a name, is refused, naming each such package.
27
+ - Wirings of one feature, and bridges, come in code point order of name.
28
+ - An axis is its owner's: an adapter `replaces` the owner (composed instead of its module) or `adapts` it (beside it). Its default is the one adapter declaring `default`, or its only one.
29
+ - An axis's default comes only where its owner is composed (reached among what runs, with a module or not, as the kernel), and not where another adapter of that axis is already composed. A default declared to replace its owner comes wherever that owner would, whether the owner has a module or not, so the owner's module is never composed beside it.
30
+ - A feature that opts in comes in `full` only where something composed needs it to run.
31
+ - Every name it gives is a module of the workspace, as it reads them there.
32
+
33
+ ## Data
34
+ - The workspace's declarations, read once per process; nothing is written.
35
+
36
+ ## Depends on
37
+ - `pnpm` (asks it for the packages the workspace definition lists); nothing in the workspace.
38
+
39
+ ## Vocabulary
40
+ - axis: an owner's adapters to outside systems; default: the adapter composed unless another is chosen.
41
+ - wiring: the module that ties a feature's store interfaces to an implementation.
42
+ - bridge: a module that comes once every module it joins is composed: one module it adds to (`metrics` to `http`), or several it ties together (`session-tokens`).
@@ -0,0 +1,18 @@
1
+ import { type Declared } from "./declared.js";
2
+ /** What to compose: features in named groups, an adapter (or the owner itself) by axis owner, and anything added. */
3
+ export interface Selection {
4
+ readonly features: Readonly<Record<string, readonly string[]>>;
5
+ readonly axes?: Readonly<Record<string, string>>;
6
+ readonly add?: readonly string[];
7
+ }
8
+ /** A selection's modules, first reached first: what it names and needs, each composed axis's chosen
9
+ * adapter or default (none where another adapter of it is there), wirings and bridges; replaced owners left out. */
10
+ export declare function composedWith(declared: Declared, selection: Selection): string[];
11
+ /** The modules given and what they need to run, in turn, then wirings and bridges; owners a reached adapter replaces left out; of axis defaults, only one declared to replace its owner. */
12
+ export declare const neededWith: (declared: Declared, modules: readonly string[]) => string[];
13
+ /** The modules given, owners a declared default replaces swapped for it (still counted for bridges), then wirings and bridges. */
14
+ export declare function completedOf(declared: Declared, modules: readonly string[]): string[];
15
+ /** The full template: every foundation and feature with a module that does not opt in, and what is added. */
16
+ export declare function fullWith(declared: Declared, add?: readonly string[]): string[];
17
+ /** The features that opt in: the full template leaves them out until added. */
18
+ export declare const optInsOf: (declared: Declared) => string[];
@@ -0,0 +1,132 @@
1
+ import { completedWith } from "./declared.js";
2
+ import { kinds } from "./kinds.js";
3
+ /** The axis owner a package adapts to or replaces. */
4
+ const axisOf = (p) => p?.replaces ?? p?.adapts;
5
+ /** Each axis's adapters, by owner; the default is the one declaring it, or the only one. */
6
+ function axesIn(declared) {
7
+ const adapters = new Map();
8
+ for (const p of declared.packages.values()) {
9
+ const owner = axisOf(p);
10
+ if (owner !== undefined)
11
+ adapters.set(owner, [...(adapters.get(owner) ?? []), p]);
12
+ }
13
+ const defaultOf = (owner) => {
14
+ const of = adapters.get(owner) ?? [];
15
+ return (of.length === 1 ? of[0] : of.find((p) => p.default))?.name;
16
+ };
17
+ /** The adapter declared the default that replaces an owner: it composes in the owner's place, a module or not. */
18
+ const replacingOf = (owner) => (adapters.get(owner) ?? []).find((p) => p.default && p.replaces === owner)?.name;
19
+ return { adapters, defaultOf, replacingOf };
20
+ }
21
+ /** Why each name cannot be selected, or none. */
22
+ function refusals(declared, selection) {
23
+ const { adapters } = axesIn(declared);
24
+ const known = (name) => declared.packages.get(name);
25
+ const absent = (name) => (known(name) ? [] : [`${name}: not in the workspace`]);
26
+ const grouped = Object.values(selection.features).flat();
27
+ const added = selection.add ?? [];
28
+ const axes = Object.entries(selection.axes ?? {});
29
+ return [
30
+ ...[...grouped, ...added, ...axes.flat()]
31
+ .filter((n, i, all) => all.indexOf(n) === i)
32
+ .flatMap(absent),
33
+ ...grouped
34
+ .filter((n) => known(n) && known(n)?.kind !== kinds.feature)
35
+ .map((n) => `${n}: not a feature`),
36
+ ...added
37
+ .filter((n) => {
38
+ const p = known(n);
39
+ return p && !(p.module && (p.kind === kinds.feature || p.kind === kinds.adapter));
40
+ })
41
+ .map((n) => `${n}: not a feature or an adapter with a module`),
42
+ ...axes
43
+ .filter(([owner]) => known(owner) && !adapters.has(owner))
44
+ .map(([owner]) => `${owner}: not an axis's owner`),
45
+ ...axes
46
+ .filter(([owner, chosen]) => adapters.has(owner) && known(chosen) && chosen !== owner)
47
+ .filter(([owner, chosen]) => axisOf(known(chosen)) !== owner)
48
+ .map(([owner, chosen]) => `${chosen}: not an adapter of ${owner}`),
49
+ ...axes
50
+ .filter(([owner, chosen]) => adapters.has(owner) && chosen === owner && !known(owner)?.module)
51
+ .map(([owner]) => `axes.${owner} = ${owner}: the owner has no module, so it cannot serve its own axis`),
52
+ ];
53
+ }
54
+ /** A selection's modules, first reached first: what it names and needs, each composed axis's chosen
55
+ * adapter or default (none where another adapter of it is there), wirings and bridges; replaced owners left out. */
56
+ export function composedWith(declared, selection) {
57
+ const refused = refusals(declared, selection);
58
+ if (refused.length > 0)
59
+ throw new Error(refused.join("; "));
60
+ return composing(declared, [...Object.values(selection.features).flat(), ...(selection.add ?? [])], selection.axes ?? {});
61
+ }
62
+ /** The modules given and what they need to run, in turn, then wirings and bridges; owners a reached adapter replaces left out; of axis defaults, only one declared to replace its owner. */
63
+ export const neededWith = (declared, modules) => composing(declared, modules, {}, { defaults: false });
64
+ function composing(declared, start, chosen, { defaults } = { defaults: true }) {
65
+ const { adapters, defaultOf, replacingOf } = axesIn(declared);
66
+ const runs = (name) => {
67
+ const p = declared.packages.get(name);
68
+ return p?.kind === kinds.foundation || p?.kind === kinds.feature;
69
+ };
70
+ /** Every package reached, a module or not: an axis owner reached is composed. */
71
+ const reached = [];
72
+ const reach = (name) => {
73
+ if (!reached.includes(name))
74
+ reached.push(name);
75
+ };
76
+ for (const name of start)
77
+ reach(name);
78
+ for (let size = -1; size !== reached.length;) {
79
+ size = reached.length;
80
+ for (const name of reached)
81
+ for (const need of declared.packages.get(name)?.needs ?? []) {
82
+ // An axis owner is reached whatever its kind, as the kernel: its axis then applies.
83
+ if (runs(need) || adapters.has(need))
84
+ reach(need);
85
+ }
86
+ for (const owner of reached.filter((name) => adapters.has(name))) {
87
+ const pick = chosen[owner];
88
+ if (pick !== undefined) {
89
+ if (pick !== owner)
90
+ reach(pick);
91
+ }
92
+ else if (!(adapters.get(owner) ?? []).some((a) => reached.includes(a.name))) {
93
+ const fallback = defaults ? defaultOf(owner) : replacingOf(owner);
94
+ if (fallback !== undefined)
95
+ reach(fallback);
96
+ }
97
+ }
98
+ // An axis owner reached counts for bridges, as a module does, whether it has one or not.
99
+ const joined = reached.filter((name) => declared.packages.get(name)?.module || adapters.has(name));
100
+ for (const name of completedWith(declared, joined))
101
+ reach(name);
102
+ }
103
+ const replaced = new Set(reached.flatMap((name) => declared.packages.get(name)?.replaces ?? []));
104
+ return reached.filter((name) => declared.packages.get(name)?.module && !replaced.has(name));
105
+ }
106
+ /** The modules given, owners a declared default replaces swapped for it (still counted for bridges), then wirings and bridges. */
107
+ export function completedOf(declared, modules) {
108
+ const { replacingOf } = axesIn(declared);
109
+ // An owner named brings its default; an adapter named brings the owner it replaces, for bridges.
110
+ const swapped = modules.flatMap((name) => {
111
+ const by = replacingOf(name);
112
+ const owner = declared.packages.get(name)?.replaces;
113
+ const missing = (other) => other === undefined || modules.includes(other) ? [] : [other];
114
+ return [name, ...missing(by), ...missing(owner)];
115
+ });
116
+ const replaced = new Set(swapped.flatMap((name) => declared.packages.get(name)?.replaces ?? []));
117
+ return completedWith(declared, swapped).filter((name) => !replaced.has(name));
118
+ }
119
+ /** The full template: every foundation and feature with a module that does not opt in, and what is added. */
120
+ export function fullWith(declared, add = []) {
121
+ const refused = refusals(declared, { features: {}, add });
122
+ if (refused.length > 0)
123
+ throw new Error(refused.join("; "));
124
+ const base = [...declared.packages.values()]
125
+ .filter((p) => p.module && !p.optIn && (p.kind === kinds.foundation || p.kind === kinds.feature))
126
+ .map((p) => p.name);
127
+ return composing(declared, [...base, ...add], {});
128
+ }
129
+ /** The features that opt in: the full template leaves them out until added. */
130
+ export const optInsOf = (declared) => [...declared.packages.values()]
131
+ .filter((p) => p.optIn && p.kind === kinds.feature)
132
+ .map((p) => p.name);
@@ -0,0 +1,13 @@
1
+ import { type Selection } from "./composed.js";
2
+ export type { Selection } from "./composed.js";
3
+ export { type Kind, kinds } from "./kinds.js";
4
+ /** The modules given (owners a declared default replaces swapped for it), then their wirings and bridges, each once, first named first. */
5
+ export declare function completed(modules: readonly string[]): string[];
6
+ /** What a selection composes (see `composedWith`); refuses, naming each, what cannot be selected. */
7
+ export declare const composed: (selection: Selection) => string[];
8
+ /** The full template: every foundation and feature that does not opt in, with each default, and what is added. */
9
+ export declare const full: (add?: readonly string[]) => string[];
10
+ /** The features that opt in, which the full template leaves out until added. */
11
+ export declare const optIns: () => string[];
12
+ /** The modules given, what they need to run, then `completed`, as `composed` reaches them but with no axis default. */
13
+ export declare const needed: (modules: readonly string[]) => string[];
@@ -0,0 +1,26 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { completedOf, composedWith, fullWith, neededWith, optInsOf, } from "./composed.js";
4
+ import { declaredIn, declaredInIndex } from "./declared.js";
5
+ export { kinds } from "./kinds.js";
6
+ let workspace;
7
+ /** The modules given (owners a declared default replaces swapped for it), then their wirings and bridges, each once, first named first. */
8
+ export function completed(modules) {
9
+ return completedOf(declared(), modules);
10
+ }
11
+ /** Read once: built into a bundle, the index at its root; in the workspace, the workspace itself. */
12
+ const declared = () => {
13
+ const index = join(import.meta.dirname, "..", "..", "index.json");
14
+ workspace ??= existsSync(index)
15
+ ? declaredInIndex(index)
16
+ : declaredIn(join(import.meta.dirname, "..", "..", "..", ".."));
17
+ return workspace;
18
+ };
19
+ /** What a selection composes (see `composedWith`); refuses, naming each, what cannot be selected. */
20
+ export const composed = (selection) => composedWith(declared(), selection);
21
+ /** The full template: every foundation and feature that does not opt in, with each default, and what is added. */
22
+ export const full = (add) => fullWith(declared(), add);
23
+ /** The features that opt in, which the full template leaves out until added. */
24
+ export const optIns = () => optInsOf(declared());
25
+ /** The modules given, what they need to run, then `completed`, as `composed` reaches them but with no axis default. */
26
+ export const needed = (modules) => neededWith(declared(), modules);
@@ -0,0 +1,38 @@
1
+ /** What one package declares that composing reads. */
2
+ export interface Package {
3
+ readonly name: string;
4
+ readonly kind?: string;
5
+ /** Whether it can be composed: it exports `./module`. */
6
+ readonly module: boolean;
7
+ /** The packages it needs to run (`dependencies`, not `devDependencies`). */
8
+ readonly needs: readonly string[];
9
+ readonly optIn: boolean;
10
+ /** The axis owner it replaces or adapts to, and whether it is that axis's default. */
11
+ readonly replaces?: string;
12
+ readonly adapts?: string;
13
+ readonly default: boolean;
14
+ }
15
+ export interface Declared {
16
+ /** Each feature's wirings, by the feature's name. */
17
+ readonly wirings: ReadonlyMap<string, readonly string[]>;
18
+ readonly bridges: readonly {
19
+ readonly joins: readonly string[];
20
+ readonly bridge: string;
21
+ }[];
22
+ /** Every package, by name, in code point order of name. */
23
+ readonly packages: ReadonlyMap<string, Package>;
24
+ }
25
+ /**
26
+ * What the packages of the workspace rooted at `root` declare in their package.json, as the
27
+ * workspace definition lists them: a wiring names the feature it `wires`, a bridge the modules it
28
+ * `joins`, a non-empty list of names; any other `wires` or `joins` is refused. Each list is in
29
+ * code point order of name.
30
+ */
31
+ export declare function declaredIn(root: string): Declared;
32
+ /** The same, from the index a bundle carries: each member's manifest as the workspace wrote it. */
33
+ export declare function declaredInIndex(file: string): Declared;
34
+ /**
35
+ * The modules given, then the wirings and bridges declared for them, each once and in the order
36
+ * first named. What is brought in is completed in turn, until nothing more comes.
37
+ */
38
+ export declare function completedWith(declared: Declared, modules: readonly string[]): string[];
@@ -0,0 +1,75 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ const packageOf = (m) => ({
5
+ name: m.name,
6
+ ...(isName(m.kind) ? { kind: m.kind } : {}),
7
+ module: typeof m.exports === "object" && m.exports !== null && "./module" in m.exports,
8
+ needs: typeof m.dependencies === "object" && m.dependencies !== null
9
+ ? Object.keys(m.dependencies)
10
+ : [],
11
+ optIn: m.optIn === true,
12
+ ...(isName(m.replaces) ? { replaces: m.replaces } : {}),
13
+ ...(isName(m.adapts) ? { adapts: m.adapts } : {}),
14
+ default: m.default === true,
15
+ });
16
+ const isName = (value) => typeof value === "string" && value !== "";
17
+ const isNames = (value) => Array.isArray(value) && value.length > 0 && value.every(isName);
18
+ /**
19
+ * What the packages of the workspace rooted at `root` declare in their package.json, as the
20
+ * workspace definition lists them: a wiring names the feature it `wires`, a bridge the modules it
21
+ * `joins`, a non-empty list of names; any other `wires` or `joins` is refused. Each list is in
22
+ * code point order of name.
23
+ */
24
+ export function declaredIn(root) {
25
+ const listed = JSON.parse(execFileSync("pnpm", ["ls", "-r", "--json", "--depth", "-1"], { cwd: root, encoding: "utf8" }));
26
+ return declaredOf(listed.map(({ path }) => JSON.parse(readFileSync(join(path, "package.json"), "utf8"))));
27
+ }
28
+ /** The same, from the index a bundle carries: each member's manifest as the workspace wrote it. */
29
+ export function declaredInIndex(file) {
30
+ const index = JSON.parse(readFileSync(file, "utf8"));
31
+ return declaredOf(index.packages.map(({ manifest }) => manifest));
32
+ }
33
+ function declaredOf(manifests) {
34
+ const packages = [...manifests].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
35
+ // Refused, never left missing with no word why: a bridge joining nothing would come with all.
36
+ const misdeclared = (key, ok, shape) => {
37
+ const names = packages.filter((m) => m[key] !== undefined && !ok(m[key])).map((m) => m.name);
38
+ return names.length > 0 ? [`${names.join(", ")}: ${key} is not ${shape}`] : [];
39
+ };
40
+ const refusals = [
41
+ ...misdeclared("joins", isNames, "a non-empty list of module names"),
42
+ ...misdeclared("wires", isName, "a module name"),
43
+ ];
44
+ if (refusals.length > 0)
45
+ throw new Error(refusals.join("; "));
46
+ const wirings = new Map();
47
+ for (const { name, wires } of packages) {
48
+ if (isName(wires))
49
+ wirings.set(wires, [...(wirings.get(wires) ?? []), name]);
50
+ }
51
+ const bridges = packages.flatMap(({ name, joins }) => isNames(joins) ? [{ joins, bridge: name }] : []);
52
+ return { wirings, bridges, packages: new Map(packages.map((m) => [m.name, packageOf(m)])) };
53
+ }
54
+ /**
55
+ * The modules given, then the wirings and bridges declared for them, each once and in the order
56
+ * first named. What is brought in is completed in turn, until nothing more comes.
57
+ */
58
+ export function completedWith(declared, modules) {
59
+ const all = [...modules];
60
+ const add = (name) => {
61
+ if (!all.includes(name))
62
+ all.push(name);
63
+ };
64
+ for (let size = -1; size !== all.length;) {
65
+ size = all.length;
66
+ for (const name of all)
67
+ for (const wiring of declared.wirings.get(name) ?? [])
68
+ add(wiring);
69
+ for (const { joins, bridge } of declared.bridges) {
70
+ if (joins.every((m) => all.includes(m)))
71
+ add(bridge);
72
+ }
73
+ }
74
+ return all;
75
+ }
@@ -0,0 +1,12 @@
1
+ /** The kinds a package's manifest names, each the one word the product and its checks read. */
2
+ export declare const kinds: {
3
+ readonly common: "common";
4
+ readonly foundation: "foundation";
5
+ readonly capability: "capability";
6
+ readonly feature: "feature";
7
+ readonly adapter: "adapter";
8
+ readonly assembly: "assembly";
9
+ readonly wiring: "wiring";
10
+ readonly verification: "verification";
11
+ };
12
+ export type Kind = (typeof kinds)[keyof typeof kinds];
@@ -0,0 +1,11 @@
1
+ /** The kinds a package's manifest names, each the one word the product and its checks read. */
2
+ export const kinds = {
3
+ common: "common",
4
+ foundation: "foundation",
5
+ capability: "capability",
6
+ feature: "feature",
7
+ adapter: "adapter",
8
+ assembly: "assembly",
9
+ wiring: "wiring",
10
+ verification: "verification",
11
+ };
@@ -0,0 +1,54 @@
1
+ # create-app
2
+
3
+ ## Responsibilities
4
+ - Generates a new project: a minimal app that assembles the modules asked for through their `./module`, with the wirings and bridges `combinations` adds by default.
5
+ - Generates the full template: what `combinations` composes in full, with the features added, its configuration from the modules' fragments, an image and the operator's guide.
6
+ - Generates a pattern's deployment the same way, from what `combinations` composes of the pattern's selection and the operator's choice; its internal module `patterns` holds the patterns.
7
+ - Maps each fragment's keys to the environment and the local layer: the boundary that keeps module words out of the environment's.
8
+ - Adds one log sink to a listed app: `log-stdout`, unless the plan names another.
9
+ - Writes a start script, and what git leaves out (`node_modules/`, local configuration files, and for full and a pattern the env files and key files).
10
+ - The app reads the configuration files `APP_CONFIG` lists, comma-separated, layered in order; the generated configuration file when unset.
11
+
12
+ ## Not here
13
+ - What each module's configuration means, and its fragment (`config.example` beside its package.json): each module's.
14
+ - What the full template and a selection compose: `combinations`.
15
+
16
+ ## Offers
17
+ - `generate`, and the `create-app` command around it (also `run`, the command on given arguments, answering its exit status, for a package that runs it): packages listed make their app; none makes a pattern's, `--pattern` naming it (default `full`), `--add` naming features to add, `--axis <owner>=<module>` an axis's choice and `--<group>` a group's features, comma-separated (not for full).
18
+ - `patterns()`: each pattern's name, use, conformance areas and what conformance adds for its run.
19
+ - The workspace's configuration reference: each section's keys from its schema (type, bounds, default, whether required, description) and its fragment (example, variable), written by `pnpm --filter @mod/create-app run configuration`.
20
+ - The configuration reference's test fails when the committed file differs, or when a key has no description outside the sections listed as described later.
21
+ - The audit event reference beside it: each module's events as its `./audit-events` declares them through `audit`, written by the same command and held to the committed file the same way.
22
+ - A kind two modules declare must be declared alike in the audit event reference.
23
+ - `trialSettings(target, { redisUrl, port?, deployment?, leave?, allow?, plainLoopback? })`: for a generated app, by the modules its manifest depends on, an environment and a local layer that boot it for a test or a conformance run.
24
+ - Its hosts are under `.invalid` and its keys made fresh, never a deployment's values.
25
+ - The sections in `leave` get neither a variable nor a block.
26
+ - Hosts in `allow` and `plainLoopback` join the trial's one outbound block.
27
+ - `mfa` is optional where composed.
28
+ - `webauthn`'s relying party is the trial's public origin.
29
+ - For full and a pattern: the project's manifest and app, the configuration file, the local layer's and the environment's examples, a Dockerfile, a `.dockerignore` and a README; a pattern's README opens with its use and carries its card.
30
+
31
+ ## Invariants
32
+ - A target that holds anything is refused, never overwritten; a missing or empty one is taken.
33
+ - A module, sink, added feature or axis choice not named as an npm package is refused, before anything is written; so is a name the workspace lacks, one that is not a feature, a pattern or group not known, and axes or groups for full.
34
+ - With a workspace, each dependency links to the workspace's package; a module the workspace does not hold is refused. Built into a bundle and given none, it reads the bundle's index: the app depends on each public bundle at the index's version, imports public entries, and takes the fragments the index holds; a module it does not hold is refused.
35
+ - A listed app's configuration file holds `kernel`'s section only, and no secret values.
36
+ - A pattern whose store is kept in memory says in its README that the deployment runs as one instance.
37
+ - The full template's and a pattern's configuration file reads the collected fragments' scalar keys from env only, holding no values; each variable is the section and key path joined by `_`, upper-cased, `-` as `_`.
38
+ - Two keys reading one variable refuse generation, naming both.
39
+ - Neither example holds a live value line: the local layer's holds each fragment list with its placeholders and each value spanning sections (`audit.receivers`), the environment's each variable, all as comments; a copy sets nothing, and boot refuses each key still needed. A value spanning sections never goes to env.
40
+ - Git leaves out every env file but `.env.example`, the local layer, `*.pem` and `*.key`; the image's build context leaves out those, `.env.example` and `.git`.
41
+ - The image pins Node by version and digest and corepack by version, installs the locked production dependencies in a stage of their own, runs node under `tini` as a user other than root, and checks liveness (`/_healthcheck`, after a start period).
42
+ - The app exits 78 on a refused boot, writing each refusal on standard error.
43
+ - SIGTERM or SIGINT stops the app, draining; one that comes while it starts stops it once started.
44
+
45
+ ## Data
46
+ - Writes the target only; reads the workspace's package list, and the fragments of the modules the full template composes.
47
+
48
+ ## Depends on
49
+ - `kernel`, `combinations` (the modules it assembles become dependencies of the output); the HOCON library, to read the fragments.
50
+
51
+ ## Vocabulary
52
+ - output: a project created from the template.
53
+ - fragment: a module's example of its section, placeholders only; a secret's is `REPLACE-…` text its section refuses.
54
+ - local layer: the operator's configuration file layered first, for lists and values the environment does not carry.