@composable-os/product 0.0.0-stage → 0.1.0-beta.7
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 +109 -0
- package/dist/index.d.ts +240 -0
- package/dist/index.js +275 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +57 -0
- package/dist/packs.d.ts +23 -0
- package/dist/packs.js +88 -0
- package/package.json +31 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
> This licence covers the repository except the directories listed in NOTICE. In particular, the
|
|
4
|
+
> assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
|
|
5
|
+
> licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
|
|
6
|
+
|
|
7
|
+
## Abbreviation
|
|
8
|
+
|
|
9
|
+
FSL-1.1-ALv2
|
|
10
|
+
|
|
11
|
+
## Notice
|
|
12
|
+
|
|
13
|
+
Copyright 2026 Tim O'Connell
|
|
14
|
+
|
|
15
|
+
## Terms and Conditions
|
|
16
|
+
|
|
17
|
+
### Licensor ("We")
|
|
18
|
+
|
|
19
|
+
The party offering the Software under these Terms and Conditions.
|
|
20
|
+
|
|
21
|
+
### The Software
|
|
22
|
+
|
|
23
|
+
The "Software" is each version of the software that we make available under
|
|
24
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
25
|
+
Conditions with the Software.
|
|
26
|
+
|
|
27
|
+
### License Grant
|
|
28
|
+
|
|
29
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
30
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
31
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
32
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
33
|
+
|
|
34
|
+
### Permitted Purpose
|
|
35
|
+
|
|
36
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
37
|
+
means making the Software available to others in a commercial product or
|
|
38
|
+
service that:
|
|
39
|
+
|
|
40
|
+
1. substitutes for the Software;
|
|
41
|
+
|
|
42
|
+
2. substitutes for any other product or service we offer using the Software
|
|
43
|
+
that exists as of the date we make the Software available; or
|
|
44
|
+
|
|
45
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
46
|
+
|
|
47
|
+
Permitted Purposes specifically include using the Software:
|
|
48
|
+
|
|
49
|
+
1. for your internal use and access;
|
|
50
|
+
|
|
51
|
+
2. for non-commercial education;
|
|
52
|
+
|
|
53
|
+
3. for non-commercial research; and
|
|
54
|
+
|
|
55
|
+
4. in connection with professional services that you provide to a licensee
|
|
56
|
+
using the Software in accordance with these Terms and Conditions.
|
|
57
|
+
|
|
58
|
+
### Patents
|
|
59
|
+
|
|
60
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
61
|
+
patents, the license grant above includes a license under our patents. If you
|
|
62
|
+
make a claim against any party that the Software infringes or contributes to
|
|
63
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
64
|
+
immediately.
|
|
65
|
+
|
|
66
|
+
### Redistribution
|
|
67
|
+
|
|
68
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
69
|
+
the Software.
|
|
70
|
+
|
|
71
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
72
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
73
|
+
remove any copyright notices provided in or with the Software.
|
|
74
|
+
|
|
75
|
+
### Disclaimer
|
|
76
|
+
|
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
78
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
79
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
80
|
+
|
|
81
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
82
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
83
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
84
|
+
|
|
85
|
+
### Trademarks
|
|
86
|
+
|
|
87
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
88
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
89
|
+
trademarks, trade names, service marks or product names.
|
|
90
|
+
|
|
91
|
+
## Grant of Future License
|
|
92
|
+
|
|
93
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
94
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
95
|
+
the date we make the Software available. On or after that date, you may use the
|
|
96
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
97
|
+
will apply:
|
|
98
|
+
|
|
99
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
100
|
+
this file except in compliance with the License.
|
|
101
|
+
|
|
102
|
+
You may obtain a copy of the License at
|
|
103
|
+
|
|
104
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
+
|
|
106
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
107
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
108
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
109
|
+
specific language governing permissions and limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
export interface ProductDefinition {
|
|
2
|
+
/** Names the product in release manifests, release files and `--product`. Lowercase. */
|
|
3
|
+
id: string;
|
|
4
|
+
/** The product's name as people read it. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** What a deployment of this product is called in a Cloudflare account. */
|
|
7
|
+
names: {
|
|
8
|
+
/** The app Worker (UI, `/mcp`, the operations registry). */
|
|
9
|
+
app: string;
|
|
10
|
+
/** The runner Worker (extension code, automations, Workflows). */
|
|
11
|
+
runner: string;
|
|
12
|
+
/** Gatekeeper Workers are this plus the gatekeeper's short name. */
|
|
13
|
+
gatekeeperPrefix: string;
|
|
14
|
+
/** The D1 database. */
|
|
15
|
+
database: string;
|
|
16
|
+
/** Buckets, queues, KV namespaces, Vectorize indexes and Workflows are this plus their name. */
|
|
17
|
+
resourcePrefix: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The packs the product includes, by id (`packs/<id>`, stage 24). A pack is a shipped extension
|
|
21
|
+
* plus its client hooks and blocks; only the packs listed here are in the product's release and
|
|
22
|
+
* installed in its deployments. Empty: a host with base records only.
|
|
23
|
+
*/
|
|
24
|
+
packs: string[];
|
|
25
|
+
/** GitHub `owner/repo` its releases are published from and updates are read from. */
|
|
26
|
+
updateRepository: string;
|
|
27
|
+
/** Where a hosted plan is changed. Shown when a plan's limit is reached. */
|
|
28
|
+
billingUrl: string;
|
|
29
|
+
/** What the UI, emails and model instructions call the product. */
|
|
30
|
+
strings: {
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Checks a definition and returns it. Throws on the first name a Cloudflare account would refuse. */
|
|
35
|
+
export declare function defineProduct(definition: ProductDefinition): ProductDefinition;
|
|
36
|
+
/**
|
|
37
|
+
* A client repo's product (stage 24, ADR 0422): `product.ts` at the root of a company's own
|
|
38
|
+
* repository. It says which platform release the host is deployed from, which of that release's
|
|
39
|
+
* packs are on, and where the company's own apps are. It is the one place a client product's
|
|
40
|
+
* names are written (AGENTS.md).
|
|
41
|
+
*
|
|
42
|
+
* The host is named for it at its first install (issue #155): its Workers and resources take the
|
|
43
|
+
* names `clientNames` gives (`<id>-app`, `<id>-runner`, `<id>-gatekeeper-…`, the `<id>` database,
|
|
44
|
+
* `<id>-…` resources, unless `names` overrides them), applied as deploy-time configuration (the
|
|
45
|
+
* deployment state's name maps, ADR 0193), so the verified release is deployed unchanged; and
|
|
46
|
+
* every surface that shows the product's name shows `label` (COS_PRODUCT_LABEL). A deployment that
|
|
47
|
+
* exists keeps its names: nothing deployed is renamed.
|
|
48
|
+
*/
|
|
49
|
+
export interface ClientProductDefinition {
|
|
50
|
+
/** The company's product, lowercase: names its Workers (`<id>-web`) and the repo. */
|
|
51
|
+
id: string;
|
|
52
|
+
/** The product's name as people read it. */
|
|
53
|
+
label: string;
|
|
54
|
+
platform: {
|
|
55
|
+
/** The platform version the repo is on: the release deployed, the client kit copied from. */
|
|
56
|
+
version: string;
|
|
57
|
+
/** The platform product whose release is deployed as the host (`crm`). */
|
|
58
|
+
release: string;
|
|
59
|
+
/** GitHub `owner/repo` the platform's releases come from. */
|
|
60
|
+
repository: string;
|
|
61
|
+
};
|
|
62
|
+
/** The release's packs that are on (`deals`, `leads`, …). Empty: base records only. */
|
|
63
|
+
packs: string[];
|
|
64
|
+
/**
|
|
65
|
+
* The web app, if the repo has one: its folder, its Worker's name, its hostname (else
|
|
66
|
+
* workers.dev) and where its generated client is (default `src/client`).
|
|
67
|
+
*/
|
|
68
|
+
web?: {
|
|
69
|
+
dir: string;
|
|
70
|
+
worker: string;
|
|
71
|
+
hostname?: string;
|
|
72
|
+
clientDir?: string;
|
|
73
|
+
/**
|
|
74
|
+
* "cos" (the default): `cos deploy` builds and uploads it. "own": it deploys itself, as an
|
|
75
|
+
* adopted site does today, and `cos deploy` only checks it; its wrangler config binds HOST.
|
|
76
|
+
*/
|
|
77
|
+
deploy?: "cos" | "own";
|
|
78
|
+
/**
|
|
79
|
+
* The web app's routes that reach the host, for the edge rate-limit rule `cos` prints (so it
|
|
80
|
+
* names only those): the sign-in route (default `/auth/`) and the operation route
|
|
81
|
+
* (`operationRoute`, default `/api/v1/op/`).
|
|
82
|
+
*/
|
|
83
|
+
routes?: {
|
|
84
|
+
signIn?: string;
|
|
85
|
+
operations?: string;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The mobile app, if the repo has one: its folder, where its generated client is, and the pack
|
|
90
|
+
* roles (ADR 0436) its staff may sign in with: `cos client generate` writes a client for each
|
|
91
|
+
* (`roles/<pack>.<role>.ts`) with only that role's operations, never the whole staff client
|
|
92
|
+
* (ADR 0451). The web app has none: its binding never serves staff (ADR 0421).
|
|
93
|
+
*/
|
|
94
|
+
mobile?: {
|
|
95
|
+
dir: string;
|
|
96
|
+
clientDir?: string;
|
|
97
|
+
roles?: string[];
|
|
98
|
+
/** The app's URL scheme (app.json `expo.scheme`), default the product's id. */
|
|
99
|
+
scheme?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The host's names, when they are not the ones derived from `id` (`clientNames`). With
|
|
103
|
+
* environments, these are the live environment's (the one that keeps `<id>-app`).
|
|
104
|
+
*/
|
|
105
|
+
names?: Partial<ProductDefinition["names"]>;
|
|
106
|
+
/**
|
|
107
|
+
* The deployments of this product, by name (ADR 0450): at least one, usually `staging` and
|
|
108
|
+
* `live`. Each is its own host (its own Workers, database, deployment state and secrets) with
|
|
109
|
+
* its own addresses, deployed into one Cloudflare account side by side by
|
|
110
|
+
* `cos deploy --env <name>`. Absent: one deployment, named as without environments.
|
|
111
|
+
*/
|
|
112
|
+
environments?: Record<string, ClientEnvironment>;
|
|
113
|
+
/** Gatekeepers every environment installs, and their settings (ADR 0452). */
|
|
114
|
+
gatekeepers?: GatekeeperSettings;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* One environment of a client product (ADR 0450). Its names derive from the product's id and the
|
|
118
|
+
* environment's name (`<id>-staging-app`, the `<id>-staging` database, `<id>-staging-…`
|
|
119
|
+
* resources), except `live`, which keeps the names a product without environments has
|
|
120
|
+
* (`<id>-app`), so nothing already deployed is renamed. Every name can be overridden.
|
|
121
|
+
*/
|
|
122
|
+
export interface ClientEnvironment {
|
|
123
|
+
/**
|
|
124
|
+
* Whether real customers and real money use it. Default true; an environment marked false
|
|
125
|
+
* (staging) may use test settings a live one may not, such as the fake payment provider.
|
|
126
|
+
* The environment named `live` is always live.
|
|
127
|
+
*/
|
|
128
|
+
live?: boolean;
|
|
129
|
+
/** The host's own hostname: the staff admin's address. Absent: workers.dev. */
|
|
130
|
+
hostname?: string;
|
|
131
|
+
/** Gatekeepers installed here and their settings, over the product's own (ADR 0452). */
|
|
132
|
+
gatekeepers?: GatekeeperSettings;
|
|
133
|
+
/** The web app in this environment: its hostname (else workers.dev) and its Worker's name. */
|
|
134
|
+
web?: {
|
|
135
|
+
hostname?: string;
|
|
136
|
+
worker?: string;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* The mobile app's build for this environment: its URL scheme, when it differs from the
|
|
140
|
+
* product's (a staging build of the app installed beside the live one), for staff sign-in's
|
|
141
|
+
* redirect (`<scheme>://staff-sign-in`, NATIVE_REDIRECT_URIS on the host).
|
|
142
|
+
*/
|
|
143
|
+
mobile?: {
|
|
144
|
+
scheme?: string;
|
|
145
|
+
};
|
|
146
|
+
/** The host's names here, when they are not the derived ones. */
|
|
147
|
+
names?: Partial<ProductDefinition["names"]>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The gatekeepers a client host installs and their settings (ADR 0452), by the gatekeeper's
|
|
151
|
+
* short name. Each takes only the settings that gatekeeper declares in its release (`cos deploy`
|
|
152
|
+
* refuses any other); secrets are never here: a person sets them as Worker secrets, and
|
|
153
|
+
* `cos deploy` says which are missing. `{}` installs a gatekeeper with its defaults.
|
|
154
|
+
*/
|
|
155
|
+
export interface GatekeeperSettings {
|
|
156
|
+
/** Outbound email through Cloudflare Email Service (packages/gatekeeper-email-send). */
|
|
157
|
+
"email-send"?: {
|
|
158
|
+
/** Domains mail may be sent from, comma separated (`gym.example`). */
|
|
159
|
+
ALLOWED_SENDER_DOMAINS?: string;
|
|
160
|
+
/** The org's own domains, comma separated: mail to them is internal. */
|
|
161
|
+
INTERNAL_DOMAINS?: string;
|
|
162
|
+
/** The `send_email` binding's limits (Cloudflare Email Service). */
|
|
163
|
+
sendEmail?: {
|
|
164
|
+
allowedSenderAddresses?: string[];
|
|
165
|
+
destinationAddress?: string;
|
|
166
|
+
allowedDestinationAddresses?: string[];
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
/** Payments (packages/gatekeeper-payments). Its webhook address, BASE_URL, is derived. */
|
|
170
|
+
payments?: {
|
|
171
|
+
/** A Stripe Connect account to act for (`acct_…`), if any. */
|
|
172
|
+
STRIPE_ACCOUNT?: string;
|
|
173
|
+
/** The fake provider instead of Stripe: only in an environment marked `live: false`. */
|
|
174
|
+
PAYMENTS_FAKE_PROVIDER?: boolean;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/** Whether an environment of `product` (or the product without environments) is live. */
|
|
178
|
+
export declare function isLiveEnvironment(product: ClientProductDefinition, environment?: string): boolean;
|
|
179
|
+
/** The gatekeepers and settings a deploy of `environment` applies: the product's, then its own. */
|
|
180
|
+
export declare function gatekeeperSettings(product: ClientProductDefinition, environment?: string): GatekeeperSettings;
|
|
181
|
+
/** The environment that keeps a product's undecorated names (`<id>-app`). */
|
|
182
|
+
export declare const LIVE_ENVIRONMENT = "live";
|
|
183
|
+
/** The names of a product's environments, sorted; empty when it declares none. */
|
|
184
|
+
export declare function environmentNames(product: ClientProductDefinition): string[];
|
|
185
|
+
/**
|
|
186
|
+
* The names a client product's host is deployed with: derived from its id (and, for an
|
|
187
|
+
* environment other than `live`, the environment's name), or as it says.
|
|
188
|
+
*/
|
|
189
|
+
export declare function clientNames(product: ClientProductDefinition, environment?: string): ProductDefinition["names"];
|
|
190
|
+
/**
|
|
191
|
+
* The web app's Worker name and hostname in an environment: as the environment says, else the
|
|
192
|
+
* product's `web` for `live` (or no environment), else `<web.worker>-<environment>`.
|
|
193
|
+
*/
|
|
194
|
+
export declare function clientWeb(product: ClientProductDefinition, environment?: string): {
|
|
195
|
+
worker: string;
|
|
196
|
+
hostname?: string;
|
|
197
|
+
} | null;
|
|
198
|
+
/**
|
|
199
|
+
* The deployed name of each of a release's Worker and resource names, for a client product: the
|
|
200
|
+
* release's product's names replaced by the client's (`crm-app` → `gym-app`, the `crm` database →
|
|
201
|
+
* `gym`). Only names that differ are listed. What the deployment state's `workerNames` and
|
|
202
|
+
* `resourceNames` hold (ADR 0193).
|
|
203
|
+
*/
|
|
204
|
+
export declare function clientNameMaps(release: ProductDefinition, client: ProductDefinition["names"], manifest: {
|
|
205
|
+
workers: {
|
|
206
|
+
name: string;
|
|
207
|
+
}[];
|
|
208
|
+
resources: {
|
|
209
|
+
name: string;
|
|
210
|
+
}[];
|
|
211
|
+
}): {
|
|
212
|
+
workers: Record<string, string>;
|
|
213
|
+
resources: Record<string, string>;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* The deploy-time variable that holds a client product's label (`cos deploy` sets it on the app
|
|
217
|
+
* and the runner). Every surface that shows the product's name reads it through `productName`.
|
|
218
|
+
*/
|
|
219
|
+
export declare const PRODUCT_LABEL_VAR = "COS_PRODUCT_LABEL";
|
|
220
|
+
/** Called once per isolate by a Worker's entry, with its COS_PRODUCT_LABEL (unset: none). */
|
|
221
|
+
export declare function setProductLabel(value: string | null | undefined): void;
|
|
222
|
+
/** The product's name as people read it: the deployment's label when one is set, else the build's. */
|
|
223
|
+
export declare function productName(product: Pick<ProductDefinition, "strings">): string;
|
|
224
|
+
/** Checks a client repo's product and returns it. Throws on the first problem. */
|
|
225
|
+
export declare function defineClientProduct(definition: ClientProductDefinition): ClientProductDefinition;
|
|
226
|
+
/**
|
|
227
|
+
* The prefix packages use for Workers and resources in their own configuration (wrangler.jsonc,
|
|
228
|
+
* deploy-inputs.json) and in local development: `cos-app`, the database `cos`. It belongs to the
|
|
229
|
+
* platform. A release replaces it with the product's names (`deployedName`).
|
|
230
|
+
*/
|
|
231
|
+
export declare const LOCAL_PREFIX = "cos";
|
|
232
|
+
/**
|
|
233
|
+
* The name a Worker or resource has in a deployment of `product`, from the name a package gives
|
|
234
|
+
* it. Names that do not start with the platform's prefix are left alone.
|
|
235
|
+
*/
|
|
236
|
+
export declare function deployedName(product: ProductDefinition, localName: string): string;
|
|
237
|
+
/** `deployedName` over a comma-separated list of names (a var that lists Workers). */
|
|
238
|
+
export declare function deployedNameList(product: ProductDefinition, list: string): string;
|
|
239
|
+
/** What a product's release files start with: `composable-os-<product>-<version>.tar.gz`. */
|
|
240
|
+
export declare function releaseFilePrefix(productId: string): string;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
// A product (ADR 0400): a named composition on the platform. Its definition holds names only, and
|
|
2
|
+
// is the one place a name that depends on the product is written. Packages never write one: the
|
|
3
|
+
// release build, the deploy engine, the installer, the self-updater and the UI read them from the
|
|
4
|
+
// definition (products/<id>/product.ts).
|
|
5
|
+
const NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
6
|
+
const PREFIX = /^[a-z0-9]+(-[a-z0-9]+)*-$/;
|
|
7
|
+
/** Checks a definition and returns it. Throws on the first name a Cloudflare account would refuse. */
|
|
8
|
+
export function defineProduct(definition) {
|
|
9
|
+
const fail = (what) => {
|
|
10
|
+
throw new Error(`product ${JSON.stringify(definition.id)}: ${what}`);
|
|
11
|
+
};
|
|
12
|
+
if (!NAME.test(definition.id))
|
|
13
|
+
fail("id must be lowercase letters, digits and single hyphens");
|
|
14
|
+
if (!definition.label.trim())
|
|
15
|
+
fail("label is empty");
|
|
16
|
+
if (!definition.strings.name.trim())
|
|
17
|
+
fail("strings.name is empty");
|
|
18
|
+
const { app, runner, gatekeeperPrefix, database, resourcePrefix } = definition.names;
|
|
19
|
+
for (const [key, value] of Object.entries({ app, runner, database })) {
|
|
20
|
+
if (!NAME.test(value))
|
|
21
|
+
fail(`names.${key} must be lowercase letters, digits and hyphens`);
|
|
22
|
+
}
|
|
23
|
+
for (const [key, value] of Object.entries({ gatekeeperPrefix, resourcePrefix })) {
|
|
24
|
+
if (!PREFIX.test(value))
|
|
25
|
+
fail(`names.${key} must end with a hyphen`);
|
|
26
|
+
}
|
|
27
|
+
if (app === runner)
|
|
28
|
+
fail("names.app and names.runner are the same");
|
|
29
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(definition.updateRepository)) {
|
|
30
|
+
fail("updateRepository must be owner/repo");
|
|
31
|
+
}
|
|
32
|
+
if (!/^https:\/\//.test(definition.billingUrl))
|
|
33
|
+
fail("billingUrl must be an https:// URL");
|
|
34
|
+
return definition;
|
|
35
|
+
}
|
|
36
|
+
/** Whether an environment of `product` (or the product without environments) is live. */
|
|
37
|
+
export function isLiveEnvironment(product, environment) {
|
|
38
|
+
if (environment === undefined || environment === LIVE_ENVIRONMENT)
|
|
39
|
+
return true;
|
|
40
|
+
return product.environments?.[environment]?.live !== false;
|
|
41
|
+
}
|
|
42
|
+
/** The gatekeepers and settings a deploy of `environment` applies: the product's, then its own. */
|
|
43
|
+
export function gatekeeperSettings(product, environment) {
|
|
44
|
+
const base = product.gatekeepers ?? {};
|
|
45
|
+
const own = (environment ? product.environments?.[environment]?.gatekeepers : undefined) ?? {};
|
|
46
|
+
const out = {};
|
|
47
|
+
for (const name of new Set([...Object.keys(base), ...Object.keys(own)])) {
|
|
48
|
+
out[name] = {
|
|
49
|
+
...base[name],
|
|
50
|
+
...own[name],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/** The environment that keeps a product's undecorated names (`<id>-app`). */
|
|
56
|
+
export const LIVE_ENVIRONMENT = "live";
|
|
57
|
+
/** The names of a product's environments, sorted; empty when it declares none. */
|
|
58
|
+
export function environmentNames(product) {
|
|
59
|
+
return Object.keys(product.environments ?? {}).sort();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The names a client product's host is deployed with: derived from its id (and, for an
|
|
63
|
+
* environment other than `live`, the environment's name), or as it says.
|
|
64
|
+
*/
|
|
65
|
+
export function clientNames(product, environment) {
|
|
66
|
+
if (environment === undefined || environment === LIVE_ENVIRONMENT) {
|
|
67
|
+
return {
|
|
68
|
+
app: `${product.id}-app`,
|
|
69
|
+
runner: `${product.id}-runner`,
|
|
70
|
+
gatekeeperPrefix: `${product.id}-gatekeeper-`,
|
|
71
|
+
database: product.id,
|
|
72
|
+
resourcePrefix: `${product.id}-`,
|
|
73
|
+
...product.names,
|
|
74
|
+
...(environment ? product.environments?.[environment]?.names : {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const base = `${product.id}-${environment}`;
|
|
78
|
+
return {
|
|
79
|
+
app: `${base}-app`,
|
|
80
|
+
runner: `${base}-runner`,
|
|
81
|
+
gatekeeperPrefix: `${base}-gatekeeper-`,
|
|
82
|
+
database: base,
|
|
83
|
+
resourcePrefix: `${base}-`,
|
|
84
|
+
...product.environments?.[environment]?.names,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The web app's Worker name and hostname in an environment: as the environment says, else the
|
|
89
|
+
* product's `web` for `live` (or no environment), else `<web.worker>-<environment>`.
|
|
90
|
+
*/
|
|
91
|
+
export function clientWeb(product, environment) {
|
|
92
|
+
if (!product.web)
|
|
93
|
+
return null;
|
|
94
|
+
const env = environment ? product.environments?.[environment] : undefined;
|
|
95
|
+
const live = environment === undefined || environment === LIVE_ENVIRONMENT;
|
|
96
|
+
const worker = env?.web?.worker ?? (live ? product.web.worker : `${product.web.worker}-${environment}`);
|
|
97
|
+
const hostname = env?.web?.hostname ?? (live ? product.web.hostname : undefined);
|
|
98
|
+
return { worker, ...(hostname ? { hostname } : {}) };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The deployed name of each of a release's Worker and resource names, for a client product: the
|
|
102
|
+
* release's product's names replaced by the client's (`crm-app` → `gym-app`, the `crm` database →
|
|
103
|
+
* `gym`). Only names that differ are listed. What the deployment state's `workerNames` and
|
|
104
|
+
* `resourceNames` hold (ADR 0193).
|
|
105
|
+
*/
|
|
106
|
+
export function clientNameMaps(release, client, manifest) {
|
|
107
|
+
const rename = (name) => {
|
|
108
|
+
const r = release.names;
|
|
109
|
+
if (name === r.app)
|
|
110
|
+
return client.app;
|
|
111
|
+
if (name === r.runner)
|
|
112
|
+
return client.runner;
|
|
113
|
+
if (name === r.database)
|
|
114
|
+
return client.database;
|
|
115
|
+
if (name.startsWith(r.gatekeeperPrefix)) {
|
|
116
|
+
return `${client.gatekeeperPrefix}${name.slice(r.gatekeeperPrefix.length)}`;
|
|
117
|
+
}
|
|
118
|
+
if (name.startsWith(r.resourcePrefix)) {
|
|
119
|
+
return `${client.resourcePrefix}${name.slice(r.resourcePrefix.length)}`;
|
|
120
|
+
}
|
|
121
|
+
return name;
|
|
122
|
+
};
|
|
123
|
+
const map = (names) => Object.fromEntries(names.map((name) => [name, rename(name)]).filter(([from, to]) => from !== to));
|
|
124
|
+
return {
|
|
125
|
+
workers: map(manifest.workers.map((w) => w.name)),
|
|
126
|
+
resources: map(manifest.resources.map((r) => r.name)),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The deploy-time variable that holds a client product's label (`cos deploy` sets it on the app
|
|
131
|
+
* and the runner). Every surface that shows the product's name reads it through `productName`.
|
|
132
|
+
*/
|
|
133
|
+
export const PRODUCT_LABEL_VAR = "COS_PRODUCT_LABEL";
|
|
134
|
+
let deployedLabel = null;
|
|
135
|
+
/** Called once per isolate by a Worker's entry, with its COS_PRODUCT_LABEL (unset: none). */
|
|
136
|
+
export function setProductLabel(value) {
|
|
137
|
+
deployedLabel = typeof value === "string" && value.trim() ? value.trim() : null;
|
|
138
|
+
}
|
|
139
|
+
/** The product's name as people read it: the deployment's label when one is set, else the build's. */
|
|
140
|
+
export function productName(product) {
|
|
141
|
+
return deployedLabel ?? product.strings.name;
|
|
142
|
+
}
|
|
143
|
+
const VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
144
|
+
/** Checks a client repo's product and returns it. Throws on the first problem. */
|
|
145
|
+
export function defineClientProduct(definition) {
|
|
146
|
+
const fail = (what) => {
|
|
147
|
+
throw new Error(`product ${JSON.stringify(definition.id)}: ${what}`);
|
|
148
|
+
};
|
|
149
|
+
if (!NAME.test(definition.id))
|
|
150
|
+
fail("id must be lowercase letters, digits and single hyphens");
|
|
151
|
+
if (!definition.label.trim())
|
|
152
|
+
fail("label is empty");
|
|
153
|
+
if (!VERSION.test(definition.platform.version))
|
|
154
|
+
fail("platform.version must be x.y.z");
|
|
155
|
+
if (!NAME.test(definition.platform.release))
|
|
156
|
+
fail("platform.release must be a product id");
|
|
157
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(definition.platform.repository)) {
|
|
158
|
+
fail("platform.repository must be owner/repo");
|
|
159
|
+
}
|
|
160
|
+
for (const pack of definition.packs)
|
|
161
|
+
if (!NAME.test(pack))
|
|
162
|
+
fail(`pack ${pack} is not an id`);
|
|
163
|
+
if (new Set(definition.packs).size !== definition.packs.length)
|
|
164
|
+
fail("a pack is listed twice");
|
|
165
|
+
if (definition.web && !NAME.test(definition.web.worker))
|
|
166
|
+
fail("web.worker must be a Worker name");
|
|
167
|
+
for (const role of definition.mobile?.roles ?? []) {
|
|
168
|
+
const [pack, local] = role.split(".");
|
|
169
|
+
if (!pack || !local || role.split(".").length !== 2) {
|
|
170
|
+
fail(`mobile.roles: ${role} is not <pack>.<role>`);
|
|
171
|
+
}
|
|
172
|
+
if (!definition.packs.includes(pack)) {
|
|
173
|
+
fail(`mobile.roles: ${role} is a role of ${pack}, which packs does not list`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const names = clientNames(definition);
|
|
177
|
+
for (const key of ["app", "runner", "database"]) {
|
|
178
|
+
if (!NAME.test(names[key]))
|
|
179
|
+
fail(`names.${key} must be lowercase letters, digits and hyphens`);
|
|
180
|
+
}
|
|
181
|
+
for (const key of ["gatekeeperPrefix", "resourcePrefix"]) {
|
|
182
|
+
if (!PREFIX.test(names[key]))
|
|
183
|
+
fail(`names.${key} must end with a hyphen`);
|
|
184
|
+
}
|
|
185
|
+
if (names.app === names.runner)
|
|
186
|
+
fail("names.app and names.runner are the same");
|
|
187
|
+
if (definition.web && [names.app, names.runner].includes(definition.web.worker)) {
|
|
188
|
+
fail("web.worker is one of the host's Workers");
|
|
189
|
+
}
|
|
190
|
+
if (definition.environments?.[LIVE_ENVIRONMENT]?.live === false) {
|
|
191
|
+
fail("the live environment cannot be marked live: false");
|
|
192
|
+
}
|
|
193
|
+
const deployments = environmentNames(definition);
|
|
194
|
+
for (const env of deployments.length ? deployments : [undefined]) {
|
|
195
|
+
if (gatekeeperSettings(definition, env).payments?.PAYMENTS_FAKE_PROVIDER === true &&
|
|
196
|
+
isLiveEnvironment(definition, env)) {
|
|
197
|
+
fail(`${env ? `environment ${env}` : "the product"} is live and turns on the fake payment provider: only an environment marked live: false may`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (definition.environments) {
|
|
201
|
+
const envs = environmentNames(definition);
|
|
202
|
+
if (!envs.length)
|
|
203
|
+
fail("environments is empty: leave it out for one deployment");
|
|
204
|
+
const taken = new Map();
|
|
205
|
+
for (const env of envs) {
|
|
206
|
+
if (!NAME.test(env))
|
|
207
|
+
fail(`environment ${env} must be lowercase letters, digits and hyphens`);
|
|
208
|
+
const n = clientNames(definition, env);
|
|
209
|
+
for (const key of ["app", "runner", "database"]) {
|
|
210
|
+
if (!NAME.test(n[key]))
|
|
211
|
+
fail(`environments.${env}.names.${key} is not a name`);
|
|
212
|
+
}
|
|
213
|
+
for (const key of ["gatekeeperPrefix", "resourcePrefix"]) {
|
|
214
|
+
if (!PREFIX.test(n[key]))
|
|
215
|
+
fail(`environments.${env}.names.${key} must end with a hyphen`);
|
|
216
|
+
}
|
|
217
|
+
const web = clientWeb(definition, env);
|
|
218
|
+
if (web && !NAME.test(web.worker))
|
|
219
|
+
fail(`environments.${env}.web.worker is not a Worker name`);
|
|
220
|
+
// Two environments in one account never share a Worker, a database or a prefix.
|
|
221
|
+
for (const name of [
|
|
222
|
+
n.app,
|
|
223
|
+
n.runner,
|
|
224
|
+
n.database,
|
|
225
|
+
n.resourcePrefix,
|
|
226
|
+
n.gatekeeperPrefix,
|
|
227
|
+
web?.worker,
|
|
228
|
+
]) {
|
|
229
|
+
if (!name)
|
|
230
|
+
continue;
|
|
231
|
+
const other = taken.get(name);
|
|
232
|
+
if (other)
|
|
233
|
+
fail(`environments ${other} and ${env} both use the name ${name}`);
|
|
234
|
+
taken.set(name, env);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return definition;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The prefix packages use for Workers and resources in their own configuration (wrangler.jsonc,
|
|
242
|
+
* deploy-inputs.json) and in local development: `cos-app`, the database `cos`. It belongs to the
|
|
243
|
+
* platform. A release replaces it with the product's names (`deployedName`).
|
|
244
|
+
*/
|
|
245
|
+
export const LOCAL_PREFIX = "cos";
|
|
246
|
+
/**
|
|
247
|
+
* The name a Worker or resource has in a deployment of `product`, from the name a package gives
|
|
248
|
+
* it. Names that do not start with the platform's prefix are left alone.
|
|
249
|
+
*/
|
|
250
|
+
export function deployedName(product, localName) {
|
|
251
|
+
if (localName === LOCAL_PREFIX)
|
|
252
|
+
return product.names.database;
|
|
253
|
+
if (!localName.startsWith(`${LOCAL_PREFIX}-`))
|
|
254
|
+
return localName;
|
|
255
|
+
const rest = localName.slice(LOCAL_PREFIX.length + 1);
|
|
256
|
+
if (rest === "app")
|
|
257
|
+
return product.names.app;
|
|
258
|
+
if (rest === "runner")
|
|
259
|
+
return product.names.runner;
|
|
260
|
+
if (rest.startsWith("gatekeeper-")) {
|
|
261
|
+
return `${product.names.gatekeeperPrefix}${rest.slice("gatekeeper-".length)}`;
|
|
262
|
+
}
|
|
263
|
+
return `${product.names.resourcePrefix}${rest}`;
|
|
264
|
+
}
|
|
265
|
+
/** `deployedName` over a comma-separated list of names (a var that lists Workers). */
|
|
266
|
+
export function deployedNameList(product, list) {
|
|
267
|
+
return list
|
|
268
|
+
.split(",")
|
|
269
|
+
.map((name) => deployedName(product, name.trim()))
|
|
270
|
+
.join(",");
|
|
271
|
+
}
|
|
272
|
+
/** What a product's release files start with: `composable-os-<product>-<version>.tar.gz`. */
|
|
273
|
+
export function releaseFilePrefix(productId) {
|
|
274
|
+
return `composable-os-${productId}`;
|
|
275
|
+
}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ProductDefinition } from "./index.ts";
|
|
2
|
+
/** The variable a build reads the product from. */
|
|
3
|
+
export declare const PRODUCT_ENV = "COS_PRODUCT";
|
|
4
|
+
/** The module bundlers replace with the chosen product's definition. */
|
|
5
|
+
export declare const ACTIVE_PRODUCT_MODULE = "@composable-os/products/active";
|
|
6
|
+
/** The product.ts for an id or a path. Throws when there is none. */
|
|
7
|
+
export declare function productFile(idOrPath: string, root?: any): string;
|
|
8
|
+
/** Loads and checks the definition for an id or a path (Node 24 imports erasable TypeScript). */
|
|
9
|
+
export declare function loadProduct(idOrPath: string, root?: any): Promise<ProductDefinition>;
|
|
10
|
+
/**
|
|
11
|
+
* The chosen product's file when COS_PRODUCT is set, else null (the default product). The file is
|
|
12
|
+
* absolute, so it can be passed to a child process that runs in another directory.
|
|
13
|
+
*/
|
|
14
|
+
export declare function chosenProductFile(env?: NodeJS.ProcessEnv): string | null;
|
|
15
|
+
/** Bundler aliases that swap the active product for the chosen one. Empty for the default. */
|
|
16
|
+
export declare function productAlias(env?: NodeJS.ProcessEnv): Record<string, string>;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
// Choosing the product a build is for (Node only: build scripts and bundler configuration).
|
|
10
|
+
//
|
|
11
|
+
// COS_PRODUCT names it: a product id (`crm`, read from products/<id>/product.ts) or a path to a
|
|
12
|
+
// product.ts. Unset means the default product, the one products/active.ts points at.
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
|
+
import { defineProduct } from "./index.js";
|
|
17
|
+
/** The variable a build reads the product from. */
|
|
18
|
+
export const PRODUCT_ENV = "COS_PRODUCT";
|
|
19
|
+
/** The module bundlers replace with the chosen product's definition. */
|
|
20
|
+
export const ACTIVE_PRODUCT_MODULE = "@composable-os/products/active";
|
|
21
|
+
const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
22
|
+
/** The product.ts for an id or a path. Throws when there is none. */
|
|
23
|
+
export function productFile(idOrPath, root = REPO_ROOT) {
|
|
24
|
+
const isPath = idOrPath.includes("/") || idOrPath.endsWith(".ts");
|
|
25
|
+
const file = isPath
|
|
26
|
+
? isAbsolute(idOrPath)
|
|
27
|
+
? idOrPath
|
|
28
|
+
: resolve(process.cwd(), idOrPath)
|
|
29
|
+
: join(root, "products", idOrPath, "product.ts");
|
|
30
|
+
if (!existsSync(file)) {
|
|
31
|
+
throw new Error(isPath
|
|
32
|
+
? `no product definition at ${file}`
|
|
33
|
+
: `unknown product ${JSON.stringify(idOrPath)}: there is no products/${idOrPath}/product.ts`);
|
|
34
|
+
}
|
|
35
|
+
return file;
|
|
36
|
+
}
|
|
37
|
+
/** Loads and checks the definition for an id or a path (Node 24 imports erasable TypeScript). */
|
|
38
|
+
export async function loadProduct(idOrPath, root = REPO_ROOT) {
|
|
39
|
+
const file = productFile(idOrPath, root);
|
|
40
|
+
const module = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
|
|
41
|
+
if (!module.product)
|
|
42
|
+
throw new Error(`${file} does not export \`product\``);
|
|
43
|
+
return defineProduct(module.product);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The chosen product's file when COS_PRODUCT is set, else null (the default product). The file is
|
|
47
|
+
* absolute, so it can be passed to a child process that runs in another directory.
|
|
48
|
+
*/
|
|
49
|
+
export function chosenProductFile(env = process.env) {
|
|
50
|
+
const value = env[PRODUCT_ENV]?.trim();
|
|
51
|
+
return value ? productFile(value) : null;
|
|
52
|
+
}
|
|
53
|
+
/** Bundler aliases that swap the active product for the chosen one. Empty for the default. */
|
|
54
|
+
export function productAlias(env = process.env) {
|
|
55
|
+
const file = chosenProductFile(env);
|
|
56
|
+
return file ? { [ACTIVE_PRODUCT_MODULE]: file } : {};
|
|
57
|
+
}
|
package/dist/packs.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ProductDefinition } from "./index.ts";
|
|
2
|
+
/** One pack's extension as source, in the form cos-runner's SHIPPED_EXTENSIONS holds it. */
|
|
3
|
+
export interface PackSource {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
/** `composableOs.optional`: shipped but opt-in, installed by an admin (ADR 0246). */
|
|
7
|
+
optional?: true;
|
|
8
|
+
label?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Path inside the pack → text. */
|
|
11
|
+
files: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/** Top-level folders of a pack that are client code, not the extension. */
|
|
14
|
+
export declare const PACK_CLIENT_FOLDERS: readonly string[];
|
|
15
|
+
/** The ids of every pack in the repository: each folder of `<root>/packs/` with a package.json. */
|
|
16
|
+
export declare function repositoryPackIds(root: string): string[];
|
|
17
|
+
/** The extensions of every pack in the repository, sorted by id: what a release carries. */
|
|
18
|
+
export declare function releasePacks(root: string): PackSource[];
|
|
19
|
+
/**
|
|
20
|
+
* The extensions of the packs `product` lists, read from `<root>/packs/<id>/`, sorted by id.
|
|
21
|
+
* Throws when a listed pack has no directory, package.json or index.ts.
|
|
22
|
+
*/
|
|
23
|
+
export declare function productPacks(product: ProductDefinition, root: string): PackSource[];
|
package/dist/packs.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// The packs a release carries (stage 24, Node only: the runner's bundle script, the release build).
|
|
2
|
+
//
|
|
3
|
+
// A pack is `packs/<id>/`: the shipped extension (`index.ts` and its files), `client/` for headless
|
|
4
|
+
// hooks and `blocks/` for its screens. Only the extension runs in the host, so only it is read
|
|
5
|
+
// here: the client parts are for client apps and never reach the runner.
|
|
6
|
+
//
|
|
7
|
+
// A release carries every pack in the repository (`releasePacks`), so a client product can turn on
|
|
8
|
+
// any of them at deploy (`COS_PACKS`). Which packs a deployment installs stays that deploy-time
|
|
9
|
+
// choice; a release product's own deployments install the packs its product lists
|
|
10
|
+
// (`productPacks`, the runner's default), exactly as before (ADR 0420, amended 2026-11-21).
|
|
11
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
12
|
+
import { join, relative } from "node:path";
|
|
13
|
+
/** Folders of a pack that are never source: build output and tests. */
|
|
14
|
+
const NOT_SOURCE = new Set(["node_modules", "test", "tests", "dist", ".turbo"]);
|
|
15
|
+
/** Top-level folders of a pack that are client code, not the extension. */
|
|
16
|
+
export const PACK_CLIENT_FOLDERS = ["client", "blocks"];
|
|
17
|
+
function sourceFiles(dir, base, files) {
|
|
18
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
19
|
+
const path = join(dir, entry.name);
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
if (NOT_SOURCE.has(entry.name))
|
|
22
|
+
continue;
|
|
23
|
+
if (dir === base && PACK_CLIENT_FOLDERS.includes(entry.name))
|
|
24
|
+
continue;
|
|
25
|
+
sourceFiles(path, base, files);
|
|
26
|
+
}
|
|
27
|
+
else if (/\.(ts|js)$/.test(entry.name) && !/\.(test|config)\.(ts|js)$/.test(entry.name)) {
|
|
28
|
+
files[relative(base, path).split("\\").join("/")] = readFileSync(path, "utf8");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The ids of every pack in the repository: each folder of `<root>/packs/` with a package.json. */
|
|
33
|
+
export function repositoryPackIds(root) {
|
|
34
|
+
let names;
|
|
35
|
+
try {
|
|
36
|
+
names = readdirSync(join(root, "packs"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return names
|
|
42
|
+
.filter((name) => {
|
|
43
|
+
try {
|
|
44
|
+
return statSync(join(root, "packs", name, "package.json")).isFile();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.sort((a, b) => a.localeCompare(b));
|
|
51
|
+
}
|
|
52
|
+
/** The extensions of every pack in the repository, sorted by id: what a release carries. */
|
|
53
|
+
export function releasePacks(root) {
|
|
54
|
+
return readPacks("the release", repositoryPackIds(root), root);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The extensions of the packs `product` lists, read from `<root>/packs/<id>/`, sorted by id.
|
|
58
|
+
* Throws when a listed pack has no directory, package.json or index.ts.
|
|
59
|
+
*/
|
|
60
|
+
export function productPacks(product, root) {
|
|
61
|
+
return readPacks(`product ${product.id}`, product.packs, root);
|
|
62
|
+
}
|
|
63
|
+
function readPacks(who, ids, root) {
|
|
64
|
+
const packs = [];
|
|
65
|
+
for (const id of [...ids].sort((a, b) => a.localeCompare(b))) {
|
|
66
|
+
const dir = join(root, "packs", id);
|
|
67
|
+
let pkg;
|
|
68
|
+
try {
|
|
69
|
+
pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
70
|
+
statSync(join(dir, "index.ts"));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
throw new Error(`${who} lists the pack ${id}, and packs/${id}/ has no package.json and index.ts`);
|
|
74
|
+
}
|
|
75
|
+
const meta = pkg.composableOs ?? {};
|
|
76
|
+
const files = {};
|
|
77
|
+
sourceFiles(dir, dir, files);
|
|
78
|
+
packs.push({
|
|
79
|
+
id,
|
|
80
|
+
version: String(pkg.version),
|
|
81
|
+
...(meta.optional ? { optional: true } : {}),
|
|
82
|
+
...(typeof meta.label === "string" ? { label: meta.label } : {}),
|
|
83
|
+
...(typeof meta.description === "string" ? { description: meta.description } : {}),
|
|
84
|
+
files,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return packs;
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/product",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
|
+
"license": "FSL-1.1-ALv2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/timoconnellaus/composable-os.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://composableos.dev",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"description": "What a product definition is (ADR 0400) and how deployed names, release file names and the active product are read from one. The definitions themselves are in products/.",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./node": {
|
|
22
|
+
"types": "./dist/node.d.ts",
|
|
23
|
+
"default": "./dist/node.js"
|
|
24
|
+
},
|
|
25
|
+
"./packs": {
|
|
26
|
+
"types": "./dist/packs.d.ts",
|
|
27
|
+
"default": "./dist/packs.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
]
|
|
33
|
+
}
|
package/README.md
DELETED