@substrat-run/cli 0.0.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.
- package/LICENSE +202 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +181 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +44 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/login.d.ts +3 -0
- package/dist/login.d.ts.map +1 -0
- package/dist/login.js +107 -0
- package/dist/login.js.map +1 -0
- package/dist/promote.d.ts +19 -0
- package/dist/promote.d.ts.map +1 -0
- package/dist/promote.js +14 -0
- package/dist/promote.js.map +1 -0
- package/dist/push.d.ts +23 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +95 -0
- package/dist/push.js.map +1 -0
- package/dist/versions.d.ts +2 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +34 -0
- package/dist/versions.js.map +1 -0
- package/dist/whoami.d.ts +18 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +9 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +41 -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/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* substrat — authenticated deploy tooling for the platform.
|
|
4
|
+
*
|
|
5
|
+
* substrat login [--cp <url>] [--token <serviceToken>]
|
|
6
|
+
* substrat push <verticalDir> --slug <slug> --version <v> [--name <name>]
|
|
7
|
+
* [--cp <url>] [--token <serviceToken>]
|
|
8
|
+
*
|
|
9
|
+
* Auth is a service token (the control plane's SERVICE_TOKEN), sent as x-service-token
|
|
10
|
+
* and resolved to the platform's service actor. `login` stores it in ~/.substrat/config.json
|
|
11
|
+
* so `push` just works; any command also accepts --cp/--token or SUBSTRAT_CP_URL /
|
|
12
|
+
* SUBSTRAT_SERVICE_TOKEN. A push is not a deploy — the version lands PENDING; admission
|
|
13
|
+
* (in the console) still gates serving.
|
|
14
|
+
*/
|
|
15
|
+
import { createInterface } from 'node:readline';
|
|
16
|
+
import { loadConfig, saveConfig, resolveAuth } from './config.js';
|
|
17
|
+
import { browserLogin } from './login.js';
|
|
18
|
+
import { push } from './push.js';
|
|
19
|
+
import { printVersions } from './versions.js';
|
|
20
|
+
import { promote } from './promote.js';
|
|
21
|
+
import { fetchWhoami } from './whoami.js';
|
|
22
|
+
const argv = process.argv.slice(2);
|
|
23
|
+
/** `--name value` → value, else undefined. */
|
|
24
|
+
function flag(name) {
|
|
25
|
+
const i = argv.indexOf(`--${name}`);
|
|
26
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** Prompt on the TTY for a plain (non-secret) value. */
|
|
29
|
+
function ask(question) {
|
|
30
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
rl.question(question, (answer) => {
|
|
33
|
+
rl.close();
|
|
34
|
+
resolve(answer.trim());
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const USAGE = `substrat — authenticated deploy tooling
|
|
39
|
+
|
|
40
|
+
Usage:
|
|
41
|
+
substrat login [--cp <url>] sign in via the browser (per-human)
|
|
42
|
+
substrat login --token <serviceToken> store a service credential (CI)
|
|
43
|
+
substrat whoami show who you are + your workspaces
|
|
44
|
+
substrat push <verticalDir> --slug <slug> --version <v> [--name <name>]
|
|
45
|
+
substrat promote <slug> --channel dev|staging --version <versionId>
|
|
46
|
+
substrat versions <slug> list a vertical's versions + channels
|
|
47
|
+
|
|
48
|
+
Options (any command):
|
|
49
|
+
--cp <url> control-plane API base, e.g. https://console.substrat.net/api
|
|
50
|
+
--token <tok> the control plane's SERVICE_TOKEN (service-actor credential, for CI)
|
|
51
|
+
--tenant <t> the workspace to act for (id or slug); a builder never types the
|
|
52
|
+
'<tenant>/' slug prefix — the control plane forms it. Defaults to the
|
|
53
|
+
one stored at login (SUBSTRAT_TENANT overrides).
|
|
54
|
+
|
|
55
|
+
A builder pushes a BARE --slug; the control plane forms '<tenantSlug>/<slug>' (§5). A push
|
|
56
|
+
lands a version PENDING; a builder self-serves dev/staging with 'promote', but prod
|
|
57
|
+
promotion + admission stay a staff decision (model B).
|
|
58
|
+
|
|
59
|
+
Auth resolves: explicit --token/SUBSTRAT_SERVICE_TOKEN → stored browser session →
|
|
60
|
+
stored service token. URL resolves flag → SUBSTRAT_CP_URL → ~/.substrat/config.json.
|
|
61
|
+
`;
|
|
62
|
+
async function cmdLogin() {
|
|
63
|
+
const existing = loadConfig();
|
|
64
|
+
const cpDefault = existing.controlPlaneUrl ?? 'https://console.substrat.net/api';
|
|
65
|
+
const cp = ((flag('cp') ?? (await ask(`control-plane URL [${cpDefault}]: `))) || cpDefault).replace(/\/$/, '');
|
|
66
|
+
// CI path: a service credential, no browser.
|
|
67
|
+
const serviceToken = flag('token');
|
|
68
|
+
if (serviceToken) {
|
|
69
|
+
const path = saveConfig({ ...existing, controlPlaneUrl: cp, serviceToken });
|
|
70
|
+
console.log(`✓ saved service credential → ${path}`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Default: browser loopback login → a per-human session token.
|
|
74
|
+
const bearerToken = await browserLogin(cp);
|
|
75
|
+
// Resolve the builder's workspace so `push`/`promote` just work (builder-plane.md §5).
|
|
76
|
+
// One tenant → store it; several → pick; none → they still need to sign up in the app.
|
|
77
|
+
const { user, tenants } = await fetchWhoami(cp, { authorization: `Bearer ${bearerToken}` }).catch(() => ({ user: null, tenants: [] }));
|
|
78
|
+
let defaultTenant = existing.defaultTenant;
|
|
79
|
+
if (tenants.length === 1) {
|
|
80
|
+
defaultTenant = tenants[0].slug;
|
|
81
|
+
console.log(` workspace: ${defaultTenant}`);
|
|
82
|
+
}
|
|
83
|
+
else if (tenants.length > 1) {
|
|
84
|
+
console.log(' you belong to several workspaces:');
|
|
85
|
+
tenants.forEach((t, i) => console.log(` ${i + 1}. ${t.slug} (${t.name})`));
|
|
86
|
+
const pick = await ask(` default workspace [1-${tenants.length}, or a slug]: `);
|
|
87
|
+
defaultTenant =
|
|
88
|
+
tenants[Number(pick) - 1]?.slug ??
|
|
89
|
+
tenants.find((t) => t.slug === pick || t.id === pick)?.slug ??
|
|
90
|
+
tenants[0].slug;
|
|
91
|
+
console.log(` default workspace: ${defaultTenant} (override per command with --tenant)`);
|
|
92
|
+
}
|
|
93
|
+
else if (user) {
|
|
94
|
+
console.log(' no workspace yet — create one at your dashboard, then `substrat push`.');
|
|
95
|
+
}
|
|
96
|
+
const path = saveConfig({ ...existing, controlPlaneUrl: cp, bearerToken, defaultTenant });
|
|
97
|
+
console.log(`✓ signed in${user?.email ? ` as ${user.email}` : ''}. session saved to ${path}`);
|
|
98
|
+
}
|
|
99
|
+
async function cmdPush() {
|
|
100
|
+
const dir = argv[1];
|
|
101
|
+
if (!dir || dir.startsWith('--')) {
|
|
102
|
+
console.error('usage: substrat push <verticalDir> --slug <slug> --version <v> [--name <name>]');
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const slug = flag('slug');
|
|
106
|
+
const version = flag('version');
|
|
107
|
+
if (!slug || !version) {
|
|
108
|
+
console.error('missing --slug and/or --version');
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
const { controlPlaneUrl, header, as } = resolveAuth({ cp: flag('cp'), token: flag('token'), tenant: flag('tenant') });
|
|
112
|
+
console.log(`authenticating with ${as}`);
|
|
113
|
+
const v = await push({ dir, slug, version, name: flag('name'), controlPlaneUrl, authHeader: header });
|
|
114
|
+
console.log(`✓ pushed. version ${v.id} is ${v.admission}; deploymentRef=${v.deploymentRef}`);
|
|
115
|
+
console.log(' admit it in the console to let a scope bind it.');
|
|
116
|
+
}
|
|
117
|
+
async function cmdVersions() {
|
|
118
|
+
const slug = argv[1];
|
|
119
|
+
if (!slug || slug.startsWith('--')) {
|
|
120
|
+
console.error('usage: substrat versions <slug>');
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const { controlPlaneUrl, header } = resolveAuth({ cp: flag('cp'), token: flag('token'), tenant: flag('tenant') });
|
|
124
|
+
await printVersions(controlPlaneUrl, header, slug);
|
|
125
|
+
}
|
|
126
|
+
async function cmdPromote() {
|
|
127
|
+
const slug = argv[1];
|
|
128
|
+
const channel = flag('channel');
|
|
129
|
+
const version = flag('version');
|
|
130
|
+
if (!slug || slug.startsWith('--') || !channel || !version) {
|
|
131
|
+
console.error('usage: substrat promote <slug> --channel dev|staging --version <versionId>');
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
const { controlPlaneUrl, header, as } = resolveAuth({ cp: flag('cp'), token: flag('token'), tenant: flag('tenant') });
|
|
135
|
+
console.log(`authenticating with ${as}`);
|
|
136
|
+
const ch = await promote({ controlPlaneUrl, header, slug, channel, versionId: version });
|
|
137
|
+
console.log(`✓ ${slug} → ${ch.channel} now points at ${ch.versionId}`);
|
|
138
|
+
}
|
|
139
|
+
async function cmdWhoami() {
|
|
140
|
+
const { controlPlaneUrl, header } = resolveAuth({ cp: flag('cp'), token: flag('token'), tenant: flag('tenant') });
|
|
141
|
+
const { user, tenants } = await fetchWhoami(controlPlaneUrl, header);
|
|
142
|
+
if (!user) {
|
|
143
|
+
console.log('not signed in.');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
console.log(`signed in as ${user.email ?? user.id}`);
|
|
147
|
+
if (tenants.length === 0)
|
|
148
|
+
console.log(' no workspaces yet.');
|
|
149
|
+
for (const t of tenants)
|
|
150
|
+
console.log(` ${t.slug} (${t.name})`);
|
|
151
|
+
}
|
|
152
|
+
async function main() {
|
|
153
|
+
const command = argv[0];
|
|
154
|
+
switch (command) {
|
|
155
|
+
case 'login':
|
|
156
|
+
return cmdLogin();
|
|
157
|
+
case 'versions':
|
|
158
|
+
return cmdVersions();
|
|
159
|
+
case 'push':
|
|
160
|
+
return cmdPush();
|
|
161
|
+
case 'promote':
|
|
162
|
+
return cmdPromote();
|
|
163
|
+
case 'whoami':
|
|
164
|
+
return cmdWhoami();
|
|
165
|
+
case 'help':
|
|
166
|
+
case '--help':
|
|
167
|
+
case '-h':
|
|
168
|
+
case undefined:
|
|
169
|
+
process.stdout.write(USAGE);
|
|
170
|
+
return;
|
|
171
|
+
default:
|
|
172
|
+
console.error(`unknown command '${command}'\n`);
|
|
173
|
+
process.stdout.write(USAGE);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
main().catch((err) => {
|
|
178
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
179
|
+
process.exit(1);
|
|
180
|
+
});
|
|
181
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,YAAY,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ACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,KAAK,CAAC,CAAC;YAChD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;IAC5B,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's stored credentials. A service token is a machine credential (the same
|
|
3
|
+
* `SERVICE_TOKEN` the control plane holds); it resolves to the platform's service
|
|
4
|
+
* actor. Kept in `~/.substrat/config.json`, chmod 600 — a home-dir file, never in a
|
|
5
|
+
* repo. A push reads it so you authenticate once with `substrat login`, not per call.
|
|
6
|
+
*/
|
|
7
|
+
export interface CliConfig {
|
|
8
|
+
controlPlaneUrl?: string;
|
|
9
|
+
/** A browser-login session (sent as `Authorization: Bearer`) — per-human, from `substrat login`. */
|
|
10
|
+
bearerToken?: string;
|
|
11
|
+
/** A shared machine credential (sent as `x-service-token`) — for CI, from `substrat login --token`. */
|
|
12
|
+
serviceToken?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The tenant a builder acts for (builder-plane.md §5) — the id or slug the control plane
|
|
15
|
+
* prefixes onto a bare `--slug` to form `<tenantSlug>/<name>`. Stored by `substrat login`
|
|
16
|
+
* (the sole/selected workspace); `--tenant` overrides per command. Sent as
|
|
17
|
+
* `x-substrat-tenant`, and only with a browser session (a service token is not a builder).
|
|
18
|
+
*/
|
|
19
|
+
defaultTenant?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function loadConfig(): CliConfig;
|
|
22
|
+
/** Write the config 0600 (best-effort chmod — a no-op on platforms without it). */
|
|
23
|
+
export declare function saveConfig(cfg: CliConfig): string;
|
|
24
|
+
export interface ResolvedAuth {
|
|
25
|
+
controlPlaneUrl: string;
|
|
26
|
+
/** The auth header to send with an authenticated request. */
|
|
27
|
+
header: Record<string, string>;
|
|
28
|
+
/** Human description of how we authenticated (for the CLI to print). */
|
|
29
|
+
as: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the control-plane URL + the auth header, in precedence order:
|
|
33
|
+
* URL: flag → SUBSTRAT_CP_URL → config
|
|
34
|
+
* auth: explicit service token (flag/env, for CI) → stored browser session → stored service token
|
|
35
|
+
* A browser session is sent as `Authorization: Bearer` (per-human, roster-gated); a
|
|
36
|
+
* service token as `x-service-token` (the platform service actor). Throws a clear,
|
|
37
|
+
* actionable error pointing at `substrat login` rather than surfacing a 401 later.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveAuth(flags: {
|
|
40
|
+
cp?: string;
|
|
41
|
+
token?: string;
|
|
42
|
+
tenant?: string;
|
|
43
|
+
}): ResolvedAuth;
|
|
44
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oGAAoG;IACpG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uGAAuG;IACvG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD,wBAAgB,UAAU,IAAI,SAAS,CAMtC;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAUjD;AAED,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,wEAAwE;IACxE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,CAwBjG"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, mkdirSync, chmodSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const configDir = () => join(homedir(), '.substrat');
|
|
5
|
+
const configFile = () => join(configDir(), 'config.json');
|
|
6
|
+
export function loadConfig() {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(readFileSync(configFile(), 'utf8'));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Write the config 0600 (best-effort chmod — a no-op on platforms without it). */
|
|
15
|
+
export function saveConfig(cfg) {
|
|
16
|
+
mkdirSync(configDir(), { recursive: true });
|
|
17
|
+
const path = configFile();
|
|
18
|
+
writeFileSync(path, JSON.stringify(cfg, null, 2) + '\n');
|
|
19
|
+
try {
|
|
20
|
+
chmodSync(path, 0o600);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* best effort */
|
|
24
|
+
}
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the control-plane URL + the auth header, in precedence order:
|
|
29
|
+
* URL: flag → SUBSTRAT_CP_URL → config
|
|
30
|
+
* auth: explicit service token (flag/env, for CI) → stored browser session → stored service token
|
|
31
|
+
* A browser session is sent as `Authorization: Bearer` (per-human, roster-gated); a
|
|
32
|
+
* service token as `x-service-token` (the platform service actor). Throws a clear,
|
|
33
|
+
* actionable error pointing at `substrat login` rather than surfacing a 401 later.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveAuth(flags) {
|
|
36
|
+
const cfg = loadConfig();
|
|
37
|
+
const raw = flags.cp ?? process.env.SUBSTRAT_CP_URL ?? cfg.controlPlaneUrl;
|
|
38
|
+
if (!raw) {
|
|
39
|
+
throw new Error('no control-plane URL — pass --cp, set SUBSTRAT_CP_URL, or run `substrat login`');
|
|
40
|
+
}
|
|
41
|
+
const controlPlaneUrl = raw.replace(/\/$/, '');
|
|
42
|
+
const explicitService = flags.token ?? process.env.SUBSTRAT_SERVICE_TOKEN;
|
|
43
|
+
if (explicitService) {
|
|
44
|
+
return { controlPlaneUrl, header: { 'x-service-token': explicitService }, as: 'service token' };
|
|
45
|
+
}
|
|
46
|
+
if (cfg.bearerToken) {
|
|
47
|
+
// A builder acts for a tenant: `--tenant` → SUBSTRAT_TENANT → the stored default.
|
|
48
|
+
// Sent only with a browser session — a service token is the platform, not a builder.
|
|
49
|
+
const tenant = flags.tenant ?? process.env.SUBSTRAT_TENANT ?? cfg.defaultTenant;
|
|
50
|
+
const header = { authorization: `Bearer ${cfg.bearerToken}` };
|
|
51
|
+
if (tenant)
|
|
52
|
+
header['x-substrat-tenant'] = tenant;
|
|
53
|
+
return { controlPlaneUrl, header, as: tenant ? `browser session (tenant ${tenant})` : 'browser session' };
|
|
54
|
+
}
|
|
55
|
+
if (cfg.serviceToken) {
|
|
56
|
+
return { controlPlaneUrl, header: { 'x-service-token': cfg.serviceToken }, as: 'service token' };
|
|
57
|
+
}
|
|
58
|
+
throw new Error('not authenticated — run `substrat login` (browser), or pass --token / set SUBSTRAT_SERVICE_TOKEN for CI');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
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@@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAsFA,+FAA+F;AAC/F,wBAAsB,YAAY,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwB3E"}
|
package/dist/login.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { webcrypto } from 'node:crypto';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
/**
|
|
5
|
+
* The loopback browser-login flow (`substrat login`). PKCE against the control plane's
|
|
6
|
+
* CLI broker (apps/control-plane/src/cli-auth.ts) — which brokers AuthHero, so the CLI
|
|
7
|
+
* never touches the IdP directly:
|
|
8
|
+
*
|
|
9
|
+
* 1. generate a PKCE verifier + challenge + state; start a localhost server
|
|
10
|
+
* 2. open the browser to {cp}/auth/cli?port&state&challenge
|
|
11
|
+
* 3. the broker signs the user in (AuthHero) and redirects to 127.0.0.1:PORT/callback?code&state
|
|
12
|
+
* 4. exchange {code, verifier} at {cp}/auth/cli/token → the session token
|
|
13
|
+
*
|
|
14
|
+
* The token never transits a URL — only the PKCE-bound `code` does — and the loopback
|
|
15
|
+
* server accepts exactly one callback on the ephemeral port, then closes.
|
|
16
|
+
*/
|
|
17
|
+
const enc = new TextEncoder();
|
|
18
|
+
function b64url(bytes) {
|
|
19
|
+
let s = '';
|
|
20
|
+
for (const byte of bytes)
|
|
21
|
+
s += String.fromCharCode(byte);
|
|
22
|
+
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
23
|
+
}
|
|
24
|
+
const randomB64url = (n = 32) => b64url(webcrypto.getRandomValues(new Uint8Array(n)));
|
|
25
|
+
async function s256(verifier) {
|
|
26
|
+
return b64url(new Uint8Array(await webcrypto.subtle.digest('SHA-256', enc.encode(verifier))));
|
|
27
|
+
}
|
|
28
|
+
function openBrowser(url) {
|
|
29
|
+
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
30
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
31
|
+
try {
|
|
32
|
+
spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* the printed URL is the fallback */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Start a one-shot loopback server; resolves with the `code` from a state-matching callback. */
|
|
39
|
+
function awaitCallback(expectedState) {
|
|
40
|
+
return new Promise((resolvePort) => {
|
|
41
|
+
let resolveCode;
|
|
42
|
+
let rejectCode;
|
|
43
|
+
const code = new Promise((res, rej) => {
|
|
44
|
+
resolveCode = res;
|
|
45
|
+
rejectCode = rej;
|
|
46
|
+
});
|
|
47
|
+
const server = createServer((req, res) => {
|
|
48
|
+
const url = new URL(req.url ?? '/', 'http://127.0.0.1');
|
|
49
|
+
if (url.pathname !== '/callback') {
|
|
50
|
+
res.writeHead(404);
|
|
51
|
+
res.end();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const html = (title, msg) => {
|
|
55
|
+
res.writeHead(url.searchParams.get('code') ? 200 : 400, { 'content-type': 'text/html' });
|
|
56
|
+
res.end(`<!doctype html><meta charset=utf-8><title>${title}</title><body style="font:16px system-ui;max-width:32rem;margin:4rem auto;text-align:center"><h1>${title}</h1><p>${msg}</p></body>`);
|
|
57
|
+
};
|
|
58
|
+
const got = url.searchParams.get('code');
|
|
59
|
+
const state = url.searchParams.get('state');
|
|
60
|
+
if (!got || state !== expectedState) {
|
|
61
|
+
html('Login failed', 'State mismatch — you can close this tab and try again.');
|
|
62
|
+
rejectCode(new Error('loopback callback state mismatch'));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
html('Signed in to the substrat CLI', 'You can close this tab and return to your terminal.');
|
|
66
|
+
resolveCode(got);
|
|
67
|
+
}
|
|
68
|
+
server.close();
|
|
69
|
+
});
|
|
70
|
+
server.listen(0, '127.0.0.1', () => {
|
|
71
|
+
const addr = server.address();
|
|
72
|
+
const port = typeof addr === 'object' && addr ? addr.port : 0;
|
|
73
|
+
resolvePort({ port, code });
|
|
74
|
+
});
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
rejectCode(new Error('login timed out — no browser callback within 5 minutes'));
|
|
77
|
+
server.close();
|
|
78
|
+
}, 5 * 60 * 1000);
|
|
79
|
+
void code.finally(() => clearTimeout(timer));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Run the full loopback login against `controlPlaneUrl`; returns a session token to store. */
|
|
83
|
+
export async function browserLogin(controlPlaneUrl) {
|
|
84
|
+
const cp = controlPlaneUrl.replace(/\/$/, '');
|
|
85
|
+
const verifier = randomB64url(32);
|
|
86
|
+
const challenge = await s256(verifier);
|
|
87
|
+
const state = randomB64url(16);
|
|
88
|
+
const { port, code } = await awaitCallback(state);
|
|
89
|
+
const authUrl = `${cp}/auth/cli?port=${port}&state=${encodeURIComponent(state)}&challenge=${encodeURIComponent(challenge)}`;
|
|
90
|
+
console.log('opening your browser to sign in…');
|
|
91
|
+
console.log(` if it doesn't open, visit:\n ${authUrl}\n`);
|
|
92
|
+
openBrowser(authUrl);
|
|
93
|
+
const codeValue = await code;
|
|
94
|
+
const res = await fetch(`${cp}/auth/cli/token`, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: { 'content-type': 'application/json' },
|
|
97
|
+
body: JSON.stringify({ code: codeValue, verifier }),
|
|
98
|
+
});
|
|
99
|
+
if (!res.ok) {
|
|
100
|
+
throw new Error(`token exchange failed (${res.status}): ${(await res.text()).slice(0, 300)}`);
|
|
101
|
+
}
|
|
102
|
+
const { token } = (await res.json());
|
|
103
|
+
if (!token)
|
|
104
|
+
throw new Error('token exchange returned no token');
|
|
105
|
+
return token;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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,CAAC,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAuB,CAAC;IAC3D,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `substrat promote <slug> --channel dev|staging --version <id>` — a builder self-serves a
|
|
3
|
+
* NON-prod channel (builder-plane.md §4; model B keeps prod a staff decision). The slug is
|
|
4
|
+
* BARE — the control plane forms `<tenantSlug>/<slug>` from the caller's tenant (§5), so a
|
|
5
|
+
* builder never types their own prefix. Only admitted versions promote; a changed digest is
|
|
6
|
+
* refused without acknowledgement (the two checkpoints), surfaced as a 4xx here.
|
|
7
|
+
*/
|
|
8
|
+
export interface PromoteOptions {
|
|
9
|
+
controlPlaneUrl: string;
|
|
10
|
+
header: Record<string, string>;
|
|
11
|
+
slug: string;
|
|
12
|
+
channel: string;
|
|
13
|
+
versionId: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function promote(opts: PromoteOptions): Promise<{
|
|
16
|
+
channel: string;
|
|
17
|
+
versionId: string;
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=promote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../src/promote.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAWnG"}
|
package/dist/promote.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function promote(opts) {
|
|
2
|
+
const base = opts.controlPlaneUrl.replace(/\/$/, '');
|
|
3
|
+
const url = `${base}/verticals/${encodeURIComponent(opts.slug)}/channels/${encodeURIComponent(opts.channel)}/promote`;
|
|
4
|
+
const res = await fetch(url, {
|
|
5
|
+
method: 'POST',
|
|
6
|
+
headers: { ...opts.header, 'content-type': 'application/json' },
|
|
7
|
+
body: JSON.stringify({ versionId: opts.versionId }),
|
|
8
|
+
});
|
|
9
|
+
const body = await res.text();
|
|
10
|
+
if (!res.ok)
|
|
11
|
+
throw new Error(`promote failed (${res.status}): ${body.slice(0, 300)}`);
|
|
12
|
+
return JSON.parse(body);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=promote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote.js","sourceRoot":"","sources":["../src/promote.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAoB;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,GAAG,IAAI,cAAc,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;IACtH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/D,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAA2C,CAAC;AACpE,CAAC"}
|
package/dist/push.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface PushOptions {
|
|
2
|
+
dir: string;
|
|
3
|
+
slug: string;
|
|
4
|
+
version: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
controlPlaneUrl: string;
|
|
7
|
+
/** The auth header to send — a bearer session or an x-service-token (see config.resolveAuth). */
|
|
8
|
+
authHeader: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Build a vertical and push its bundle to the platform's deploy endpoint
|
|
12
|
+
* (self-serve-deploy.md). The worker is built with `wrangler --dry-run --outdir` — the
|
|
13
|
+
* control plane holds the Cloudflare credential, this never does (D-34). The version
|
|
14
|
+
* lands PENDING; admission still gates serving. Authenticated with the caller's own
|
|
15
|
+
* credential (`opts.authHeader` — a browser session or a service token), never a
|
|
16
|
+
* hand-picked `--actor`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function push(opts: PushOptions): Promise<{
|
|
19
|
+
id: string;
|
|
20
|
+
admission: string;
|
|
21
|
+
deploymentRef: string;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,iGAAiG;IACjG,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CA2E/G"}
|
package/dist/push.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { mkdtempSync, readFileSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join, basename } from 'node:path';
|
|
5
|
+
import { webcrypto } from 'node:crypto';
|
|
6
|
+
async function sha256(bytes) {
|
|
7
|
+
const digest = await webcrypto.subtle.digest('SHA-256', bytes);
|
|
8
|
+
return Buffer.from(digest).toString('hex').slice(0, 32);
|
|
9
|
+
}
|
|
10
|
+
/** A tiny JSONC reader: strip // and block comments, then JSON.parse. */
|
|
11
|
+
function readJsonc(path) {
|
|
12
|
+
const raw = readFileSync(path, 'utf8')
|
|
13
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
14
|
+
.replace(/(^|[^:])\/\/.*$/gm, '$1');
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build a vertical and push its bundle to the platform's deploy endpoint
|
|
19
|
+
* (self-serve-deploy.md). The worker is built with `wrangler --dry-run --outdir` — the
|
|
20
|
+
* control plane holds the Cloudflare credential, this never does (D-34). The version
|
|
21
|
+
* lands PENDING; admission still gates serving. Authenticated with the caller's own
|
|
22
|
+
* credential (`opts.authHeader` — a browser session or a service token), never a
|
|
23
|
+
* hand-picked `--actor`.
|
|
24
|
+
*/
|
|
25
|
+
export async function push(opts) {
|
|
26
|
+
const cfg = readJsonc(join(opts.dir, 'wrangler.jsonc'));
|
|
27
|
+
// A vertical's OWN stores travel with the bundle: its DO classes, and its D1 databases
|
|
28
|
+
// (e.g. a Better-Auth AUTH_DB). The control plane re-checks these against the §4 sandbox
|
|
29
|
+
// contract before the upload reaches the namespace.
|
|
30
|
+
const doBindings = cfg.durable_objects?.bindings ?? [];
|
|
31
|
+
const d1 = cfg.d1_databases ?? [];
|
|
32
|
+
const bindings = [
|
|
33
|
+
...doBindings.map((b) => ({
|
|
34
|
+
type: 'durable_object_namespace',
|
|
35
|
+
name: b.name,
|
|
36
|
+
class_name: b.class_name,
|
|
37
|
+
...(b.script_name ? { script_name: b.script_name } : {}),
|
|
38
|
+
})),
|
|
39
|
+
...d1.map((b) => ({ type: 'd1', name: b.binding, id: b.database_id })),
|
|
40
|
+
];
|
|
41
|
+
const migrations = cfg.migrations ?? [];
|
|
42
|
+
const doClasses = migrations.flatMap((m) => m.new_sqlite_classes ?? []);
|
|
43
|
+
const compatibilityDate = cfg.compatibility_date ?? '2025-01-01';
|
|
44
|
+
// Flags travel with the bundle: a vertical needing `nodejs_compat` (Better Auth, node
|
|
45
|
+
// built-ins) can't start without them, and the runtime rejects the upload.
|
|
46
|
+
const compatibilityFlags = cfg.compatibility_flags ?? [];
|
|
47
|
+
const mainPath = cfg.main;
|
|
48
|
+
// Build the bundle (runs the vertical's own wrangler `build.command` first).
|
|
49
|
+
const out = mkdtempSync(join(tmpdir(), 'substrat-build-'));
|
|
50
|
+
console.log(`building ${opts.slug}@${opts.version} …`);
|
|
51
|
+
execFileSync('npx', ['wrangler', 'deploy', '--dry-run', '--outdir', out], {
|
|
52
|
+
cwd: opts.dir,
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
});
|
|
55
|
+
// Collect the built modules; the entry is the bundled basename of `main`.
|
|
56
|
+
const mainBase = basename(mainPath).replace(/\.[cm]?ts$|\.[cm]?js$/, '');
|
|
57
|
+
const files = readdirSync(out).filter((f) => /\.(m?js)$/.test(f) && !f.endsWith('.map'));
|
|
58
|
+
const entry = files.find((f) => f.replace(/\.[cm]?js$/, '') === mainBase) ?? files[0];
|
|
59
|
+
if (!entry)
|
|
60
|
+
throw new Error(`no built module found in ${out}`);
|
|
61
|
+
const modules = files.map((f) => ({ name: f, content: readFileSync(join(out, f)) }));
|
|
62
|
+
const concat = Buffer.concat(modules.map((m) => m.content));
|
|
63
|
+
const manifest = {
|
|
64
|
+
version: opts.version,
|
|
65
|
+
name: opts.name ?? opts.slug,
|
|
66
|
+
entry,
|
|
67
|
+
compatibilityDate,
|
|
68
|
+
compatibilityFlags,
|
|
69
|
+
doClasses,
|
|
70
|
+
bindings,
|
|
71
|
+
digests: {
|
|
72
|
+
manifest: await sha256(concat),
|
|
73
|
+
permission: await sha256(Buffer.from(JSON.stringify(bindings))),
|
|
74
|
+
migration: await sha256(Buffer.from(JSON.stringify(doClasses))),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const form = new FormData();
|
|
78
|
+
form.set('manifest', JSON.stringify(manifest));
|
|
79
|
+
for (const m of modules) {
|
|
80
|
+
form.set(m.name, new Blob([m.content], { type: 'application/javascript+module' }), m.name);
|
|
81
|
+
}
|
|
82
|
+
const url = `${opts.controlPlaneUrl}/verticals/${opts.slug}/deploy`;
|
|
83
|
+
console.log(`pushing ${entry} (+${modules.length - 1} modules) → ${url}`);
|
|
84
|
+
const res = await fetch(url, {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
headers: opts.authHeader,
|
|
87
|
+
body: form,
|
|
88
|
+
});
|
|
89
|
+
const body = await res.text();
|
|
90
|
+
if (!res.ok) {
|
|
91
|
+
throw new Error(`push failed (${res.status}): ${body}`);
|
|
92
|
+
}
|
|
93
|
+
return JSON.parse(body);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=push.js.map
|
package/dist/push.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.js","sourceR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A6D,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.d.ts","sourceRoot":"","sources":["../src/versions.ts"],"names":[],"mappings":"AA0BA,wBAAsB,aAAa,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BxH"}
|
package/dist/versions.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
async function getJson(url, header) {
|
|
2
|
+
const res = await fetch(url, { headers: header });
|
|
3
|
+
if (!res.ok) {
|
|
4
|
+
throw new Error(`${res.status} ${(await res.text().catch(() => res.statusText)).slice(0, 200)}`);
|
|
5
|
+
}
|
|
6
|
+
return res.json();
|
|
7
|
+
}
|
|
8
|
+
export async function printVersions(controlPlaneUrl, header, slug) {
|
|
9
|
+
const base = controlPlaneUrl.replace(/\/$/, '');
|
|
10
|
+
const versions = await getJson(`${base}/verticals/${encodeURIComponent(slug)}/versions`, header);
|
|
11
|
+
// Channels are best-effort — a vertical with none registered still lists its versions.
|
|
12
|
+
const channels = await getJson(`${base}/verticals/${encodeURIComponent(slug)}/channels`, header).catch(() => []);
|
|
13
|
+
if (versions.length === 0) {
|
|
14
|
+
console.log(`no versions for '${slug}' (or they aren't visible to you).`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const byVersion = new Map();
|
|
18
|
+
for (const c of channels) {
|
|
19
|
+
const list = byVersion.get(c.versionId) ?? [];
|
|
20
|
+
list.push(c.channel);
|
|
21
|
+
byVersion.set(c.versionId, list);
|
|
22
|
+
}
|
|
23
|
+
// Newest first (the id is a ULID — lexicographic order is chronological).
|
|
24
|
+
const rows = [...versions]
|
|
25
|
+
.sort((a, b) => (a.id < b.id ? 1 : -1))
|
|
26
|
+
.map((v) => [v.version, v.admission, (byVersion.get(v.id) ?? []).join(',') || '—', v.id]);
|
|
27
|
+
const headers = ['VERSION', 'ADMISSION', 'CHANNELS', 'ID'];
|
|
28
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? '').length)));
|
|
29
|
+
const fmt = (cells) => cells.map((c, i) => c.padEnd(widths[i] ?? 0)).join(' ');
|
|
30
|
+
console.log(fmt(headers));
|
|
31
|
+
for (const r of rows)
|
|
32
|
+
console.log(fmt(r));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versions.js","sourceRoot":"","sources":["../src/versions.ts"],"names":[],"mappings":"AAkBA,KAAK,UAAU,OAAO,CAAI,GAAW,EAAE,MAA8B;IACnE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAClD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,EAAgB,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,eAAuB,EAAE,MAA8B,EAAE,IAAY;IACvG,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAY,GAAG,IAAI,cAAc,kBAAkB,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC5G,uFAAuF;IACvF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAY,GAAG,IAAI,cAAc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AAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAClG,MAAM,GAAG,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1F,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,IAAI;QAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/whoami.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /auth/whoami` — the signed-in user + the tenants they can build for
|
|
3
|
+
* (builder-plane.md §5). `substrat login` calls it to store a default tenant (and to
|
|
4
|
+
* prompt when a user belongs to several); a bare `whoami` command prints it.
|
|
5
|
+
*/
|
|
6
|
+
export interface Whoami {
|
|
7
|
+
user: {
|
|
8
|
+
id: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
} | null;
|
|
11
|
+
tenants: {
|
|
12
|
+
id: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
name: string;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
export declare function fetchWhoami(controlPlaneUrl: string, header: Record<string, string>): Promise<Whoami>;
|
|
18
|
+
//# sourceMappingURL=whoami.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../src/whoami.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC5C,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACvD;AAED,wBAAsB,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1G"}
|
package/dist/whoami.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export async function fetchWhoami(controlPlaneUrl, header) {
|
|
2
|
+
const base = controlPlaneUrl.replace(/\/$/, '');
|
|
3
|
+
const res = await fetch(`${base}/auth/whoami`, { headers: header });
|
|
4
|
+
if (!res.ok) {
|
|
5
|
+
throw new Error(`whoami failed (${res.status}): ${(await res.text().catch(() => res.statusText)).slice(0, 200)}`);
|
|
6
|
+
}
|
|
7
|
+
return (await res.json());
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=whoami.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami.js","sourceRoot":"","sources":["../src/whoami.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,eAAuB,EAAE,MAA8B;IACvF,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACpE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACpH,CAAC;IACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAW,CAAC;AACtC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@substrat-run/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The substrat CLI — authenticated deploy tooling: push a vertical to the platform, manage its versions and channels",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/substrat-run/substrat.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://substrat.net/guide/deploying",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"substrat",
|
|
14
|
+
"deploy",
|
|
15
|
+
"cli",
|
|
16
|
+
"cloudflare",
|
|
17
|
+
"workers-for-platforms"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"bin": {
|
|
21
|
+
"substrat": "./dist/cli.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.0.0",
|
|
32
|
+
"typescript": "^7.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -p tsconfig.json",
|
|
39
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
40
|
+
}
|
|
41
|
+
}
|