@composable-os/cli 0.0.0-stage → 0.1.0-beta.11
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/README.md +24 -2
- package/dist/accounts-UHYLCLEY.js +45 -0
- package/dist/blocks-5IFU25J6.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/chunk-2TWV3SVB.js +349 -0
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-6WGFA2IV.js +643 -0
- package/dist/chunk-6XTU2MTP.js +11278 -0
- package/dist/chunk-7CQGMVDO.js +63 -0
- package/dist/chunk-7D4GKZOX.js +615 -0
- package/dist/chunk-7OGCMQXG.js +284 -0
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/chunk-DU6OIFOU.js +2358 -0
- package/dist/chunk-E4WCYTCT.js +347 -0
- package/dist/chunk-E64SG24J.js +88 -0
- package/dist/chunk-FJIZGS5Q.js +698 -0
- package/dist/chunk-GYTEW66E.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-LAAL4YGR.js +365 -0
- package/dist/chunk-LO6WGU5Y.js +26189 -0
- package/dist/chunk-MBIKVRAC.js +1425 -0
- package/dist/chunk-P6UWZ6QQ.js +426 -0
- package/dist/chunk-PDD2ETVF.js +1302 -0
- package/dist/chunk-UB4I2QKR.js +31575 -0
- package/dist/chunk-WHKJGF36.js +2418 -0
- package/dist/chunk-XIDLW3EP.js +15471 -0
- package/dist/chunk-YFTLIEWU.js +504 -0
- package/dist/chunk-YNUZRTPH.js +182 -0
- package/dist/chunk-ZAWES2UD.js +9364 -0
- package/dist/chunk-ZZFWMVJO.js +704 -0
- package/dist/cli-5UNY5G5L.js +136 -0
- package/dist/cli-UYZMVQMR.js +24534 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-SE4EKG6W.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-FTWWMD7N.js +50 -0
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/order-U4KZLLSJ.js +19 -0
- package/dist/person-UHLVBVLR.js +67 -0
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
- package/dist/platform/migrations/0516_order_tax.sql +63 -0
- package/dist/platform/migrations/0520_publish_requests.sql +20 -0
- package/dist/platform/migrations/0530_subscriptions.sql +173 -0
- package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
- package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
- package/dist/platform/migrations/0533_allowances.sql +262 -0
- package/dist/platform/migrations/0560_recurring.sql +75 -0
- package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
- package/dist/platform/migrations/0581_once_per_person.sql +34 -0
- package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/allowance.ts +522 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +303 -0
- package/dist/platform/sdk/contract.ts +909 -0
- package/dist/platform/sdk/document.ts +935 -0
- package/dist/platform/sdk/field-types.ts +111 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +36 -0
- package/dist/platform/sdk/manifest.ts +1785 -0
- package/dist/platform/sdk/media.ts +108 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/recurring.ts +321 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +221 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +1138 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +598 -0
- package/dist/platform/sdk/testing.ts +847 -0
- package/dist/platform/sdk/unique.ts +81 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-7P4RQALH.js +648 -0
- package/dist/run-PO3W5BFA.js +508 -0
- package/dist/run-ZCGFMEZF.js +309 -0
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/src-I3IJ4NKC.js +354 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/dist/visibility-TVXZ67FD.js +41 -0
- package/package.json +33 -4
|
@@ -0,0 +1,1425 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CliError,
|
|
4
|
+
install,
|
|
5
|
+
latestVersion,
|
|
6
|
+
releaseSource,
|
|
7
|
+
str,
|
|
8
|
+
upgrade,
|
|
9
|
+
verified
|
|
10
|
+
} from "./chunk-PDD2ETVF.js";
|
|
11
|
+
import {
|
|
12
|
+
CloudflareClient,
|
|
13
|
+
assetHash,
|
|
14
|
+
contentTypeOf,
|
|
15
|
+
locateDeployment,
|
|
16
|
+
releaseAssetNames,
|
|
17
|
+
sha256Hex,
|
|
18
|
+
toBase64
|
|
19
|
+
} from "./chunk-DU6OIFOU.js";
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_PRODUCT,
|
|
22
|
+
products
|
|
23
|
+
} from "./chunk-2ABSVMGB.js";
|
|
24
|
+
import {
|
|
25
|
+
LIVE_ENVIRONMENT,
|
|
26
|
+
clientNameMaps,
|
|
27
|
+
clientNames,
|
|
28
|
+
clientWeb,
|
|
29
|
+
defineClientProduct,
|
|
30
|
+
environmentNames,
|
|
31
|
+
gatekeeperSettings,
|
|
32
|
+
isLiveEnvironment
|
|
33
|
+
} from "./chunk-6UWRT4VM.js";
|
|
34
|
+
|
|
35
|
+
// src/client-repo.ts
|
|
36
|
+
import { execFileSync } from "node:child_process";
|
|
37
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3, statSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
38
|
+
import { tmpdir } from "node:os";
|
|
39
|
+
import { basename, dirname as dirname3, join as join3, relative as relative2, resolve } from "node:path";
|
|
40
|
+
import { pathToFileURL } from "node:url";
|
|
41
|
+
|
|
42
|
+
// src/diff.ts
|
|
43
|
+
function lineDiff(before, after, context = 2) {
|
|
44
|
+
const a = before.split("\n");
|
|
45
|
+
const b = after.split("\n");
|
|
46
|
+
const n = a.length;
|
|
47
|
+
const m = b.length;
|
|
48
|
+
const width = m + 1;
|
|
49
|
+
const table = new Int32Array((n + 1) * width);
|
|
50
|
+
const lcs = (i2, j2) => table[i2 * width + j2] ?? 0;
|
|
51
|
+
for (let i2 = n - 1; i2 >= 0; i2--) {
|
|
52
|
+
for (let j2 = m - 1; j2 >= 0; j2--) {
|
|
53
|
+
table[i2 * width + j2] = a[i2] === b[j2] ? lcs(i2 + 1, j2 + 1) + 1 : Math.max(lcs(i2 + 1, j2), lcs(i2, j2 + 1));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const ops = [];
|
|
57
|
+
let i = 0;
|
|
58
|
+
let j = 0;
|
|
59
|
+
while (i < n || j < m) {
|
|
60
|
+
if (i < n && j < m && a[i] === b[j]) {
|
|
61
|
+
ops.push({ kind: " ", line: a[i] });
|
|
62
|
+
i++;
|
|
63
|
+
j++;
|
|
64
|
+
} else if (j < m && (i === n || lcs(i, j + 1) >= lcs(i + 1, j))) {
|
|
65
|
+
ops.push({ kind: "+", line: b[j] });
|
|
66
|
+
j++;
|
|
67
|
+
} else {
|
|
68
|
+
ops.push({ kind: "-", line: a[i] });
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const near = ops.map(
|
|
73
|
+
(_op, k) => ops.slice(Math.max(0, k - context), k + context + 1).some((o) => o.kind !== " ")
|
|
74
|
+
);
|
|
75
|
+
const out = [];
|
|
76
|
+
let skipped = false;
|
|
77
|
+
ops.forEach((op, k) => {
|
|
78
|
+
if (near[k]) {
|
|
79
|
+
if (skipped) out.push("@@");
|
|
80
|
+
skipped = false;
|
|
81
|
+
out.push(`${op.kind} ${op.line}`);
|
|
82
|
+
} else skipped = true;
|
|
83
|
+
});
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/host-modules.ts
|
|
88
|
+
import { createHash } from "node:crypto";
|
|
89
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
90
|
+
import { dirname, join } from "node:path";
|
|
91
|
+
var STATE_FILE = "composable-os.lock.json";
|
|
92
|
+
var MODULES = { web: ["host.ts"], mobile: ["host.ts", "secure-store.ts", "secure-random.ts"] };
|
|
93
|
+
var sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
94
|
+
var decode = (bytes) => new TextDecoder().decode(bytes);
|
|
95
|
+
function readState(root) {
|
|
96
|
+
const path = join(root, STATE_FILE);
|
|
97
|
+
return existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : {};
|
|
98
|
+
}
|
|
99
|
+
function writeState(root, state) {
|
|
100
|
+
const modules = Object.fromEntries(
|
|
101
|
+
Object.entries(state.hostModules ?? {}).sort(([a], [b]) => a.localeCompare(b))
|
|
102
|
+
);
|
|
103
|
+
writeFileSync(
|
|
104
|
+
join(root, STATE_FILE),
|
|
105
|
+
`${JSON.stringify({ ...state, hostModules: modules }, null, 2)}
|
|
106
|
+
`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function hostModulePlaces(product) {
|
|
110
|
+
const out = [];
|
|
111
|
+
for (const kind of ["web", "mobile"]) {
|
|
112
|
+
const app = product[kind];
|
|
113
|
+
if (!app) continue;
|
|
114
|
+
const clientDir = app.clientDir ?? "src/client";
|
|
115
|
+
const adopted = clientDir !== "src/client";
|
|
116
|
+
for (const file of MODULES[kind]) {
|
|
117
|
+
out.push({
|
|
118
|
+
path: join(app.dir, adopted ? clientDir : "src", file).split("\\").join("/"),
|
|
119
|
+
template: `apps/${kind}/src/${file}`,
|
|
120
|
+
adopted
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
function templateText(kit, place) {
|
|
127
|
+
const bytes = kit.get(`template/${place.template}`);
|
|
128
|
+
if (!bytes) return null;
|
|
129
|
+
const text = decode(bytes);
|
|
130
|
+
return place.adopted ? text.replaceAll("./client/customer.ts", "./customer.ts") : text;
|
|
131
|
+
}
|
|
132
|
+
function recordHostModules(root, product, kit, version) {
|
|
133
|
+
const state = readState(root);
|
|
134
|
+
state.hostModules ??= {};
|
|
135
|
+
for (const place of hostModulePlaces(product)) {
|
|
136
|
+
const path = join(root, place.path);
|
|
137
|
+
const text = templateText(kit, place);
|
|
138
|
+
if (text === null || !existsSync(path) || readFileSync(path, "utf8") !== text) continue;
|
|
139
|
+
state.hostModules[place.path] = { template: place.template, version, sha256: sha(text) };
|
|
140
|
+
}
|
|
141
|
+
writeState(root, state);
|
|
142
|
+
}
|
|
143
|
+
function upgradeHostModules(root, product, kit, version, io) {
|
|
144
|
+
const state = readState(root);
|
|
145
|
+
state.hostModules ??= {};
|
|
146
|
+
const replaced = [];
|
|
147
|
+
const edited = [];
|
|
148
|
+
for (const place of hostModulePlaces(product)) {
|
|
149
|
+
const next = templateText(kit, place);
|
|
150
|
+
if (next === null) continue;
|
|
151
|
+
const path = join(root, place.path);
|
|
152
|
+
const recorded = state.hostModules[place.path];
|
|
153
|
+
const record = () => {
|
|
154
|
+
state.hostModules[place.path] = {
|
|
155
|
+
template: place.template,
|
|
156
|
+
version,
|
|
157
|
+
sha256: sha(next)
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
if (!existsSync(path)) {
|
|
161
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
162
|
+
writeFileSync(path, next);
|
|
163
|
+
record();
|
|
164
|
+
replaced.push(`${place.path} (new)`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const current = readFileSync(path, "utf8");
|
|
168
|
+
if (current === next) {
|
|
169
|
+
record();
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (recorded && sha(current) === recorded.sha256) {
|
|
173
|
+
writeFileSync(path, next);
|
|
174
|
+
record();
|
|
175
|
+
replaced.push(place.path);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
edited.push(place.path);
|
|
179
|
+
io.out(
|
|
180
|
+
`
|
|
181
|
+
${place.path}: ${recorded ? "edited here since cos wrote it" : "no record of what cos wrote (adopted before host modules were recorded), so treated as edited"}. Not changed. The new template's changes, to apply by hand:`
|
|
182
|
+
);
|
|
183
|
+
io.out(`--- ${place.path} (here)
|
|
184
|
+
+++ ${place.path} (template, ${version})`);
|
|
185
|
+
for (const line of lineDiff(current, next)) io.out(line);
|
|
186
|
+
}
|
|
187
|
+
writeState(root, state);
|
|
188
|
+
if (replaced.length) io.out(`Host modules: ${replaced.join(", ")} replaced with ${version}'s.`);
|
|
189
|
+
if (edited.length) {
|
|
190
|
+
io.out(
|
|
191
|
+
`
|
|
192
|
+
Host modules left to merge by hand: ${edited.join(", ")}. Merge the diff above (or take the template's file as it is, if your edits are no longer needed); once a file equals the template, cos records it and replaces it on later upgrades.`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return edited;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/platform-versions.ts
|
|
199
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
200
|
+
import { dirname as dirname2, join as join2, relative } from "node:path";
|
|
201
|
+
var SECTIONS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
|
|
202
|
+
var PLATFORM = /^@composable-os\//;
|
|
203
|
+
function packageFiles(root, product) {
|
|
204
|
+
const dirs = [".", product.web?.dir, product.mobile?.dir].filter((d) => Boolean(d));
|
|
205
|
+
return [...new Set(dirs.map((d) => join2(root, d, "package.json")))].filter((p) => existsSync2(p));
|
|
206
|
+
}
|
|
207
|
+
function platformDependencies(root, product) {
|
|
208
|
+
const found = [];
|
|
209
|
+
for (const file of packageFiles(root, product)) {
|
|
210
|
+
const pkg = JSON.parse(readFileSync2(file, "utf8"));
|
|
211
|
+
for (const section of SECTIONS) {
|
|
212
|
+
const deps = pkg[section] ?? {};
|
|
213
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
214
|
+
if (PLATFORM.test(name)) found.push({ file, name, spec });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return found;
|
|
219
|
+
}
|
|
220
|
+
function movedSpec(spec, version) {
|
|
221
|
+
const match = /^([\^~]|>=|=)?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec.trim());
|
|
222
|
+
if (!match) return null;
|
|
223
|
+
return `${match[1] ?? ""}${version}`;
|
|
224
|
+
}
|
|
225
|
+
function movePlatformVersions(root, product, version) {
|
|
226
|
+
const moved = [];
|
|
227
|
+
const left = [];
|
|
228
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
229
|
+
for (const dep of platformDependencies(root, product)) {
|
|
230
|
+
byFile.set(dep.file, [...byFile.get(dep.file) ?? [], dep]);
|
|
231
|
+
}
|
|
232
|
+
for (const [file, deps] of byFile) {
|
|
233
|
+
let text = readFileSync2(file, "utf8");
|
|
234
|
+
const where = relative(root, file) || "package.json";
|
|
235
|
+
for (const dep of deps) {
|
|
236
|
+
const next = movedSpec(dep.spec, version);
|
|
237
|
+
if (next === null) {
|
|
238
|
+
left.push(`${where}: ${dep.name} "${dep.spec}"`);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (next === dep.spec) continue;
|
|
242
|
+
const pattern = new RegExp(
|
|
243
|
+
`("${dep.name.replace(/[/.]/g, "\\$&")}"\\s*:\\s*")${dep.spec.replace(/[.^~*+?()[\]{}|\\$]/g, "\\$&")}(")`
|
|
244
|
+
);
|
|
245
|
+
text = text.replace(pattern, `$1${next}$2`);
|
|
246
|
+
moved.push(`${where}: ${dep.name} ${dep.spec} \u2192 ${next}`);
|
|
247
|
+
}
|
|
248
|
+
writeFileSync2(file, text);
|
|
249
|
+
}
|
|
250
|
+
for (const file of packageFiles(root, product)) {
|
|
251
|
+
const pkg = JSON.parse(readFileSync2(file, "utf8"));
|
|
252
|
+
const where = relative(root, file) || "package.json";
|
|
253
|
+
for (const [key, map] of [
|
|
254
|
+
["pnpm.overrides", pkg.pnpm?.overrides],
|
|
255
|
+
["overrides", pkg.overrides],
|
|
256
|
+
["resolutions", pkg.resolutions]
|
|
257
|
+
]) {
|
|
258
|
+
for (const [name, spec] of Object.entries(map ?? {})) {
|
|
259
|
+
if (PLATFORM.test(name)) left.push(`${where}: ${key} ${name} ${JSON.stringify(spec)}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return { moved, left };
|
|
264
|
+
}
|
|
265
|
+
function installedVersion(root, dir, name) {
|
|
266
|
+
let at = dir;
|
|
267
|
+
for (; ; ) {
|
|
268
|
+
const file = join2(at, "node_modules", name, "package.json");
|
|
269
|
+
if (existsSync2(file)) {
|
|
270
|
+
return JSON.parse(readFileSync2(file, "utf8")).version ?? null;
|
|
271
|
+
}
|
|
272
|
+
if (at === root || dirname2(at) === at) return null;
|
|
273
|
+
at = dirname2(at);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function staleInstalls(root, product, version) {
|
|
277
|
+
const stale = [];
|
|
278
|
+
for (const dep of platformDependencies(root, product)) {
|
|
279
|
+
if (movedSpec(dep.spec, version) === null) continue;
|
|
280
|
+
const installed = installedVersion(root, dirname2(dep.file), dep.name);
|
|
281
|
+
if (installed !== version) {
|
|
282
|
+
stale.push(`${dep.name} (${installed ? `${installed} installed` : "not installed"})`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return [...new Set(stale)];
|
|
286
|
+
}
|
|
287
|
+
function installAll(root) {
|
|
288
|
+
if (existsSync2(join2(root, "yarn.lock"))) return "yarn install";
|
|
289
|
+
if (existsSync2(join2(root, "bun.lock")) || existsSync2(join2(root, "bun.lockb")))
|
|
290
|
+
return "bun install";
|
|
291
|
+
if (existsSync2(join2(root, "package-lock.json"))) return "npm install";
|
|
292
|
+
return "pnpm install";
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/client-repo.ts
|
|
296
|
+
function hostRoutes(product) {
|
|
297
|
+
return [
|
|
298
|
+
product?.web?.routes?.signIn ?? "/auth/",
|
|
299
|
+
product?.web?.routes?.operations ?? "/api/v1/op/"
|
|
300
|
+
];
|
|
301
|
+
}
|
|
302
|
+
function edgeRuleStep(product) {
|
|
303
|
+
const expression = hostRoutes(product).map((route) => `starts_with(http.request.uri.path, "${route}")`).join(" or ");
|
|
304
|
+
return `Before you open the web app to the public, add a rate limiting rule on its zone
|
|
305
|
+
(Security > WAF > Rate limiting rules). Calls over the binding do not pass the host's zone, so the
|
|
306
|
+
host's own rule does not cover them. It names only the routes that reach the host (web.routes in
|
|
307
|
+
product.ts), so the site's own pages and API are not limited by it:
|
|
308
|
+
Expression: (${expression})
|
|
309
|
+
Counting: IP (ip.src), 30 requests per 10 seconds; action Block for 10 seconds`;
|
|
310
|
+
}
|
|
311
|
+
var KIT = { template: "template/", skills: "skills/", blocks: "blocks/", contract: "contract/" };
|
|
312
|
+
var decode2 = (bytes) => new TextDecoder().decode(bytes);
|
|
313
|
+
function releaseProduct(deps, id) {
|
|
314
|
+
const known = deps.products ?? { all: products, default: DEFAULT_PRODUCT };
|
|
315
|
+
const product = known.all[id];
|
|
316
|
+
if (!product) {
|
|
317
|
+
throw new CliError(`No platform product ${id}. Known: ${Object.keys(known.all).join(", ")}.`);
|
|
318
|
+
}
|
|
319
|
+
return product;
|
|
320
|
+
}
|
|
321
|
+
async function fetchKit(flags, deps, releaseId, repository, version, options = {}) {
|
|
322
|
+
const release = releaseProduct(deps, releaseId);
|
|
323
|
+
const source = releaseSource(repository ? { ...flags, repo: repository } : flags, deps, release);
|
|
324
|
+
const chosen = version ?? await latestVersion(source, "stable");
|
|
325
|
+
if (options.bundleOnly && source.bundleDir) {
|
|
326
|
+
const file = releaseAssetNames(release.id, chosen).bundle;
|
|
327
|
+
if (!existsSync3(join3(source.bundleDir, file))) {
|
|
328
|
+
throw new CliError(
|
|
329
|
+
`${file} is not in --bundle-dir ${source.bundleDir}: put ${chosen}'s bundle and its SHA256SUMS there, or leave out --bundle-dir to download it.`
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const { bundle } = await verified(source, chosen, deps);
|
|
334
|
+
if (!bundle.clientFiles.size) {
|
|
335
|
+
throw new CliError(`${release.label} ${chosen} has no client kit: it is older than stage 24.`);
|
|
336
|
+
}
|
|
337
|
+
return { kit: bundle.clientFiles, version: chosen, manifest: bundle.manifest, release };
|
|
338
|
+
}
|
|
339
|
+
function appWorker(manifest) {
|
|
340
|
+
const app = manifest.workers.find((w) => w.role === "app");
|
|
341
|
+
if (!app) throw new CliError("The release has no app Worker.");
|
|
342
|
+
return app.name;
|
|
343
|
+
}
|
|
344
|
+
async function loadClientProduct(root) {
|
|
345
|
+
const file = join3(root, "product.ts");
|
|
346
|
+
if (!existsSync3(file)) {
|
|
347
|
+
throw new CliError("No product.ts here: run cos init to adopt this repository, or cos create.");
|
|
348
|
+
}
|
|
349
|
+
const { build } = await import("esbuild");
|
|
350
|
+
const out = join3(mkdtemp("cos-product-"), "product.mjs");
|
|
351
|
+
await build({
|
|
352
|
+
entryPoints: [file],
|
|
353
|
+
outfile: out,
|
|
354
|
+
bundle: true,
|
|
355
|
+
platform: "node",
|
|
356
|
+
format: "esm",
|
|
357
|
+
logLevel: "error",
|
|
358
|
+
plugins: [
|
|
359
|
+
{
|
|
360
|
+
name: "product",
|
|
361
|
+
setup(b) {
|
|
362
|
+
b.onResolve({ filter: /^@composable-os\/product$/ }, () => ({
|
|
363
|
+
path: "product",
|
|
364
|
+
namespace: "cos"
|
|
365
|
+
}));
|
|
366
|
+
b.onLoad({ filter: /.*/, namespace: "cos" }, () => ({
|
|
367
|
+
contents: "export const defineClientProduct = (d) => d; export const defineProduct = (d) => d;",
|
|
368
|
+
loader: "js"
|
|
369
|
+
}));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
]
|
|
373
|
+
});
|
|
374
|
+
const module = await import(pathToFileURL(out).href);
|
|
375
|
+
if (!module.product?.platform) {
|
|
376
|
+
throw new CliError(`${file} does not export a client product (defineClientProduct).`);
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
return defineClientProduct(module.product);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
throw new CliError(error.message);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function mkdtemp(prefix) {
|
|
385
|
+
const dir = join3(
|
|
386
|
+
tmpdir(),
|
|
387
|
+
`${prefix}${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`
|
|
388
|
+
);
|
|
389
|
+
mkdirSync2(dir, { recursive: true });
|
|
390
|
+
return dir;
|
|
391
|
+
}
|
|
392
|
+
function setPlatformVersion(root, version) {
|
|
393
|
+
const file = join3(root, "product.ts");
|
|
394
|
+
const text = readFileSync3(file, "utf8");
|
|
395
|
+
const next = text.replace(
|
|
396
|
+
/(["']?platform["']?\s*:\s*\{[^}]*["']?version["']?\s*:\s*")[^"]*(")/,
|
|
397
|
+
`$1${version}$2`
|
|
398
|
+
);
|
|
399
|
+
if (next === text && !text.includes(`"${version}"`)) {
|
|
400
|
+
throw new CliError("Could not find platform.version in product.ts to change it.");
|
|
401
|
+
}
|
|
402
|
+
writeFileSync3(file, next);
|
|
403
|
+
}
|
|
404
|
+
function orgExtensionDirs(root) {
|
|
405
|
+
const dir = join3(root, "extensions");
|
|
406
|
+
if (!existsSync3(dir)) return [];
|
|
407
|
+
return readdirSync(dir).map((name) => join3(dir, name)).filter((path) => statSync(path).isDirectory() && existsSync3(join3(path, "index.ts"))).sort();
|
|
408
|
+
}
|
|
409
|
+
function appClients(product) {
|
|
410
|
+
const out = [];
|
|
411
|
+
if (product.web) out.push(join3(product.web.dir, product.web.clientDir ?? "src/client"));
|
|
412
|
+
if (product.mobile) out.push(join3(product.mobile.dir, product.mobile.clientDir ?? "src/client"));
|
|
413
|
+
return out;
|
|
414
|
+
}
|
|
415
|
+
async function generateClients(root, product, kit, io) {
|
|
416
|
+
const { releaseContract, renderClient } = await import("./src-CRO35DYY.js");
|
|
417
|
+
const { loadExtension } = await import("./cli-5UNY5G5L.js");
|
|
418
|
+
const perAudience = ["customer", "public", "staff"].map((audience) => {
|
|
419
|
+
const bytes = kit.get(`${KIT.contract}${audience}.json`);
|
|
420
|
+
if (!bytes) throw new CliError(`The release's client kit has no ${audience} contract.`);
|
|
421
|
+
return JSON.parse(decode2(bytes));
|
|
422
|
+
});
|
|
423
|
+
const extensions = await Promise.all(orgExtensionDirs(root).map((dir) => loadExtension(dir)));
|
|
424
|
+
const contract = releaseContract(perAudience, product.packs, extensions);
|
|
425
|
+
const files = renderClient(contract, { product: product.id });
|
|
426
|
+
const written = [];
|
|
427
|
+
for (const dir of appClients(product)) {
|
|
428
|
+
mkdirSync2(join3(root, dir), { recursive: true });
|
|
429
|
+
writeFileSync3(join3(root, dir, "customer.ts"), files["customer.ts"]);
|
|
430
|
+
written.push(join3(dir, "customer.ts"));
|
|
431
|
+
}
|
|
432
|
+
const roles = product.mobile?.roles ?? [];
|
|
433
|
+
if (roles.length && product.mobile) {
|
|
434
|
+
const { renderRoleClient } = await import("./src-CRO35DYY.js");
|
|
435
|
+
const rolesFile = kit.get(`${KIT.contract}roles.json`);
|
|
436
|
+
if (!rolesFile) {
|
|
437
|
+
throw new CliError(
|
|
438
|
+
"The release's client kit has no roles.json: it is older than role clients. Upgrade the platform version first."
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
const declared = JSON.parse(decode2(rolesFile)).roles;
|
|
442
|
+
const staff = perAudience[2];
|
|
443
|
+
const dir = join3(product.mobile.dir, product.mobile.clientDir ?? "src/client", "roles");
|
|
444
|
+
mkdirSync2(join3(root, dir), { recursive: true });
|
|
445
|
+
for (const name of roles) {
|
|
446
|
+
const role = declared.find((r) => r.name === name);
|
|
447
|
+
if (!role) {
|
|
448
|
+
throw new CliError(
|
|
449
|
+
`The release has no pack role ${name}. Its roles: ${declared.map((r) => r.name).join(", ") || "none"}.`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
writeFileSync3(
|
|
453
|
+
join3(root, dir, `${name}.ts`),
|
|
454
|
+
renderRoleClient(staff, role, { product: product.id })
|
|
455
|
+
);
|
|
456
|
+
written.push(join3(dir, `${name}.ts`));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (written.length) io.out(`Typed client: ${written.join(", ")}`);
|
|
460
|
+
return written;
|
|
461
|
+
}
|
|
462
|
+
async function typeErrors(root, product) {
|
|
463
|
+
const apps = [product.web?.dir, product.mobile?.dir].filter((d) => Boolean(d));
|
|
464
|
+
const errors = [];
|
|
465
|
+
let ts;
|
|
466
|
+
try {
|
|
467
|
+
ts = (await import("typescript")).default;
|
|
468
|
+
} catch {
|
|
469
|
+
throw new CliError("TypeScript is not installed here: pnpm add -D typescript");
|
|
470
|
+
}
|
|
471
|
+
for (const app of apps) {
|
|
472
|
+
const config = join3(root, app, "tsconfig.json");
|
|
473
|
+
if (!existsSync3(config)) continue;
|
|
474
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(
|
|
475
|
+
config,
|
|
476
|
+
{},
|
|
477
|
+
{
|
|
478
|
+
...ts.sys,
|
|
479
|
+
onUnRecoverableConfigFileDiagnostic: () => {
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
if (!parsed) continue;
|
|
484
|
+
const program = ts.createProgram(parsed.fileNames, { ...parsed.options, noEmit: true });
|
|
485
|
+
for (const d of ts.getPreEmitDiagnostics(program)) {
|
|
486
|
+
if (d.category !== ts.DiagnosticCategory.Error) continue;
|
|
487
|
+
const where = d.file ? `${relative2(root, d.file.fileName)}:${d.file.getLineAndCharacterOfPosition(d.start ?? 0).line + 1}` : app;
|
|
488
|
+
errors.push(`${where}: ${ts.flattenDiagnosticMessageText(d.messageText, "\n")}`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return errors;
|
|
492
|
+
}
|
|
493
|
+
function writeSkills(root, kit) {
|
|
494
|
+
let count = 0;
|
|
495
|
+
for (const [path, bytes] of kit) {
|
|
496
|
+
if (!path.startsWith(KIT.skills)) continue;
|
|
497
|
+
const target = join3(root, "skills", path.slice(KIT.skills.length));
|
|
498
|
+
mkdirSync2(dirname3(target), { recursive: true });
|
|
499
|
+
writeFileSync3(target, bytes);
|
|
500
|
+
count += 1;
|
|
501
|
+
}
|
|
502
|
+
return count;
|
|
503
|
+
}
|
|
504
|
+
function render(text, values) {
|
|
505
|
+
return text.replaceAll("{{id}}", values.id).replaceAll("{{label}}", values.label).replaceAll("{{version}}", values.version).replaceAll("{{release}}", values.release).replaceAll("{{repository}}", values.repository);
|
|
506
|
+
}
|
|
507
|
+
function appPackage(text, name, version) {
|
|
508
|
+
const pkg = JSON.parse(text);
|
|
509
|
+
pkg.name = name;
|
|
510
|
+
delete pkg.description;
|
|
511
|
+
for (const key of ["dependencies", "devDependencies"]) {
|
|
512
|
+
const deps = pkg[key];
|
|
513
|
+
for (const [dep, range] of Object.entries(deps ?? {})) {
|
|
514
|
+
if (range.startsWith("workspace:")) deps[dep] = version;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
518
|
+
`;
|
|
519
|
+
}
|
|
520
|
+
function templateFiles(kit, values) {
|
|
521
|
+
const files = /* @__PURE__ */ new Map();
|
|
522
|
+
for (const [path, bytes] of kit) {
|
|
523
|
+
if (!path.startsWith(KIT.template)) continue;
|
|
524
|
+
let rel = path.slice(KIT.template.length);
|
|
525
|
+
let text = decode2(bytes);
|
|
526
|
+
if (/(^|\/)src\/client\/customer\.ts$/.test(rel)) continue;
|
|
527
|
+
if (rel.endsWith(".template")) {
|
|
528
|
+
rel = rel.slice(0, -".template".length);
|
|
529
|
+
if (basename(rel) === "gitignore") rel = join3(dirname3(rel), ".gitignore");
|
|
530
|
+
text = render(text, values);
|
|
531
|
+
}
|
|
532
|
+
const app = /^apps\/([^/]+)\/(package\.json|wrangler\.jsonc)$/.exec(rel);
|
|
533
|
+
if (app?.[2] === "package.json")
|
|
534
|
+
text = appPackage(text, `${values.id}-${app[1]}`, values.version);
|
|
535
|
+
if (rel === "apps/mobile/app.json") {
|
|
536
|
+
const config = JSON.parse(text);
|
|
537
|
+
config.expo = { ...config.expo, name: values.label, slug: values.id, scheme: values.id };
|
|
538
|
+
text = `${JSON.stringify(config, null, 2)}
|
|
539
|
+
`;
|
|
540
|
+
}
|
|
541
|
+
if (app?.[2] === "wrangler.jsonc") {
|
|
542
|
+
text = text.replace(/"name":\s*"client-web"/, `"name": "${values.id}-web"`).replace(/"service":\s*"cos-app"/, `"service": "${values.appWorker}"`);
|
|
543
|
+
}
|
|
544
|
+
files.set(rel.replace(/^\.\//, ""), text);
|
|
545
|
+
}
|
|
546
|
+
return files;
|
|
547
|
+
}
|
|
548
|
+
function slug(name) {
|
|
549
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
550
|
+
}
|
|
551
|
+
async function create(argv, flags, deps) {
|
|
552
|
+
const { io } = deps;
|
|
553
|
+
const target = argv[0];
|
|
554
|
+
if (!target) throw new CliError("Usage: cos create <dir> [--version x.y.z] [--label <name>]");
|
|
555
|
+
const root = resolve(target);
|
|
556
|
+
if (existsSync3(root) && readdirSync(root).length) {
|
|
557
|
+
throw new CliError(
|
|
558
|
+
`${target} is not empty. cos create starts a new repo; cos init adopts one.`
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
const id = str(flags, "id") ?? slug(basename(root));
|
|
562
|
+
const releaseId = str(flags, "release") ?? deps.products?.default ?? DEFAULT_PRODUCT;
|
|
563
|
+
const { kit, version, release } = await fetchKit(
|
|
564
|
+
flags,
|
|
565
|
+
deps,
|
|
566
|
+
releaseId,
|
|
567
|
+
str(flags, "repo"),
|
|
568
|
+
str(flags, "version")
|
|
569
|
+
);
|
|
570
|
+
const values = {
|
|
571
|
+
id,
|
|
572
|
+
label: str(flags, "label") ?? id.replace(
|
|
573
|
+
/(^|-)([a-z])/g,
|
|
574
|
+
(_m, s, c) => `${s ? " " : ""}${c.toUpperCase()}`
|
|
575
|
+
),
|
|
576
|
+
version,
|
|
577
|
+
release: release.id,
|
|
578
|
+
repository: str(flags, "repo") ?? release.updateRepository,
|
|
579
|
+
// The host is named for the product (issue #155): `cos deploy` installs it as <id>-app.
|
|
580
|
+
appWorker: `${id}-app`
|
|
581
|
+
};
|
|
582
|
+
const files = templateFiles(kit, values);
|
|
583
|
+
const mobile = Boolean(flags["with-mobile"]);
|
|
584
|
+
for (const path of [...files.keys()])
|
|
585
|
+
if (!mobile && path.startsWith("apps/mobile/")) files.delete(path);
|
|
586
|
+
if (mobile) {
|
|
587
|
+
const product2 = files.get("product.ts");
|
|
588
|
+
files.set(
|
|
589
|
+
"product.ts",
|
|
590
|
+
product2.replace(/(\n\s*web: \{[^\n]*\},)/, '$1\n mobile: { dir: "apps/mobile" },')
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
for (const [path, text] of files) {
|
|
594
|
+
mkdirSync2(dirname3(join3(root, path)), { recursive: true });
|
|
595
|
+
writeFileSync3(join3(root, path), text);
|
|
596
|
+
}
|
|
597
|
+
const skills = writeSkills(root, kit);
|
|
598
|
+
const product = await loadClientProduct(root);
|
|
599
|
+
await generateClients(root, product, kit, io);
|
|
600
|
+
recordHostModules(root, product, kit, version);
|
|
601
|
+
try {
|
|
602
|
+
execFileSync("git", ["init", "-q"], { cwd: root, stdio: "ignore" });
|
|
603
|
+
} catch {
|
|
604
|
+
}
|
|
605
|
+
io.out(
|
|
606
|
+
`Created ${values.label} in ${target}: ${files.size} files and ${skills} skills from ${release.label} ${version}.`
|
|
607
|
+
);
|
|
608
|
+
io.out(`
|
|
609
|
+
Next:
|
|
610
|
+
cd ${target}
|
|
611
|
+
pnpm install
|
|
612
|
+
pnpm cos deploy
|
|
613
|
+
|
|
614
|
+
${edgeRuleStep(product)}`);
|
|
615
|
+
return 0;
|
|
616
|
+
}
|
|
617
|
+
function readIf(path) {
|
|
618
|
+
return existsSync3(path) ? readFileSync3(path, "utf8") : null;
|
|
619
|
+
}
|
|
620
|
+
function withDependencies(text, key, entries) {
|
|
621
|
+
const pkg = JSON.parse(text);
|
|
622
|
+
const deps = { ...pkg[key] ?? {} };
|
|
623
|
+
let changed = false;
|
|
624
|
+
for (const [name, range] of Object.entries(entries)) {
|
|
625
|
+
if (!deps[name]) {
|
|
626
|
+
deps[name] = range;
|
|
627
|
+
changed = true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (!changed) return text;
|
|
631
|
+
pkg[key] = Object.fromEntries(Object.entries(deps).sort(([a], [b]) => a.localeCompare(b)));
|
|
632
|
+
const indent = /^\s+/m.exec(text.split("\n")[1] ?? " ")?.[0] ?? " ";
|
|
633
|
+
return `${JSON.stringify(pkg, null, indent)}
|
|
634
|
+
`;
|
|
635
|
+
}
|
|
636
|
+
function withTsExtensions(text) {
|
|
637
|
+
let config;
|
|
638
|
+
try {
|
|
639
|
+
config = JSON.parse(text);
|
|
640
|
+
} catch {
|
|
641
|
+
return text;
|
|
642
|
+
}
|
|
643
|
+
const options = config.compilerOptions ?? {};
|
|
644
|
+
if (options.allowImportingTsExtensions === true && options.noEmit === true) return text;
|
|
645
|
+
config.compilerOptions = { ...options, allowImportingTsExtensions: true, noEmit: true };
|
|
646
|
+
const indent = /^\s+/m.exec(text.split("\n")[1] ?? " ")?.[0] ?? " ";
|
|
647
|
+
return `${JSON.stringify(config, null, indent)}
|
|
648
|
+
`;
|
|
649
|
+
}
|
|
650
|
+
function closingBrace(text, open) {
|
|
651
|
+
let depth = 0;
|
|
652
|
+
for (let i = open; i < text.length; i++) {
|
|
653
|
+
const c = text[i];
|
|
654
|
+
if (c === '"') {
|
|
655
|
+
for (i++; i < text.length && text[i] !== '"'; i++) if (text[i] === "\\") i++;
|
|
656
|
+
} else if (c === "/" && text[i + 1] === "/") {
|
|
657
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
658
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
659
|
+
i = text.indexOf("*/", i + 2) + 1;
|
|
660
|
+
if (i <= 0) return -1;
|
|
661
|
+
} else if (c === "{") depth++;
|
|
662
|
+
else if (c === "}" && --depth === 0) return i;
|
|
663
|
+
}
|
|
664
|
+
return -1;
|
|
665
|
+
}
|
|
666
|
+
function withEnvBinding(path, text, env, service) {
|
|
667
|
+
const entry = `{ "binding": "HOST", "service": "${service}", "entrypoint": "ClientApp" }`;
|
|
668
|
+
if (path.endsWith(".toml")) {
|
|
669
|
+
if (!new RegExp(`^\\[env\\.${env}\\]`, "m").test(text)) return null;
|
|
670
|
+
if (new RegExp(`\\[\\[env\\.${env}\\.services\\]\\][^[]*binding\\s*=\\s*"HOST"`).test(text))
|
|
671
|
+
return text;
|
|
672
|
+
return `${text.trimEnd()}
|
|
673
|
+
|
|
674
|
+
# The ${env} host (Composable OS): customers and the public, over the ClientApp entrypoint.
|
|
675
|
+
[[env.${env}.services]]
|
|
676
|
+
binding = "HOST"
|
|
677
|
+
service = "${service}"
|
|
678
|
+
entrypoint = "ClientApp"
|
|
679
|
+
`;
|
|
680
|
+
}
|
|
681
|
+
const envKey = /"env"\s*:\s*\{/.exec(text);
|
|
682
|
+
if (!envKey) return null;
|
|
683
|
+
const envOpen = envKey.index + envKey[0].length - 1;
|
|
684
|
+
const envClose = closingBrace(text, envOpen);
|
|
685
|
+
const named = new RegExp(`"${env}"\\s*:\\s*\\{`).exec(text.slice(envOpen, envClose));
|
|
686
|
+
if (!named) return null;
|
|
687
|
+
const open = envOpen + named.index + named[0].length - 1;
|
|
688
|
+
const close = closingBrace(text, open);
|
|
689
|
+
const block = text.slice(open, close);
|
|
690
|
+
if (/"HOST"/.test(block) && block.includes("ClientApp")) return text;
|
|
691
|
+
const services = /"services"\s*:\s*\[/.exec(block);
|
|
692
|
+
if (services) {
|
|
693
|
+
const at = open + services.index + services[0].length;
|
|
694
|
+
return `${text.slice(0, at)}${entry}, ${text.slice(at)}`;
|
|
695
|
+
}
|
|
696
|
+
const body = text.slice(open + 1, close).trim();
|
|
697
|
+
const indent = /\n([ \t]*)\S/.exec(text.slice(open, close))?.[1] ?? " ";
|
|
698
|
+
return `${text.slice(0, open + 1)}
|
|
699
|
+
${indent}"services": [${entry}]${body ? "," : ""}${text.slice(open + 1)}`;
|
|
700
|
+
}
|
|
701
|
+
function wranglerConfig(dir) {
|
|
702
|
+
for (const name of ["wrangler.jsonc", "wrangler.json", "wrangler.toml"]) {
|
|
703
|
+
if (existsSync3(join3(dir, name))) return join3(dir, name);
|
|
704
|
+
}
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
async function init(flags, deps) {
|
|
708
|
+
const { io } = deps;
|
|
709
|
+
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
710
|
+
if (existsSync3(join3(root, "product.ts"))) {
|
|
711
|
+
throw new CliError("This repo already has a product.ts: it is adopted. Use cos upgrade.");
|
|
712
|
+
}
|
|
713
|
+
const id = str(flags, "id") ?? slug(basename(root));
|
|
714
|
+
const ask = async (question, found) => {
|
|
715
|
+
if (flags.yes || !io.interactive) return found ?? "";
|
|
716
|
+
return (await io.ask(`${question} (empty for none)`, { default: found ?? "" })).trim();
|
|
717
|
+
};
|
|
718
|
+
const guessWeb = wranglerConfig(root) ? "." : void 0;
|
|
719
|
+
const guessMobile = ["mobile", "app", "apps/mobile"].find(
|
|
720
|
+
(d) => existsSync3(join3(root, d, "app.json"))
|
|
721
|
+
);
|
|
722
|
+
const webDir = str(flags, "web") ?? await ask("Where is the web app (its Worker)?", guessWeb);
|
|
723
|
+
const mobileDir = str(flags, "mobile") ?? await ask("Where is the mobile app?", guessMobile);
|
|
724
|
+
const releaseId = str(flags, "release") ?? deps.products?.default ?? DEFAULT_PRODUCT;
|
|
725
|
+
const { kit, version, release } = await fetchKit(
|
|
726
|
+
flags,
|
|
727
|
+
deps,
|
|
728
|
+
releaseId,
|
|
729
|
+
str(flags, "repo"),
|
|
730
|
+
str(flags, "version")
|
|
731
|
+
);
|
|
732
|
+
const repository = str(flags, "repo") ?? release.updateRepository;
|
|
733
|
+
const clientDir = "src/composable-os";
|
|
734
|
+
const webConfig = webDir ? wranglerConfig(join3(root, webDir)) : null;
|
|
735
|
+
const existingName = webConfig ? /"?name"?\s*[:=]\s*"([a-z0-9-]+)"/.exec(readFileSync3(webConfig, "utf8"))?.[1] : void 0;
|
|
736
|
+
const list = (flag) => (str(flags, flag) ?? "").split(",").map((p) => p.trim()).filter(Boolean);
|
|
737
|
+
const packs = list("packs");
|
|
738
|
+
const carried = kitPacks(kit);
|
|
739
|
+
const unknown = packs.filter((p) => !carried.has(p));
|
|
740
|
+
if (unknown.length) {
|
|
741
|
+
throw new CliError(
|
|
742
|
+
`${release.label} ${version} does not carry the pack${unknown.length > 1 ? "s" : ""} ${unknown.join(", ")} (it carries ${[...carried].sort().join(", ") || "none"}). Nothing was written.`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
const envs = list("envs");
|
|
746
|
+
const product = {
|
|
747
|
+
id,
|
|
748
|
+
label: str(flags, "label") ?? id,
|
|
749
|
+
platform: { version, release: release.id, repository },
|
|
750
|
+
packs,
|
|
751
|
+
...envs.length ? { environments: Object.fromEntries(envs.map((e) => [e, {}])) } : {},
|
|
752
|
+
...webDir ? {
|
|
753
|
+
web: {
|
|
754
|
+
dir: webDir,
|
|
755
|
+
worker: existingName ?? `${id}-web`,
|
|
756
|
+
clientDir,
|
|
757
|
+
deploy: "own",
|
|
758
|
+
// The routes the site serves to reach the host: what the edge rule names.
|
|
759
|
+
...str(flags, "sign-in-route") || str(flags, "operation-route") ? {
|
|
760
|
+
routes: {
|
|
761
|
+
...str(flags, "sign-in-route") ? { signIn: str(flags, "sign-in-route") } : {},
|
|
762
|
+
...str(flags, "operation-route") ? { operations: str(flags, "operation-route") } : {}
|
|
763
|
+
}
|
|
764
|
+
} : {}
|
|
765
|
+
}
|
|
766
|
+
} : {},
|
|
767
|
+
...mobileDir ? { mobile: { dir: mobileDir, clientDir } } : {}
|
|
768
|
+
};
|
|
769
|
+
const productText = `// This product: what the host is deployed from, which packs are on, and where the apps are.
|
|
770
|
+
// Added by cos init; cos deploy reads it and cos upgrade moves platform.version. See AGENTS.md.
|
|
771
|
+
import { defineClientProduct } from "@composable-os/product";
|
|
772
|
+
|
|
773
|
+
export const product = defineClientProduct(${JSON.stringify(product, null, 2)});
|
|
774
|
+
`;
|
|
775
|
+
writeFileSync3(join3(root, "product.ts"), productText);
|
|
776
|
+
const added = ["product.ts"];
|
|
777
|
+
const skills = writeSkills(root, kit);
|
|
778
|
+
added.push(`skills/ (${skills} skills)`);
|
|
779
|
+
added.push(...await generateClients(root, defineClientProduct(product), kit, io));
|
|
780
|
+
const hostModules = [
|
|
781
|
+
[webDir, "web", ["host.ts"]],
|
|
782
|
+
[mobileDir, "mobile", ["host.ts", "secure-store.ts", "secure-random.ts"]]
|
|
783
|
+
];
|
|
784
|
+
for (const [app, kind, files] of hostModules) {
|
|
785
|
+
if (!app) continue;
|
|
786
|
+
for (const file of files) {
|
|
787
|
+
const source = kit.get(`${KIT.template}apps/${kind}/src/${file}`);
|
|
788
|
+
const target = join3(root, app, clientDir, file);
|
|
789
|
+
if (!source || existsSync3(target)) continue;
|
|
790
|
+
writeFileSync3(target, decode2(source).replaceAll("./client/customer.ts", "./customer.ts"));
|
|
791
|
+
added.push(join3(app, clientDir, file));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
recordHostModules(root, defineClientProduct(product), kit, version);
|
|
795
|
+
added.push(STATE_FILE);
|
|
796
|
+
const changes = [];
|
|
797
|
+
const consider = (path, after) => {
|
|
798
|
+
const full = join3(root, path);
|
|
799
|
+
const before = readIf(full);
|
|
800
|
+
const next = after(before);
|
|
801
|
+
if (before === null) {
|
|
802
|
+
writeFileSync3(full, next);
|
|
803
|
+
added.push(path);
|
|
804
|
+
} else if (next !== before) changes.push({ path, before, after: next });
|
|
805
|
+
};
|
|
806
|
+
const rules = decode2(kit.get(`${KIT.template}AGENTS.md`) ?? new Uint8Array());
|
|
807
|
+
consider(
|
|
808
|
+
"AGENTS.md",
|
|
809
|
+
(before) => before === null ? rules : before.includes("composable-os: client repo rules") ? before : `${before.trimEnd()}
|
|
810
|
+
|
|
811
|
+
${rules}`
|
|
812
|
+
);
|
|
813
|
+
consider(
|
|
814
|
+
"package.json",
|
|
815
|
+
(before) => withDependencies(before ?? `{ "name": "${id}", "private": true }
|
|
816
|
+
`, "devDependencies", {
|
|
817
|
+
"@composable-os/cli": version,
|
|
818
|
+
"@composable-os/product": version
|
|
819
|
+
})
|
|
820
|
+
);
|
|
821
|
+
const mobileTemplate = kit.get(`${KIT.template}apps/mobile/package.json`);
|
|
822
|
+
const mobileDeps = mobileTemplate ? JSON.parse(decode2(mobileTemplate)).dependencies ?? {} : {};
|
|
823
|
+
for (const app of [webDir, mobileDir].filter((d) => Boolean(d))) {
|
|
824
|
+
if (!existsSync3(join3(root, app, "package.json"))) continue;
|
|
825
|
+
const needs = { "@composable-os/client": version };
|
|
826
|
+
if (app === mobileDir) {
|
|
827
|
+
for (const name of ["expo-secure-store", "expo-crypto"]) {
|
|
828
|
+
const range = mobileDeps[name];
|
|
829
|
+
if (range) needs[name] = range;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (app === ".") {
|
|
833
|
+
const index = changes.findIndex((c) => c.path === "package.json");
|
|
834
|
+
const current = index >= 0 ? changes[index] : null;
|
|
835
|
+
const after = withDependencies(
|
|
836
|
+
current?.after ?? readFileSync3(join3(root, "package.json"), "utf8"),
|
|
837
|
+
"dependencies",
|
|
838
|
+
needs
|
|
839
|
+
);
|
|
840
|
+
const before = readFileSync3(join3(root, "package.json"), "utf8");
|
|
841
|
+
if (current) current.after = after;
|
|
842
|
+
else if (after !== before) changes.push({ path: "package.json", before, after });
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
consider(
|
|
846
|
+
join3(app, "package.json"),
|
|
847
|
+
(before) => withDependencies(before, "dependencies", needs)
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
if (mobileDir && existsSync3(join3(root, mobileDir, "tsconfig.json"))) {
|
|
851
|
+
consider(join3(mobileDir, "tsconfig.json"), (before) => withTsExtensions(before));
|
|
852
|
+
}
|
|
853
|
+
const members = [webDir, mobileDir].filter((d) => Boolean(d) && d !== ".");
|
|
854
|
+
if (members.length && !existsSync3(join3(root, "pnpm-workspace.yaml"))) {
|
|
855
|
+
writeFileSync3(
|
|
856
|
+
join3(root, "pnpm-workspace.yaml"),
|
|
857
|
+
`packages:
|
|
858
|
+
${members.map((m) => ` - ${m}
|
|
859
|
+
`).join("")}`
|
|
860
|
+
);
|
|
861
|
+
added.push("pnpm-workspace.yaml");
|
|
862
|
+
}
|
|
863
|
+
if (webDir) {
|
|
864
|
+
const config = webConfig;
|
|
865
|
+
const own = config ? OWN_RESOURCES.filter(
|
|
866
|
+
(key) => new RegExp(`"?${key}"?\\s*[:=]|\\[\\[${key}\\]\\]`).test(readFileSync3(config, "utf8"))
|
|
867
|
+
) : [];
|
|
868
|
+
if (own.length) {
|
|
869
|
+
io.out(
|
|
870
|
+
`Note: the web app has data of its own (${own.join(", ")}). It keeps them and keeps deploying itself (web.deploy "own"). Customers' records live in the host: what moves there, and when, is the company's decision, not an agent's.`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
const defined = defineClientProduct(product);
|
|
874
|
+
const later = [];
|
|
875
|
+
for (const env of envs.length ? envs : [void 0]) {
|
|
876
|
+
const host = clientNames(defined, env).app;
|
|
877
|
+
const text = config ? readFileSync3(config, "utf8") : null;
|
|
878
|
+
const under = config && text && env ? withEnvBinding(config, text, env, host) : null;
|
|
879
|
+
if (config && under !== null) {
|
|
880
|
+
const path = relative2(root, config);
|
|
881
|
+
const pending = changes.find((c) => c.path === path);
|
|
882
|
+
if (pending)
|
|
883
|
+
pending.after = withEnvBinding(config, pending.after, env, host) ?? pending.after;
|
|
884
|
+
else if (under !== text) changes.push({ path, before: text, after: under });
|
|
885
|
+
} else {
|
|
886
|
+
later.push(
|
|
887
|
+
` ${env ? `${env}: ` : ""}${hostBindingText(host, env)}${config ? "" : ` (no wrangler config in ${webDir})`}`
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (later.length) {
|
|
892
|
+
io.out(
|
|
893
|
+
`
|
|
894
|
+
The site's Worker config needs the HOST binding${envs.length > 1 ? " in each environment" : ""}. Add it only after cos deploy${envs.length ? " --env <name>" : ""} has made that host, before the site's next deploy:
|
|
895
|
+
${later.join("\n")}`
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (!existsSync3(join3(root, "package.json"))) added.push("package.json");
|
|
900
|
+
io.out(`Added: ${added.join(", ")}`);
|
|
901
|
+
for (const change of changes) {
|
|
902
|
+
io.out(`
|
|
903
|
+
--- ${change.path}
|
|
904
|
+
+++ ${change.path} (cos init)`);
|
|
905
|
+
for (const line of lineDiff(change.before, change.after)) io.out(line);
|
|
906
|
+
}
|
|
907
|
+
if (changes.length) {
|
|
908
|
+
const apply = Boolean(flags.yes) || io.interactive && /^y/i.test(await io.ask("Apply these changes? (y/N)", { default: "n" }));
|
|
909
|
+
if (apply) {
|
|
910
|
+
for (const change of changes) writeFileSync3(join3(root, change.path), change.after);
|
|
911
|
+
io.out(`
|
|
912
|
+
Changed: ${changes.map((c) => c.path).join(", ")}`);
|
|
913
|
+
} else {
|
|
914
|
+
io.out("\nNot changed. Apply the diffs above by hand, or run cos init again with --yes.");
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
io.out(`
|
|
918
|
+
Next: pnpm install, then pnpm cos deploy.
|
|
919
|
+
|
|
920
|
+
${edgeRuleStep(product)}`);
|
|
921
|
+
return 0;
|
|
922
|
+
}
|
|
923
|
+
function orgExtensionSources(root) {
|
|
924
|
+
const SKIP = /* @__PURE__ */ new Set(["node_modules", "test", "tests", "dist", ".turbo"]);
|
|
925
|
+
const files = (dir, base, out) => {
|
|
926
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
927
|
+
const path = join3(dir, entry.name);
|
|
928
|
+
if (entry.isDirectory()) {
|
|
929
|
+
if (!SKIP.has(entry.name)) files(path, base, out);
|
|
930
|
+
} else if (/\.(ts|js)$/.test(entry.name) && !/\.(test|config)\.(ts|js)$/.test(entry.name)) {
|
|
931
|
+
out[relative2(base, path).split("\\").join("/")] = readFileSync3(path, "utf8");
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return out;
|
|
935
|
+
};
|
|
936
|
+
return orgExtensionDirs(root).map((dir) => {
|
|
937
|
+
const pkg = existsSync3(join3(dir, "package.json")) ? JSON.parse(readFileSync3(join3(dir, "package.json"), "utf8")) : {};
|
|
938
|
+
return { id: basename(dir), version: pkg.version ?? "0.0.0", files: files(dir, dir, {}) };
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
async function checkOrgExtensions(root, io) {
|
|
942
|
+
const dirs = orgExtensionDirs(root);
|
|
943
|
+
if (!dirs.length) return true;
|
|
944
|
+
const { runExt } = await import("./cli-UYZMVQMR.js");
|
|
945
|
+
let ok = true;
|
|
946
|
+
for (const dir of dirs) {
|
|
947
|
+
io.out(`cos ext check ${relative2(root, dir)}`);
|
|
948
|
+
if (await runExt(["check", dir], io) !== 0) ok = false;
|
|
949
|
+
}
|
|
950
|
+
return ok;
|
|
951
|
+
}
|
|
952
|
+
function walkFiles(dir, base = dir) {
|
|
953
|
+
const out = [];
|
|
954
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
955
|
+
const path = join3(dir, entry.name);
|
|
956
|
+
if (entry.isDirectory()) out.push(...walkFiles(path, base));
|
|
957
|
+
else out.push(relative2(base, path).split("\\").join("/"));
|
|
958
|
+
}
|
|
959
|
+
return out;
|
|
960
|
+
}
|
|
961
|
+
var OWN_RESOURCES = [
|
|
962
|
+
"d1_databases",
|
|
963
|
+
"r2_buckets",
|
|
964
|
+
"kv_namespaces",
|
|
965
|
+
"queues",
|
|
966
|
+
"vectorize",
|
|
967
|
+
"hyperdrive"
|
|
968
|
+
];
|
|
969
|
+
function buildWeb(root, product, flags, io) {
|
|
970
|
+
const web = product.web;
|
|
971
|
+
const dir = join3(root, web.dir);
|
|
972
|
+
if (!flags["skip-build"]) {
|
|
973
|
+
io.out(`Building ${web.dir}\u2026`);
|
|
974
|
+
execFileSync("pnpm", ["run", "build"], { cwd: dir, stdio: "inherit" });
|
|
975
|
+
}
|
|
976
|
+
const out = join3(dir, "dist", "server");
|
|
977
|
+
const configPath = join3(out, "wrangler.json");
|
|
978
|
+
if (!existsSync3(configPath))
|
|
979
|
+
throw new CliError(
|
|
980
|
+
`No build at ${relative2(root, out)}/wrangler.json. cos deploy uploads a web app built the way the template's is (TanStack Start with the Cloudflare Vite plugin). A web app that deploys itself (an adopted site) sets web.deploy: "own" in product.ts. Nothing was deployed.`
|
|
981
|
+
);
|
|
982
|
+
const config = JSON.parse(readFileSync3(configPath, "utf8"));
|
|
983
|
+
for (const key of OWN_RESOURCES) {
|
|
984
|
+
if (Array.isArray(config[key]) && config[key].length) {
|
|
985
|
+
throw new CliError(
|
|
986
|
+
`The web app has its own ${key}: a client app reaches the host only through HOST and never opens a database (AGENTS.md).`
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
const services = config.services ?? [];
|
|
991
|
+
if (services.some((s) => s.binding !== "HOST")) {
|
|
992
|
+
throw new CliError("The web app may have one service binding, HOST, to the host.");
|
|
993
|
+
}
|
|
994
|
+
return { out, config };
|
|
995
|
+
}
|
|
996
|
+
async function deployWeb(api, accountId, web, host, { out, config }) {
|
|
997
|
+
const modules = walkFiles(out).filter((f) => f !== "wrangler.json" && !f.endsWith(".map") && !f.startsWith(".")).map((name) => ({
|
|
998
|
+
name,
|
|
999
|
+
type: /\.(m?js)$/.test(name) ? "esm" : "text",
|
|
1000
|
+
bytes: new Uint8Array(readFileSync3(join3(out, name)))
|
|
1001
|
+
}));
|
|
1002
|
+
const main = String(config.main ?? "index.js");
|
|
1003
|
+
let assetsJwt;
|
|
1004
|
+
const assetsDir = config.assets?.directory;
|
|
1005
|
+
if (assetsDir && existsSync3(join3(out, assetsDir))) {
|
|
1006
|
+
const base = join3(out, assetsDir);
|
|
1007
|
+
const manifest = {};
|
|
1008
|
+
const bytesOf = /* @__PURE__ */ new Map();
|
|
1009
|
+
for (const file of walkFiles(base).filter((f) => !f.startsWith("."))) {
|
|
1010
|
+
const bytes = new Uint8Array(readFileSync3(join3(base, file)));
|
|
1011
|
+
const hash = await assetHash(bytes, `/${file}`);
|
|
1012
|
+
manifest[`/${file}`] = { hash, size: bytes.length };
|
|
1013
|
+
bytesOf.set(hash, bytes);
|
|
1014
|
+
}
|
|
1015
|
+
const session = await api.assetsUploadSession(accountId, web.worker, manifest);
|
|
1016
|
+
const pathOf = new Map(Object.entries(manifest).map(([p, f]) => [f.hash, p]));
|
|
1017
|
+
assetsJwt = session.buckets?.length ? void 0 : session.jwt;
|
|
1018
|
+
for (const bucket of session.buckets ?? []) {
|
|
1019
|
+
const token = await api.uploadAssets(
|
|
1020
|
+
accountId,
|
|
1021
|
+
session.jwt,
|
|
1022
|
+
bucket.map((hash) => ({
|
|
1023
|
+
hash,
|
|
1024
|
+
base64: toBase64(bytesOf.get(hash)),
|
|
1025
|
+
contentType: contentTypeOf(pathOf.get(hash) ?? "")
|
|
1026
|
+
}))
|
|
1027
|
+
);
|
|
1028
|
+
if (token) assetsJwt = token;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
const metadata = {
|
|
1032
|
+
main_module: main,
|
|
1033
|
+
compatibility_date: config.compatibility_date ?? "2026-10-01",
|
|
1034
|
+
compatibility_flags: config.compatibility_flags ?? ["nodejs_compat"],
|
|
1035
|
+
bindings: [{ type: "service", name: "HOST", service: host, entrypoint: "ClientApp" }],
|
|
1036
|
+
...assetsJwt ? { assets: { jwt: assetsJwt } } : {}
|
|
1037
|
+
};
|
|
1038
|
+
await api.putScript(accountId, web.worker, metadata, modules);
|
|
1039
|
+
if (web.hostname) {
|
|
1040
|
+
const zones = await api.listZones(accountId);
|
|
1041
|
+
const zone = zones.filter((z) => web.hostname === z.name || web.hostname?.endsWith(`.${z.name}`)).sort((a, b) => b.name.length - a.name.length)[0];
|
|
1042
|
+
if (!zone) throw new CliError(`No zone in this account covers ${web.hostname}.`);
|
|
1043
|
+
await api.putDomain(accountId, web.hostname, web.worker, zone.id);
|
|
1044
|
+
return `https://${web.hostname}`;
|
|
1045
|
+
}
|
|
1046
|
+
await api.setWorkersDev(accountId, web.worker, true);
|
|
1047
|
+
const sub = await api.workersSubdomain(accountId);
|
|
1048
|
+
return `https://${web.worker}.${sub ?? "<subdomain>"}.workers.dev`;
|
|
1049
|
+
}
|
|
1050
|
+
function blobsBucket(manifest, state) {
|
|
1051
|
+
const bucket = manifest.resources.find((r) => r.type === "r2" && r.name.endsWith("-blobs"));
|
|
1052
|
+
if (!bucket) throw new CliError("The release has no BLOBS bucket for the org's extensions.");
|
|
1053
|
+
return state.resourceNames?.[bucket.name] ?? bucket.name;
|
|
1054
|
+
}
|
|
1055
|
+
function chooseEnvironment(product, flag) {
|
|
1056
|
+
const envs = environmentNames(product);
|
|
1057
|
+
if (!envs.length) {
|
|
1058
|
+
if (flag) {
|
|
1059
|
+
throw new CliError(
|
|
1060
|
+
`product.ts declares no environments, so there is no ${flag}: leave out --env, or add environments to product.ts.`
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
return void 0;
|
|
1064
|
+
}
|
|
1065
|
+
if (flag) {
|
|
1066
|
+
if (!envs.includes(flag)) {
|
|
1067
|
+
throw new CliError(
|
|
1068
|
+
`product.ts has no environment ${flag}. Its environments: ${envs.join(", ")}.`
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
return flag;
|
|
1072
|
+
}
|
|
1073
|
+
if (envs.length === 1) return envs[0];
|
|
1074
|
+
throw new CliError(
|
|
1075
|
+
`product.ts has ${envs.length} environments: say which with --env (${envs.join(", ")}). Nothing was deployed.`
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
var IMPORT_LOOPBACK_REDIRECT = "http://127.0.0.1/cos-sign-in";
|
|
1079
|
+
function nativeRedirectUris(product, environment) {
|
|
1080
|
+
return [
|
|
1081
|
+
IMPORT_LOOPBACK_REDIRECT,
|
|
1082
|
+
...product.mobile ? [nativeRedirectUri(product, environment)] : []
|
|
1083
|
+
].join(",");
|
|
1084
|
+
}
|
|
1085
|
+
function nativeRedirectUri(product, environment) {
|
|
1086
|
+
const scheme = (environment ? product.environments?.[environment]?.mobile?.scheme : void 0) ?? product.mobile?.scheme ?? product.id;
|
|
1087
|
+
return `${scheme}://staff-sign-in`;
|
|
1088
|
+
}
|
|
1089
|
+
function gatekeeperPlan(manifest, product, environment) {
|
|
1090
|
+
const settings = gatekeeperSettings(product, environment);
|
|
1091
|
+
const where = environment ? `environment ${environment}` : "product.ts";
|
|
1092
|
+
const gatekeepers = manifest.workers.filter((w) => w.role === "gatekeeper");
|
|
1093
|
+
const workers = [];
|
|
1094
|
+
const vars = {};
|
|
1095
|
+
const sendEmail = {};
|
|
1096
|
+
for (const [short, values] of Object.entries(settings)) {
|
|
1097
|
+
const worker = gatekeepers.find((w) => w.shortName === short);
|
|
1098
|
+
if (!worker) {
|
|
1099
|
+
return {
|
|
1100
|
+
problem: `${where} names the gatekeeper ${short}, which this release does not have (it has ${gatekeepers.map((w) => w.shortName).join(", ")}).`
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
workers.push(worker);
|
|
1104
|
+
const declared = worker.bindings.filter((b) => b.type === "plain_text").map((b) => b.name).filter((name) => name !== "BASE_URL");
|
|
1105
|
+
const secrets = (worker.secrets ?? []).map((s) => s.name);
|
|
1106
|
+
for (const [key, value] of Object.entries(values ?? {})) {
|
|
1107
|
+
if (key === "sendEmail") {
|
|
1108
|
+
const email = worker.bindings.find((b) => b.type === "send_email");
|
|
1109
|
+
if (!email) return { problem: `${short} has no send_email binding to set.` };
|
|
1110
|
+
const v = value;
|
|
1111
|
+
sendEmail[worker.name] = {
|
|
1112
|
+
[email.name]: {
|
|
1113
|
+
...v.allowedSenderAddresses ? { allowed_sender_addresses: v.allowedSenderAddresses } : {},
|
|
1114
|
+
...v.destinationAddress ? { destination_address: v.destinationAddress } : {},
|
|
1115
|
+
...v.allowedDestinationAddresses ? { allowed_destination_addresses: v.allowedDestinationAddresses } : {}
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
if (secrets.includes(key)) {
|
|
1121
|
+
return {
|
|
1122
|
+
problem: `${key} is a secret of ${short}: it never goes in product.ts. Take it out, and set it with npx wrangler secret put ${key} --name <the deployed ${short} Worker>.`
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
if (key === "BASE_URL") {
|
|
1126
|
+
return {
|
|
1127
|
+
problem: `${short}'s BASE_URL is derived from the host's hostname: take it out of ${where}.`
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
if (!declared.includes(key)) {
|
|
1131
|
+
return {
|
|
1132
|
+
problem: `${short} takes no setting ${key}. It takes: ${declared.join(", ") || "none"}.`
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
vars[worker.name] = { ...vars[worker.name], [key]: String(value) };
|
|
1136
|
+
}
|
|
1137
|
+
if (vars[worker.name]?.PAYMENTS_FAKE_PROVIDER === "true" && isLiveEnvironment(product, environment)) {
|
|
1138
|
+
return {
|
|
1139
|
+
problem: `${where} is live and turns on the fake payment provider: only an environment marked live: false may.`
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return { workers, vars, sendEmail };
|
|
1144
|
+
}
|
|
1145
|
+
function hostBindingText(host, environment) {
|
|
1146
|
+
const entry = `{ "binding": "HOST", "service": "${host}", "entrypoint": "ClientApp" }`;
|
|
1147
|
+
return environment && environment !== LIVE_ENVIRONMENT ? `"env": { "${environment}": { "services": [${entry}] } } (TOML: [[env.${environment}.services]] binding = "HOST", service = "${host}", entrypoint = "ClientApp")` : `"services": [${entry}] (TOML: [[services]] binding = "HOST", service = "${host}", entrypoint = "ClientApp")`;
|
|
1148
|
+
}
|
|
1149
|
+
async function deploy(flags, deps) {
|
|
1150
|
+
const { io } = deps;
|
|
1151
|
+
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
1152
|
+
const product = await loadClientProduct(root);
|
|
1153
|
+
const environment = chooseEnvironment(product, str(flags, "env"));
|
|
1154
|
+
const envLabel = environment ? ` (${environment})` : "";
|
|
1155
|
+
const web = clientWeb(product, environment);
|
|
1156
|
+
if (!await checkOrgExtensions(root, io)) {
|
|
1157
|
+
io.err("An extension in extensions/ failed cos ext check: nothing was deployed.");
|
|
1158
|
+
return 1;
|
|
1159
|
+
}
|
|
1160
|
+
const errors = flags["no-typecheck"] ? [] : await typeErrors(root, product);
|
|
1161
|
+
if (errors.length) {
|
|
1162
|
+
for (const e of errors) io.err(e);
|
|
1163
|
+
io.err("The apps have type errors: nothing was deployed.");
|
|
1164
|
+
return 1;
|
|
1165
|
+
}
|
|
1166
|
+
const built = product.web && product.web.deploy !== "own" ? buildWeb(root, product, flags, io) : null;
|
|
1167
|
+
io.out(
|
|
1168
|
+
`Checked: ${orgExtensionDirs(root).length} extension(s) with cos ext check${flags["no-typecheck"] ? "" : ", the apps' types"}.`
|
|
1169
|
+
);
|
|
1170
|
+
const release = releaseProduct(deps, product.platform.release);
|
|
1171
|
+
const own = orgExtensionSources(root);
|
|
1172
|
+
for (const extension of own) {
|
|
1173
|
+
if (product.packs.includes(extension.id)) {
|
|
1174
|
+
throw new CliError(`extensions/${extension.id} has the id of a pack this product lists.`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const ownBytes = new TextEncoder().encode(JSON.stringify({ extensions: own }));
|
|
1178
|
+
const ownHash = own.length ? await sha256Hex(ownBytes) : "";
|
|
1179
|
+
const envSettings = environment ? product.environments?.[environment] : void 0;
|
|
1180
|
+
const hostFlags = {
|
|
1181
|
+
...flags,
|
|
1182
|
+
product: release.id,
|
|
1183
|
+
repo: product.platform.repository,
|
|
1184
|
+
version: product.platform.version,
|
|
1185
|
+
yes: flags.yes ?? true,
|
|
1186
|
+
packs: product.packs.join(","),
|
|
1187
|
+
"org-extensions": ownHash,
|
|
1188
|
+
...envSettings?.hostname && !str(flags, "hostname") ? { hostname: envSettings.hostname } : {}
|
|
1189
|
+
};
|
|
1190
|
+
const scoped = {
|
|
1191
|
+
...deps,
|
|
1192
|
+
products: { all: { [release.id]: release }, default: release.id }
|
|
1193
|
+
};
|
|
1194
|
+
const source = releaseSource(hostFlags, scoped, release);
|
|
1195
|
+
const { bundle } = await verified(source, product.platform.version, scoped);
|
|
1196
|
+
const manifest = bundle.manifest;
|
|
1197
|
+
const inRelease = kitPacks(bundle.clientFiles);
|
|
1198
|
+
const missing = product.packs.filter((pack) => !inRelease.has(pack));
|
|
1199
|
+
if (missing.length) {
|
|
1200
|
+
io.err(
|
|
1201
|
+
`${release.label} ${product.platform.version} does not carry the pack${missing.length > 1 ? "s" : ""} ${missing.join(", ")} that product.ts lists (it carries ${[...inRelease].sort().join(", ") || "none"}): the platform needs it in a release first. Nothing was deployed.`
|
|
1202
|
+
);
|
|
1203
|
+
return 1;
|
|
1204
|
+
}
|
|
1205
|
+
const gatekeepers = gatekeeperPlan(manifest, product, environment);
|
|
1206
|
+
if ("problem" in gatekeepers) {
|
|
1207
|
+
io.err(`${gatekeepers.problem} Nothing was deployed.`);
|
|
1208
|
+
return 1;
|
|
1209
|
+
}
|
|
1210
|
+
if (gatekeepers.workers.length) {
|
|
1211
|
+
hostFlags.gatekeepers = gatekeepers.workers.map((w) => w.name).join(",");
|
|
1212
|
+
hostFlags["gatekeeper-vars"] = JSON.stringify(gatekeepers.vars);
|
|
1213
|
+
if (Object.keys(gatekeepers.sendEmail).length) {
|
|
1214
|
+
hostFlags["send-email"] = JSON.stringify(gatekeepers.sendEmail);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
const token = str(flags, "token") ?? deps.env.CLOUDFLARE_API_TOKEN;
|
|
1218
|
+
if (!token)
|
|
1219
|
+
throw new CliError("A Cloudflare API token is needed: --token or CLOUDFLARE_API_TOKEN.");
|
|
1220
|
+
deps.redactor.add(token);
|
|
1221
|
+
const api = new CloudflareClient({
|
|
1222
|
+
token,
|
|
1223
|
+
...deps.env.COS_CLOUDFLARE_API ? { apiBase: deps.env.COS_CLOUDFLARE_API } : {},
|
|
1224
|
+
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
1225
|
+
});
|
|
1226
|
+
let accountId = str(flags, "account") ?? deps.env.CLOUDFLARE_ACCOUNT_ID;
|
|
1227
|
+
if (!accountId) {
|
|
1228
|
+
const accounts = await api.listAccounts();
|
|
1229
|
+
if (accounts.length !== 1) throw new CliError("Pass --account <id>.");
|
|
1230
|
+
accountId = accounts[0].id;
|
|
1231
|
+
}
|
|
1232
|
+
hostFlags.account = accountId;
|
|
1233
|
+
const names = clientNames(product, environment);
|
|
1234
|
+
const ownHost = await locateDeployment(api, accountId, names.database);
|
|
1235
|
+
const mayBeLegacy = environment === void 0 || environment === LIVE_ENVIRONMENT;
|
|
1236
|
+
const legacyHost = ownHost?.state || !mayBeLegacy ? null : await locateDeployment(api, accountId, release.names.database);
|
|
1237
|
+
const database = legacyHost?.state ? release.names.database : names.database;
|
|
1238
|
+
hostFlags.database = database;
|
|
1239
|
+
hostFlags.label = product.label;
|
|
1240
|
+
if (!ownHost?.state && !legacyHost?.state) {
|
|
1241
|
+
hostFlags.names = JSON.stringify(clientNameMaps(release, names, manifest));
|
|
1242
|
+
}
|
|
1243
|
+
const deployedWorker = (name) => (ownHost?.state ?? legacyHost?.state)?.workerNames[name] ?? (legacyHost?.state ? name : clientNameMaps(release, names, manifest).workers[name] ?? name);
|
|
1244
|
+
const hostWorker = deployedWorker(appWorker(manifest));
|
|
1245
|
+
let webOrigin;
|
|
1246
|
+
if (web) {
|
|
1247
|
+
webOrigin = web.hostname ? `https://${web.hostname}` : `https://${web.worker}.${await api.workersSubdomain(accountId) ?? "<subdomain>"}.workers.dev`;
|
|
1248
|
+
hostFlags["customer-auth-url"] = webOrigin;
|
|
1249
|
+
}
|
|
1250
|
+
hostFlags["native-redirect-uris"] = nativeRedirectUris(product, environment);
|
|
1251
|
+
const found = ownHost?.state ? ownHost : legacyHost;
|
|
1252
|
+
if (found?.state && found.state.version !== product.platform.version) {
|
|
1253
|
+
io.out(
|
|
1254
|
+
`The host${envLabel} is on ${found.state.version}; moving it to ${product.platform.version}.`
|
|
1255
|
+
);
|
|
1256
|
+
const code2 = await upgrade({ ...hostFlags }, scoped);
|
|
1257
|
+
if (code2 !== 0) return code2;
|
|
1258
|
+
}
|
|
1259
|
+
const code = await install(hostFlags, scoped);
|
|
1260
|
+
if (code !== 0) return code;
|
|
1261
|
+
if (own.length) {
|
|
1262
|
+
const located = await locateDeployment(api, accountId, database);
|
|
1263
|
+
if (!located?.state) throw new CliError("The host's deployment state is missing.");
|
|
1264
|
+
const bucket = blobsBucket(manifest, located.state);
|
|
1265
|
+
await api.putR2Object(accountId, bucket, `org-extensions/${ownHash}.json`, ownBytes);
|
|
1266
|
+
io.out(`Org extensions: ${own.map((e) => e.id).join(", ")} (${ownHash.slice(0, 12)}\u2026)`);
|
|
1267
|
+
}
|
|
1268
|
+
for (const worker of gatekeepers.workers) {
|
|
1269
|
+
const deployedAs = deployedWorker(worker.name);
|
|
1270
|
+
const set = await api.listSecrets(accountId, deployedAs);
|
|
1271
|
+
const missing2 = (worker.secrets ?? []).filter(
|
|
1272
|
+
(s) => s.source !== "generated" && !set.includes(s.name)
|
|
1273
|
+
);
|
|
1274
|
+
if (!missing2.length) continue;
|
|
1275
|
+
io.out(`
|
|
1276
|
+
${deployedAs} has no ${missing2.map((s) => s.name).join(", ")}. A person sets each:`);
|
|
1277
|
+
for (const secret of missing2) {
|
|
1278
|
+
io.out(
|
|
1279
|
+
` npx wrangler secret put ${secret.name} --name ${deployedAs}${secret.description ? `
|
|
1280
|
+
(${secret.description})` : ""}`
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
if (built && web) {
|
|
1285
|
+
const url = await deployWeb(api, accountId, web, hostWorker, built);
|
|
1286
|
+
io.out(`Web app${envLabel}: ${url}, bound to ${hostWorker} (ClientApp).`);
|
|
1287
|
+
} else if (product.web?.deploy === "own" && web) {
|
|
1288
|
+
io.out(
|
|
1289
|
+
`Web app${envLabel}: ${product.web.dir} deploys itself (web.deploy "own"): deploy it as you do today.
|
|
1290
|
+
Its Worker (${web.worker})${environment ? ` in its ${environment} environment` : ""} needs this service binding, now that the host exists:
|
|
1291
|
+
${hostBindingText(hostWorker, environment)}
|
|
1292
|
+
HOST's target is ${hostWorker}, entrypoint ClientApp. Customer sign-in expects the site at ${webOrigin}.`
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
io.out(
|
|
1296
|
+
`
|
|
1297
|
+
The host's staff admin${envLabel}: ${hostWorker}'s address (printed above); open /setup there to create the first admin. Then a human admin, in Settings \u2192 Users, chooses the host's mail connection and turns on "Send sign-in codes without review" for it: until then sign-in by code (customers and staff) answers that it is not set up. cos deploy does not do this step.`
|
|
1298
|
+
);
|
|
1299
|
+
io.out(`
|
|
1300
|
+
${edgeRuleStep(product)}`);
|
|
1301
|
+
return 0;
|
|
1302
|
+
}
|
|
1303
|
+
async function upgradeRepo(flags, deps) {
|
|
1304
|
+
const { io } = deps;
|
|
1305
|
+
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
1306
|
+
const product = await loadClientProduct(root);
|
|
1307
|
+
const { kit, version, manifest } = await fetchKit(
|
|
1308
|
+
flags,
|
|
1309
|
+
deps,
|
|
1310
|
+
product.platform.release,
|
|
1311
|
+
product.platform.repository,
|
|
1312
|
+
str(flags, "version")
|
|
1313
|
+
);
|
|
1314
|
+
if (version === product.platform.version) {
|
|
1315
|
+
io.out(`Already on ${version}. Checking the host modules against its template.`);
|
|
1316
|
+
upgradeHostModules(root, product, kit, version, io);
|
|
1317
|
+
return packagesAndTypes(root, product, version, io);
|
|
1318
|
+
}
|
|
1319
|
+
io.out(`Moving from ${product.platform.version} to ${version}.`);
|
|
1320
|
+
const { CONTRACT_VERSION } = await import("./src-I3IJ4NKC.js");
|
|
1321
|
+
if (orgExtensionDirs(root).length && !manifest.extensionContract.supported.includes(CONTRACT_VERSION)) {
|
|
1322
|
+
io.err(
|
|
1323
|
+
`${version} does not support extension contract ${CONTRACT_VERSION}, which extensions/ is written against: nothing changed.`
|
|
1324
|
+
);
|
|
1325
|
+
return 1;
|
|
1326
|
+
}
|
|
1327
|
+
const missing = product.packs.filter((pack) => !kitPacks(kit).has(pack));
|
|
1328
|
+
if (missing.length) {
|
|
1329
|
+
io.err(`${version} has no pack ${missing.join(", ")}: nothing changed.`);
|
|
1330
|
+
return 1;
|
|
1331
|
+
}
|
|
1332
|
+
setPlatformVersion(root, version);
|
|
1333
|
+
const moved = await loadClientProduct(root);
|
|
1334
|
+
await generateClients(root, moved, kit, io);
|
|
1335
|
+
io.out(`Skills: ${writeSkills(root, kit)} replaced.`);
|
|
1336
|
+
upgradeHostModules(root, moved, kit, version, io);
|
|
1337
|
+
return packagesAndTypes(root, moved, version, io);
|
|
1338
|
+
}
|
|
1339
|
+
async function packagesAndTypes(root, product, version, io) {
|
|
1340
|
+
const { moved, left } = movePlatformVersions(root, product, version);
|
|
1341
|
+
if (moved.length) io.out(`
|
|
1342
|
+
Packages moved to ${version}:
|
|
1343
|
+
${moved.join("\n ")}`);
|
|
1344
|
+
if (left.length) {
|
|
1345
|
+
io.out(
|
|
1346
|
+
`
|
|
1347
|
+
Left as they are (not a version cos can safely rewrite: a tarball, a path, a workspace, a tag). Point them at ${version} yourself:
|
|
1348
|
+
${left.join("\n ")}`
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
const stale = staleInstalls(root, product, version);
|
|
1352
|
+
if (stale.length) {
|
|
1353
|
+
io.out(
|
|
1354
|
+
`
|
|
1355
|
+
The type check was skipped: ${stale.join(", ")} ${stale.length === 1 ? "is" : "are"} not installed at ${version}, so it would check the apps against the old packages. Install, then run cos upgrade again to type-check:
|
|
1356
|
+
${installAll(root)}
|
|
1357
|
+
pnpm cos upgrade`
|
|
1358
|
+
);
|
|
1359
|
+
io.out(`
|
|
1360
|
+
On ${version}, not yet type-checked. Nothing is deployed.`);
|
|
1361
|
+
return 0;
|
|
1362
|
+
}
|
|
1363
|
+
const errors = await typeErrors(root, product);
|
|
1364
|
+
if (errors.length) {
|
|
1365
|
+
io.err(`
|
|
1366
|
+
The apps do not compile against ${version}. Fix these, then cos deploy:`);
|
|
1367
|
+
for (const e of errors) io.err(` ${e}`);
|
|
1368
|
+
io.err("Nothing was deployed.");
|
|
1369
|
+
return 1;
|
|
1370
|
+
}
|
|
1371
|
+
io.out(
|
|
1372
|
+
`
|
|
1373
|
+
Upgraded to ${version}; the apps type-check against it. Nothing is deployed yet: run cos deploy.`
|
|
1374
|
+
);
|
|
1375
|
+
return 0;
|
|
1376
|
+
}
|
|
1377
|
+
function kitPacks(kit) {
|
|
1378
|
+
const listed = kit.get("packs.json");
|
|
1379
|
+
if (!listed) return /* @__PURE__ */ new Set();
|
|
1380
|
+
return new Set(JSON.parse(decode2(listed)));
|
|
1381
|
+
}
|
|
1382
|
+
async function regenerate(flags, deps) {
|
|
1383
|
+
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
1384
|
+
const product = await loadClientProduct(root);
|
|
1385
|
+
const { kit } = await fetchKit(
|
|
1386
|
+
flags,
|
|
1387
|
+
deps,
|
|
1388
|
+
product.platform.release,
|
|
1389
|
+
product.platform.repository,
|
|
1390
|
+
product.platform.version
|
|
1391
|
+
);
|
|
1392
|
+
const written = await generateClients(root, product, kit, deps.io);
|
|
1393
|
+
if (!written.length) deps.io.out("product.ts names no app: nothing to generate.");
|
|
1394
|
+
return 0;
|
|
1395
|
+
}
|
|
1396
|
+
function isClientRepo(dir) {
|
|
1397
|
+
const file = join3(dir, "product.ts");
|
|
1398
|
+
return existsSync3(file) && readFileSync3(file, "utf8").includes("defineClientProduct");
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
export {
|
|
1402
|
+
lineDiff,
|
|
1403
|
+
hostRoutes,
|
|
1404
|
+
edgeRuleStep,
|
|
1405
|
+
fetchKit,
|
|
1406
|
+
loadClientProduct,
|
|
1407
|
+
generateClients,
|
|
1408
|
+
typeErrors,
|
|
1409
|
+
templateFiles,
|
|
1410
|
+
create,
|
|
1411
|
+
withTsExtensions,
|
|
1412
|
+
withEnvBinding,
|
|
1413
|
+
init,
|
|
1414
|
+
chooseEnvironment,
|
|
1415
|
+
IMPORT_LOOPBACK_REDIRECT,
|
|
1416
|
+
nativeRedirectUris,
|
|
1417
|
+
nativeRedirectUri,
|
|
1418
|
+
gatekeeperPlan,
|
|
1419
|
+
hostBindingText,
|
|
1420
|
+
deploy,
|
|
1421
|
+
upgradeRepo,
|
|
1422
|
+
kitPacks,
|
|
1423
|
+
regenerate,
|
|
1424
|
+
isClientRepo
|
|
1425
|
+
};
|