@composable-os/cli 0.1.0-beta.11 → 0.1.0-beta.14
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/dist/{accounts-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
- package/dist/app-OSPZHKOI.js +43 -0
- package/dist/app-upload-LH4PXKI4.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-6DZIP47W.js} +207 -25
- package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
- package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
- package/dist/{chunk-MBIKVRAC.js → chunk-5YDYQM6V.js} +830 -47
- package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
- package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
- package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
- package/dist/chunk-KMFMD52Z.js +13276 -0
- package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
- package/dist/{chunk-PDD2ETVF.js → chunk-O37YUZ52.js} +172 -16
- package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
- package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
- package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
- package/dist/cli.js +5 -5
- package/dist/{client-repo-SE4EKG6W.js → client-repo-MPCPTXLF.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
- package/dist/gateway-DPPEQZT4.js +25 -0
- package/dist/grants-6JY4XZO7.js +27 -0
- package/dist/invoke-MRONRZ5Q.js +33 -0
- package/dist/moves-UAUCMWL5.js +36 -0
- package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0730_practitioners.sql +79 -0
- package/dist/platform/migrations/0750_routine_mail.sql +98 -0
- package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
- package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
- package/dist/platform/migrations/0811_staff_time.sql +109 -0
- package/dist/platform/migrations/0812_staff_offers.sql +112 -0
- package/dist/platform/migrations/0813_pay_periods.sql +241 -0
- package/dist/platform/migrations/0814_staff_feed.sql +47 -0
- package/dist/platform/migrations/0815_checklists.sql +237 -0
- package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
- package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
- package/dist/platform/migrations/0850_agreements.sql +271 -0
- package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
- package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
- package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
- package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
- package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
- package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
- package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
- package/dist/platform/migrations/0910_routine_messages.sql +99 -0
- package/dist/platform/migrations/0911_texts.sql +60 -0
- package/dist/platform/migrations/0913_contact_consent.sql +93 -0
- package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
- package/dist/platform/migrations/0930_stock_movements.sql +95 -0
- package/dist/platform/migrations/0931_stock_low.sql +25 -0
- package/dist/platform/migrations/0932_order_delivery.sql +78 -0
- package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
- package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
- package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
- package/dist/platform/migrations/0953_discount_uses.sql +183 -0
- package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
- package/dist/platform/migrations/0970_published_text.sql +59 -0
- package/dist/platform/migrations/0971_publish_acks.sql +68 -0
- package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
- package/dist/platform/migrations/1010_intake_links.sql +148 -0
- package/dist/platform/migrations/1030_invoices.sql +747 -0
- package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
- package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
- package/dist/platform/migrations/1090_staff_hours.sql +43 -0
- package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
- package/dist/platform/migrations/1092_client_guard.sql +26 -0
- package/dist/platform/migrations/1095_thing_time.sql +70 -0
- package/dist/platform/migrations/1130_devices.sql +162 -0
- package/dist/platform/migrations/1135_person_codes.sql +88 -0
- package/dist/platform/migrations/1150_finance_periods.sql +316 -0
- package/dist/platform/migrations/1151_payouts.sql +202 -0
- package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
- package/dist/platform/migrations/1170_journeys.sql +318 -0
- package/dist/platform/migrations/1171_person_birthday.sql +52 -0
- package/dist/platform/migrations/1175_person_signals.sql +29 -0
- package/dist/platform/migrations/1190_restricted_values.sql +25 -0
- package/dist/platform/migrations/1230_note_levels.sql +113 -0
- package/dist/platform/migrations/1231_person_carers.sql +33 -0
- package/dist/platform/migrations/1232_note_kinds.sql +122 -0
- package/dist/platform/migrations/1270_time_entries.sql +145 -0
- package/dist/platform/migrations/1271_leave.sql +249 -0
- package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
- package/dist/platform/migrations/1330_accounting.sql +260 -0
- package/dist/platform/migrations/1350_customer_feed.sql +24 -0
- package/dist/platform/migrations/1390_locations.sql +77 -0
- package/dist/platform/migrations/1410_outside_copy.sql +213 -0
- package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
- package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
- package/dist/platform/sdk/acknowledge.ts +100 -0
- package/dist/platform/sdk/agreements.ts +185 -0
- package/dist/platform/sdk/allowance.ts +98 -8
- package/dist/platform/sdk/automation-check.ts +120 -9
- package/dist/platform/sdk/automation.ts +78 -10
- package/dist/platform/sdk/behaviour.ts +26 -6
- package/dist/platform/sdk/calendar-entry.ts +258 -0
- package/dist/platform/sdk/capacity.ts +1 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +489 -27
- package/dist/platform/sdk/discount.ts +408 -0
- package/dist/platform/sdk/document.ts +4 -2
- package/dist/platform/sdk/field-types.ts +5 -0
- package/dist/platform/sdk/formula/compile.ts +10 -0
- package/dist/platform/sdk/index.ts +17 -0
- package/dist/platform/sdk/intake.ts +380 -0
- package/dist/platform/sdk/journey-signals.ts +215 -0
- package/dist/platform/sdk/manifest.ts +1236 -65
- package/dist/platform/sdk/mine.ts +161 -0
- package/dist/platform/sdk/occupies.ts +192 -0
- package/dist/platform/sdk/questions.ts +681 -0
- package/dist/platform/sdk/recurring.ts +90 -9
- package/dist/platform/sdk/restricted-fields.ts +129 -0
- package/dist/platform/sdk/rich-text.ts +112 -0
- package/dist/platform/sdk/routine-mail.ts +1272 -0
- package/dist/platform/sdk/runtime.ts +25 -12
- package/dist/platform/sdk/screens.ts +91 -0
- package/dist/platform/sdk/sellable.ts +344 -0
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +68 -26
- package/dist/platform/sdk/stock.ts +332 -0
- package/dist/platform/sdk/team.ts +83 -0
- package/dist/platform/sdk/testing.ts +70 -6
- package/dist/platform/sdk/worked-on.ts +134 -0
- package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
- package/dist/run-7ID64RA6.js +65 -0
- package/dist/run-FH7OGGTV.js +131 -0
- package/dist/run-OYZIAP6M.js +3363 -0
- package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
- package/package.json +2 -2
- package/dist/chunk-2TWV3SVB.js +0 -349
- package/dist/chunk-2XC5JLBO.js +0 -1931
- package/dist/chunk-324WJXNP.js +0 -320
- package/dist/chunk-6ELZRNUU.js +0 -116
- package/dist/chunk-6WGFA2IV.js +0 -643
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-7OGCMQXG.js +0 -284
- package/dist/chunk-FJIZGS5Q.js +0 -698
- package/dist/chunk-UB4I2QKR.js +0 -31575
- package/dist/chunk-WHKJGF36.js +0 -2418
- package/dist/chunk-YNUZRTPH.js +0 -182
- package/dist/chunk-ZZFWMVJO.js +0 -704
- package/dist/grants-LOW6TSWD.js +0 -32
- package/dist/invoke-6KVT6WJI.js +0 -41
- package/dist/moves-E2HKYCTK.js +0 -41
- package/dist/plan-on-sale-TJPFCNL7.js +0 -26
- package/dist/src-CRO35DYY.js +0 -46
|
@@ -3,34 +3,50 @@ import {
|
|
|
3
3
|
CliError,
|
|
4
4
|
install,
|
|
5
5
|
latestVersion,
|
|
6
|
+
parseArgs,
|
|
6
7
|
releaseSource,
|
|
7
8
|
str,
|
|
8
9
|
upgrade,
|
|
9
10
|
verified
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-O37YUZ52.js";
|
|
11
12
|
import {
|
|
13
|
+
APP_PLATFORMS,
|
|
14
|
+
AppBuildRefused,
|
|
12
15
|
CloudflareClient,
|
|
16
|
+
appBuildsViaApi,
|
|
13
17
|
assetHash,
|
|
14
18
|
contentTypeOf,
|
|
15
19
|
locateDeployment,
|
|
20
|
+
nextBuildNumber,
|
|
21
|
+
recordAppBuildViaApi,
|
|
22
|
+
recordedIdProblem,
|
|
16
23
|
releaseAssetNames,
|
|
17
24
|
sha256Hex,
|
|
18
25
|
toBase64
|
|
19
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-3OGDWKJ3.js";
|
|
20
27
|
import {
|
|
21
28
|
DEFAULT_PRODUCT,
|
|
22
29
|
products
|
|
23
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-SMJZIK2O.js";
|
|
24
31
|
import {
|
|
25
32
|
LIVE_ENVIRONMENT,
|
|
33
|
+
appBuild,
|
|
34
|
+
clientLocation,
|
|
26
35
|
clientNameMaps,
|
|
27
36
|
clientNames,
|
|
28
37
|
clientWeb,
|
|
38
|
+
contrastRatio,
|
|
29
39
|
defineClientProduct,
|
|
30
40
|
environmentNames,
|
|
31
41
|
gatekeeperSettings,
|
|
32
|
-
isLiveEnvironment
|
|
33
|
-
|
|
42
|
+
isLiveEnvironment,
|
|
43
|
+
mobileRole
|
|
44
|
+
} from "./chunk-ZJSFX4RD.js";
|
|
45
|
+
|
|
46
|
+
// src/app.ts
|
|
47
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
48
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, statSync as statSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
49
|
+
import { dirname as dirname4, join as join4, relative as relative3, resolve as resolve2 } from "node:path";
|
|
34
50
|
|
|
35
51
|
// src/client-repo.ts
|
|
36
52
|
import { execFileSync } from "node:child_process";
|
|
@@ -89,7 +105,11 @@ import { createHash } from "node:crypto";
|
|
|
89
105
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
90
106
|
import { dirname, join } from "node:path";
|
|
91
107
|
var STATE_FILE = "composable-os.lock.json";
|
|
92
|
-
var
|
|
108
|
+
var HOST_MODULES = {
|
|
109
|
+
web: ["host.ts", "agreements.ts"],
|
|
110
|
+
mobile: ["host.ts", "secure-store.ts", "secure-random.ts"]
|
|
111
|
+
};
|
|
112
|
+
var MODULES = HOST_MODULES;
|
|
93
113
|
var sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
94
114
|
var decode = (bytes) => new TextDecoder().decode(bytes);
|
|
95
115
|
function readState(root) {
|
|
@@ -143,15 +163,16 @@ function recordHostModules(root, product, kit, version) {
|
|
|
143
163
|
function upgradeHostModules(root, product, kit, version, io) {
|
|
144
164
|
const state = readState(root);
|
|
145
165
|
state.hostModules ??= {};
|
|
166
|
+
const modules = state.hostModules;
|
|
146
167
|
const replaced = [];
|
|
147
168
|
const edited = [];
|
|
148
169
|
for (const place of hostModulePlaces(product)) {
|
|
149
170
|
const next = templateText(kit, place);
|
|
150
171
|
if (next === null) continue;
|
|
151
172
|
const path = join(root, place.path);
|
|
152
|
-
const recorded =
|
|
153
|
-
const
|
|
154
|
-
|
|
173
|
+
const recorded = modules[place.path];
|
|
174
|
+
const record2 = () => {
|
|
175
|
+
modules[place.path] = {
|
|
155
176
|
template: place.template,
|
|
156
177
|
version,
|
|
157
178
|
sha256: sha(next)
|
|
@@ -160,18 +181,18 @@ function upgradeHostModules(root, product, kit, version, io) {
|
|
|
160
181
|
if (!existsSync(path)) {
|
|
161
182
|
mkdirSync(dirname(path), { recursive: true });
|
|
162
183
|
writeFileSync(path, next);
|
|
163
|
-
|
|
184
|
+
record2();
|
|
164
185
|
replaced.push(`${place.path} (new)`);
|
|
165
186
|
continue;
|
|
166
187
|
}
|
|
167
188
|
const current = readFileSync(path, "utf8");
|
|
168
189
|
if (current === next) {
|
|
169
|
-
|
|
190
|
+
record2();
|
|
170
191
|
continue;
|
|
171
192
|
}
|
|
172
193
|
if (recorded && sha(current) === recorded.sha256) {
|
|
173
194
|
writeFileSync(path, next);
|
|
174
|
-
|
|
195
|
+
record2();
|
|
175
196
|
replaced.push(place.path);
|
|
176
197
|
continue;
|
|
177
198
|
}
|
|
@@ -300,13 +321,18 @@ function hostRoutes(product) {
|
|
|
300
321
|
];
|
|
301
322
|
}
|
|
302
323
|
function edgeRuleStep(product) {
|
|
303
|
-
const expression =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
324
|
+
const expression = [
|
|
325
|
+
...hostRoutes(product).map((route) => `starts_with(http.request.uri.path, "${route}")`),
|
|
326
|
+
// With Forms, the form page the site forwards to the host (stage 29, ADR 0728): a form's own
|
|
327
|
+
// page and a personal link's, which post to the host as the operation route does.
|
|
328
|
+
...product?.packs?.includes("forms") ? ['starts_with(http.request.uri.path, "/f/")', 'http.request.uri.path eq "/form"'] : []
|
|
329
|
+
].join(" or ");
|
|
330
|
+
return `The host limits calls from the web app itself, per visitor (ADR 0940). Against floods, also
|
|
331
|
+
add a rate limiting rule on the web app's zone (Security > WAF > Rate limiting rules): calls over
|
|
332
|
+
the binding do not pass the host's zone. It names only the routes that reach the host (web.routes in
|
|
307
333
|
product.ts), so the site's own pages and API are not limited by it:
|
|
308
334
|
Expression: (${expression})
|
|
309
|
-
Counting: IP (ip.src),
|
|
335
|
+
Counting: IP (ip.src), 300 requests per 10 seconds; action Block for 10 seconds`;
|
|
310
336
|
}
|
|
311
337
|
var KIT = { template: "template/", skills: "skills/", blocks: "blocks/", contract: "contract/" };
|
|
312
338
|
var decode2 = (bytes) => new TextDecoder().decode(bytes);
|
|
@@ -413,8 +439,8 @@ function appClients(product) {
|
|
|
413
439
|
return out;
|
|
414
440
|
}
|
|
415
441
|
async function generateClients(root, product, kit, io) {
|
|
416
|
-
const { releaseContract, renderClient } = await import("./src-
|
|
417
|
-
const { loadExtension } = await import("./cli-
|
|
442
|
+
const { releaseContract, renderClient } = await import("./src-PHRELWN5.js");
|
|
443
|
+
const { loadExtension } = await import("./cli-OKQHHSOE.js");
|
|
418
444
|
const perAudience = ["customer", "public", "staff"].map((audience) => {
|
|
419
445
|
const bytes = kit.get(`${KIT.contract}${audience}.json`);
|
|
420
446
|
if (!bytes) throw new CliError(`The release's client kit has no ${audience} contract.`);
|
|
@@ -430,33 +456,66 @@ async function generateClients(root, product, kit, io) {
|
|
|
430
456
|
written.push(join3(dir, "customer.ts"));
|
|
431
457
|
}
|
|
432
458
|
const roles = product.mobile?.roles ?? [];
|
|
433
|
-
|
|
434
|
-
|
|
459
|
+
const owner = product.mobile?.owner === true;
|
|
460
|
+
if ((roles.length || owner) && product.mobile) {
|
|
461
|
+
const { renderOwnerClient, renderRoleClient } = await import("./src-PHRELWN5.js");
|
|
435
462
|
const rolesFile = kit.get(`${KIT.contract}roles.json`);
|
|
436
463
|
if (!rolesFile) {
|
|
437
464
|
throw new CliError(
|
|
438
465
|
"The release's client kit has no roles.json: it is older than role clients. Upgrade the platform version first."
|
|
439
466
|
);
|
|
440
467
|
}
|
|
441
|
-
const
|
|
468
|
+
const parsed = JSON.parse(decode2(rolesFile));
|
|
469
|
+
const declared = parsed.roles;
|
|
442
470
|
const staff = perAudience[2];
|
|
443
471
|
const dir = join3(product.mobile.dir, product.mobile.clientDir ?? "src/client", "roles");
|
|
444
472
|
mkdirSync2(join3(root, dir), { recursive: true });
|
|
445
|
-
|
|
473
|
+
if (owner) {
|
|
474
|
+
if (!parsed.owner) {
|
|
475
|
+
throw new CliError(
|
|
476
|
+
"The release's roles.json has no owner's client (mobile.owner): it is older than it. Upgrade the platform version first."
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
writeFileSync3(
|
|
480
|
+
join3(root, dir, "owner.ts"),
|
|
481
|
+
renderOwnerClient(staff, parsed.owner, { product: product.id })
|
|
482
|
+
);
|
|
483
|
+
written.push(join3(dir, "owner.ts"));
|
|
484
|
+
}
|
|
485
|
+
for (const entry of roles) {
|
|
486
|
+
const { role: name, grants } = mobileRole(entry);
|
|
446
487
|
const role = declared.find((r) => r.name === name);
|
|
447
488
|
if (!role) {
|
|
448
489
|
throw new CliError(
|
|
449
490
|
`The release has no pack role ${name}. Its roles: ${declared.map((r) => r.name).join(", ") || "none"}.`
|
|
450
491
|
);
|
|
451
492
|
}
|
|
493
|
+
const granted = [];
|
|
494
|
+
for (const permission of grants) {
|
|
495
|
+
const grant = parsed.grants?.find((g) => g.permission === permission);
|
|
496
|
+
if (!grant) {
|
|
497
|
+
throw new CliError(
|
|
498
|
+
`The release has no grantable permission ${permission}. Its grantable permissions: ${(parsed.grants ?? []).map((g) => g.permission).join(", ") || "none (the release is older than role clients with grants)"}.`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
if (grant.restricted) {
|
|
502
|
+
io.out(
|
|
503
|
+
`Note: ${name}'s client includes ${permission}, a restricted permission: the host still decides every call, and only an account an admin granted it may use those screens.`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
granted.push(...grant.operations);
|
|
507
|
+
}
|
|
508
|
+
const withGrants = granted.length ? { ...role, operations: [.../* @__PURE__ */ new Set([...role.operations, ...granted])].sort() } : role;
|
|
452
509
|
writeFileSync3(
|
|
453
510
|
join3(root, dir, `${name}.ts`),
|
|
454
|
-
renderRoleClient(staff,
|
|
511
|
+
renderRoleClient(staff, withGrants, { product: product.id, grants })
|
|
455
512
|
);
|
|
456
513
|
written.push(join3(dir, `${name}.ts`));
|
|
457
514
|
}
|
|
458
515
|
}
|
|
459
516
|
if (written.length) io.out(`Typed client: ${written.join(", ")}`);
|
|
517
|
+
const brand = product.mobile && existsSync3(join3(root, product.mobile.dir)) ? writeBrand(root, product) : null;
|
|
518
|
+
if (brand) written.push(brand);
|
|
460
519
|
return written;
|
|
461
520
|
}
|
|
462
521
|
async function typeErrors(root, product) {
|
|
@@ -508,6 +567,8 @@ function appPackage(text, name, version) {
|
|
|
508
567
|
const pkg = JSON.parse(text);
|
|
509
568
|
pkg.name = name;
|
|
510
569
|
delete pkg.description;
|
|
570
|
+
const scripts = pkg.scripts;
|
|
571
|
+
if (scripts?.typecheck?.includes("tsconfig.platform.json")) scripts.typecheck = "tsc --noEmit";
|
|
511
572
|
for (const key of ["dependencies", "devDependencies"]) {
|
|
512
573
|
const deps = pkg[key];
|
|
513
574
|
for (const [dep, range] of Object.entries(deps ?? {})) {
|
|
@@ -532,12 +593,6 @@ function templateFiles(kit, values) {
|
|
|
532
593
|
const app = /^apps\/([^/]+)\/(package\.json|wrangler\.jsonc)$/.exec(rel);
|
|
533
594
|
if (app?.[2] === "package.json")
|
|
534
595
|
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
596
|
if (app?.[2] === "wrangler.jsonc") {
|
|
542
597
|
text = text.replace(/"name":\s*"client-web"/, `"name": "${values.id}-web"`).replace(/"service":\s*"cos-app"/, `"service": "${values.appWorker}"`);
|
|
543
598
|
}
|
|
@@ -548,6 +603,24 @@ function templateFiles(kit, values) {
|
|
|
548
603
|
function slug(name) {
|
|
549
604
|
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
550
605
|
}
|
|
606
|
+
var APP_WORKFLOW = ".github/workflows/app.yml";
|
|
607
|
+
var MOBILE_ENTRY = ` mobile: {
|
|
608
|
+
dir: "apps/mobile",
|
|
609
|
+
// The app's identity in the phone app stores (stage 63): app.config.ts and the app's brand are
|
|
610
|
+
// made from it. Fill it in before the first store build, then run \`pnpm cos app check\`.
|
|
611
|
+
// app: {
|
|
612
|
+
// name: "Example", // under the icon, at most 30 characters
|
|
613
|
+
// version: "1.0.0",
|
|
614
|
+
// ids: { ios: "com.example.app", android: "com.example.app" }, // never change once published
|
|
615
|
+
// icon: "apps/mobile/assets/icon.png", // 1024 by 1024, no transparency
|
|
616
|
+
// splash: { image: "apps/mobile/assets/splash.png", background: "#ffffff" },
|
|
617
|
+
// colours: { primary: "#18181b", background: "#ffffff", text: "#18181b" },
|
|
618
|
+
// listing: "apps/mobile/store", // <locale>/name.txt, subtitle.txt, description.txt, \u2026
|
|
619
|
+
// purchases: "none",
|
|
620
|
+
// },
|
|
621
|
+
// A staging app installs beside the live one with its own name, ids and scheme:
|
|
622
|
+
// environments.staging.mobile: { scheme: "example-staging", app: { name, ids } }.
|
|
623
|
+
},`;
|
|
551
624
|
async function create(argv, flags, deps) {
|
|
552
625
|
const { io } = deps;
|
|
553
626
|
const target = argv[0];
|
|
@@ -582,13 +655,11 @@ async function create(argv, flags, deps) {
|
|
|
582
655
|
const files = templateFiles(kit, values);
|
|
583
656
|
const mobile = Boolean(flags["with-mobile"]);
|
|
584
657
|
for (const path of [...files.keys()])
|
|
585
|
-
if (!mobile && path.startsWith("apps/mobile/")) files.delete(path);
|
|
658
|
+
if (!mobile && (path.startsWith("apps/mobile/") || path === APP_WORKFLOW)) files.delete(path);
|
|
586
659
|
if (mobile) {
|
|
587
660
|
const product2 = files.get("product.ts");
|
|
588
|
-
files.set(
|
|
589
|
-
|
|
590
|
-
product2.replace(/(\n\s*web: \{[^\n]*\},)/, '$1\n mobile: { dir: "apps/mobile" },')
|
|
591
|
-
);
|
|
661
|
+
files.set("product.ts", product2.replace(/(\n\s*web: \{[^\n]*\},)/, `$1
|
|
662
|
+
${MOBILE_ENTRY}`));
|
|
592
663
|
}
|
|
593
664
|
for (const [path, text] of files) {
|
|
594
665
|
mkdirSync2(dirname3(join3(root, path)), { recursive: true });
|
|
@@ -596,6 +667,12 @@ async function create(argv, flags, deps) {
|
|
|
596
667
|
}
|
|
597
668
|
const skills = writeSkills(root, kit);
|
|
598
669
|
const product = await loadClientProduct(root);
|
|
670
|
+
if (mobile && product.mobile && kit.has("blocks/native-account/block.json")) {
|
|
671
|
+
const { copyBlocks, saveLock } = await import("./blocks-6DZIP47W.js");
|
|
672
|
+
const lock = {};
|
|
673
|
+
copyBlocks(root, product, kit, version, ["native-account"], lock);
|
|
674
|
+
saveLock(root, lock);
|
|
675
|
+
}
|
|
599
676
|
await generateClients(root, product, kit, io);
|
|
600
677
|
recordHostModules(root, product, kit, version);
|
|
601
678
|
try {
|
|
@@ -717,7 +794,7 @@ async function init(flags, deps) {
|
|
|
717
794
|
};
|
|
718
795
|
const guessWeb = wranglerConfig(root) ? "." : void 0;
|
|
719
796
|
const guessMobile = ["mobile", "app", "apps/mobile"].find(
|
|
720
|
-
(d) => existsSync3(join3(root, d,
|
|
797
|
+
(d) => ["app.json", "app.config.ts", "app.config.js"].some((f) => existsSync3(join3(root, d, f)))
|
|
721
798
|
);
|
|
722
799
|
const webDir = str(flags, "web") ?? await ask("Where is the web app (its Worker)?", guessWeb);
|
|
723
800
|
const mobileDir = str(flags, "mobile") ?? await ask("Where is the mobile app?", guessMobile);
|
|
@@ -778,8 +855,8 @@ export const product = defineClientProduct(${JSON.stringify(product, null, 2)});
|
|
|
778
855
|
added.push(`skills/ (${skills} skills)`);
|
|
779
856
|
added.push(...await generateClients(root, defineClientProduct(product), kit, io));
|
|
780
857
|
const hostModules = [
|
|
781
|
-
[webDir, "web",
|
|
782
|
-
[mobileDir, "mobile",
|
|
858
|
+
[webDir, "web", HOST_MODULES.web],
|
|
859
|
+
[mobileDir, "mobile", HOST_MODULES.mobile]
|
|
783
860
|
];
|
|
784
861
|
for (const [app, kind, files] of hostModules) {
|
|
785
862
|
if (!app) continue;
|
|
@@ -921,12 +998,12 @@ ${edgeRuleStep(product)}`);
|
|
|
921
998
|
return 0;
|
|
922
999
|
}
|
|
923
1000
|
function orgExtensionSources(root) {
|
|
924
|
-
const
|
|
1001
|
+
const SKIP2 = /* @__PURE__ */ new Set(["node_modules", "test", "tests", "dist", ".turbo"]);
|
|
925
1002
|
const files = (dir, base, out) => {
|
|
926
1003
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
927
1004
|
const path = join3(dir, entry.name);
|
|
928
1005
|
if (entry.isDirectory()) {
|
|
929
|
-
if (!
|
|
1006
|
+
if (!SKIP2.has(entry.name)) files(path, base, out);
|
|
930
1007
|
} else if (/\.(ts|js)$/.test(entry.name) && !/\.(test|config)\.(ts|js)$/.test(entry.name)) {
|
|
931
1008
|
out[relative2(base, path).split("\\").join("/")] = readFileSync3(path, "utf8");
|
|
932
1009
|
}
|
|
@@ -941,7 +1018,7 @@ function orgExtensionSources(root) {
|
|
|
941
1018
|
async function checkOrgExtensions(root, io) {
|
|
942
1019
|
const dirs = orgExtensionDirs(root);
|
|
943
1020
|
if (!dirs.length) return true;
|
|
944
|
-
const { runExt } = await import("./cli-
|
|
1021
|
+
const { runExt } = await import("./cli-VYSD2S4Z.js");
|
|
945
1022
|
let ok = true;
|
|
946
1023
|
for (const dir of dirs) {
|
|
947
1024
|
io.out(`cos ext check ${relative2(root, dir)}`);
|
|
@@ -1134,9 +1211,10 @@ function gatekeeperPlan(manifest, product, environment) {
|
|
|
1134
1211
|
}
|
|
1135
1212
|
vars[worker.name] = { ...vars[worker.name], [key]: String(value) };
|
|
1136
1213
|
}
|
|
1137
|
-
|
|
1214
|
+
const fake = vars[worker.name]?.PAYMENTS_FAKE_PROVIDER === "true" ? "the fake payment provider" : vars[worker.name]?.TEXT_PROVIDER === "fake" ? "the fake text provider" : null;
|
|
1215
|
+
if (fake && isLiveEnvironment(product, environment)) {
|
|
1138
1216
|
return {
|
|
1139
|
-
problem: `${where} is live and turns on
|
|
1217
|
+
problem: `${where} is live and turns on ${fake}: only an environment marked live: false may.`
|
|
1140
1218
|
};
|
|
1141
1219
|
}
|
|
1142
1220
|
}
|
|
@@ -1195,13 +1273,21 @@ async function deploy(flags, deps) {
|
|
|
1195
1273
|
const { bundle } = await verified(source, product.platform.version, scoped);
|
|
1196
1274
|
const manifest = bundle.manifest;
|
|
1197
1275
|
const inRelease = kitPacks(bundle.clientFiles);
|
|
1198
|
-
const
|
|
1276
|
+
const brought = requiredPacks(bundle.clientFiles, product.packs);
|
|
1277
|
+
const missing = [...product.packs, ...brought].filter((pack) => !inRelease.has(pack));
|
|
1199
1278
|
if (missing.length) {
|
|
1200
1279
|
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.`
|
|
1280
|
+
`${release.label} ${product.platform.version} does not carry the pack${missing.length > 1 ? "s" : ""} ${missing.join(", ")} that product.ts lists${brought.some((p) => missing.includes(p)) ? " or its packs require" : ""} (it carries ${[...inRelease].sort().join(", ") || "none"}): the platform needs it in a release first. Nothing was deployed.`
|
|
1202
1281
|
);
|
|
1203
1282
|
return 1;
|
|
1204
1283
|
}
|
|
1284
|
+
if (brought.length) {
|
|
1285
|
+
hostFlags.packs = [...product.packs, ...brought].join(",");
|
|
1286
|
+
const them = brought.length > 1 ? "them" : "it";
|
|
1287
|
+
io.out(
|
|
1288
|
+
`Installing ${brought.join(", ")} too: a pack product.ts lists requires ${them}. Add ${them} to packs in product.ts to say so there.`
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1205
1291
|
const gatekeepers = gatekeeperPlan(manifest, product, environment);
|
|
1206
1292
|
if ("problem" in gatekeepers) {
|
|
1207
1293
|
io.err(`${gatekeepers.problem} Nothing was deployed.`);
|
|
@@ -1248,12 +1334,14 @@ async function deploy(flags, deps) {
|
|
|
1248
1334
|
hostFlags["customer-auth-url"] = webOrigin;
|
|
1249
1335
|
}
|
|
1250
1336
|
hostFlags["native-redirect-uris"] = nativeRedirectUris(product, environment);
|
|
1337
|
+
hostFlags.location = clientLocation(product, environment) ?? "none";
|
|
1251
1338
|
const found = ownHost?.state ? ownHost : legacyHost;
|
|
1252
1339
|
if (found?.state && found.state.version !== product.platform.version) {
|
|
1253
1340
|
io.out(
|
|
1254
1341
|
`The host${envLabel} is on ${found.state.version}; moving it to ${product.platform.version}.`
|
|
1255
1342
|
);
|
|
1256
|
-
const
|
|
1343
|
+
const { location: _location, ...upgradeFlags } = hostFlags;
|
|
1344
|
+
const code2 = await upgrade(upgradeFlags, scoped);
|
|
1257
1345
|
if (code2 !== 0) return code2;
|
|
1258
1346
|
}
|
|
1259
1347
|
const code = await install(hostFlags, scoped);
|
|
@@ -1314,10 +1402,12 @@ async function upgradeRepo(flags, deps) {
|
|
|
1314
1402
|
if (version === product.platform.version) {
|
|
1315
1403
|
io.out(`Already on ${version}. Checking the host modules against its template.`);
|
|
1316
1404
|
upgradeHostModules(root, product, kit, version, io);
|
|
1405
|
+
const { rewriteAccountSections: rewriteAccountSections2 } = await import("./blocks-6DZIP47W.js");
|
|
1406
|
+
rewriteAccountSections2(root, product, kit, version, io);
|
|
1317
1407
|
return packagesAndTypes(root, product, version, io);
|
|
1318
1408
|
}
|
|
1319
1409
|
io.out(`Moving from ${product.platform.version} to ${version}.`);
|
|
1320
|
-
const { CONTRACT_VERSION } = await import("./src-
|
|
1410
|
+
const { CONTRACT_VERSION } = await import("./src-52VERUPK.js");
|
|
1321
1411
|
if (orgExtensionDirs(root).length && !manifest.extensionContract.supported.includes(CONTRACT_VERSION)) {
|
|
1322
1412
|
io.err(
|
|
1323
1413
|
`${version} does not support extension contract ${CONTRACT_VERSION}, which extensions/ is written against: nothing changed.`
|
|
@@ -1333,6 +1423,8 @@ async function upgradeRepo(flags, deps) {
|
|
|
1333
1423
|
const moved = await loadClientProduct(root);
|
|
1334
1424
|
await generateClients(root, moved, kit, io);
|
|
1335
1425
|
io.out(`Skills: ${writeSkills(root, kit)} replaced.`);
|
|
1426
|
+
const { rewriteAccountSections } = await import("./blocks-6DZIP47W.js");
|
|
1427
|
+
rewriteAccountSections(root, moved, kit, version, io);
|
|
1336
1428
|
upgradeHostModules(root, moved, kit, version, io);
|
|
1337
1429
|
return packagesAndTypes(root, moved, version, io);
|
|
1338
1430
|
}
|
|
@@ -1379,6 +1471,20 @@ function kitPacks(kit) {
|
|
|
1379
1471
|
if (!listed) return /* @__PURE__ */ new Set();
|
|
1380
1472
|
return new Set(JSON.parse(decode2(listed)));
|
|
1381
1473
|
}
|
|
1474
|
+
function requiredPacks(kit, packs) {
|
|
1475
|
+
const file = kit.get(`${KIT.contract}roles.json`);
|
|
1476
|
+
const requires = file ? JSON.parse(decode2(file)).requires ?? {} : {};
|
|
1477
|
+
const brought = [];
|
|
1478
|
+
const visit = (pack) => {
|
|
1479
|
+
for (const needed of requires[pack] ?? []) {
|
|
1480
|
+
if (packs.includes(needed) || brought.includes(needed)) continue;
|
|
1481
|
+
brought.push(needed);
|
|
1482
|
+
visit(needed);
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
for (const pack of packs) visit(pack);
|
|
1486
|
+
return brought;
|
|
1487
|
+
}
|
|
1382
1488
|
async function regenerate(flags, deps) {
|
|
1383
1489
|
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
1384
1490
|
const product = await loadClientProduct(root);
|
|
@@ -1398,7 +1504,683 @@ function isClientRepo(dir) {
|
|
|
1398
1504
|
return existsSync3(file) && readFileSync3(file, "utf8").includes("defineClientProduct");
|
|
1399
1505
|
}
|
|
1400
1506
|
|
|
1507
|
+
// src/purchase-rules.ts
|
|
1508
|
+
function codeOnly(source) {
|
|
1509
|
+
let out = "";
|
|
1510
|
+
let i = 0;
|
|
1511
|
+
while (i < source.length) {
|
|
1512
|
+
const c = source[i];
|
|
1513
|
+
const next = source[i + 1];
|
|
1514
|
+
if (c === "/" && next === "/") {
|
|
1515
|
+
while (i < source.length && source[i] !== "\n") {
|
|
1516
|
+
out += " ";
|
|
1517
|
+
i++;
|
|
1518
|
+
}
|
|
1519
|
+
} else if (c === "/" && next === "*") {
|
|
1520
|
+
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) {
|
|
1521
|
+
out += source[i] === "\n" ? "\n" : " ";
|
|
1522
|
+
i++;
|
|
1523
|
+
}
|
|
1524
|
+
out += " ";
|
|
1525
|
+
i += 2;
|
|
1526
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
1527
|
+
out += c;
|
|
1528
|
+
i++;
|
|
1529
|
+
while (i < source.length && source[i] !== c) {
|
|
1530
|
+
if (source[i] === "\\") {
|
|
1531
|
+
out += " ";
|
|
1532
|
+
i++;
|
|
1533
|
+
}
|
|
1534
|
+
out += source[i] === "\n" ? "\n" : " ";
|
|
1535
|
+
i++;
|
|
1536
|
+
}
|
|
1537
|
+
out += c;
|
|
1538
|
+
i++;
|
|
1539
|
+
} else {
|
|
1540
|
+
out += c;
|
|
1541
|
+
i++;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
return out;
|
|
1545
|
+
}
|
|
1546
|
+
var PURCHASE_OPERATION = /^(?:order\.(?:start|checkout|cancel)|subscription\.(?:start|cancel|resume|portal|change|pause|coolOff)|x\.[a-z0-9]+\.(?:buy|orderStart|checkout|subscribe))$/;
|
|
1547
|
+
var BUY_HOOK = /\b(?:useBuy\w*|useCheckout\w*|useOrderStart|useSubscribe|useCancelSubscription|useResumeSubscription|useBillingPortal|useCoolOff)\b/;
|
|
1548
|
+
var OPERATION_STRING = /["'`]((?:order|subscription|x\.[a-z0-9]+)\.[a-zA-Z]+)["'`]/g;
|
|
1549
|
+
function scanPurchases(source) {
|
|
1550
|
+
const problems = [];
|
|
1551
|
+
const code = codeOnly(source).split("\n");
|
|
1552
|
+
source.split("\n").forEach((line, index) => {
|
|
1553
|
+
for (const match of line.matchAll(OPERATION_STRING)) {
|
|
1554
|
+
if (PURCHASE_OPERATION.test(match[1])) {
|
|
1555
|
+
problems.push({ line: index + 1, names: match[1] });
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
const hook = BUY_HOOK.exec(code[index] ?? "");
|
|
1559
|
+
if (hook) problems.push({ line: index + 1, names: hook[0] });
|
|
1560
|
+
});
|
|
1561
|
+
return problems;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// src/app.ts
|
|
1565
|
+
var APP_USAGE = `Usage:
|
|
1566
|
+
cos app check [--dir <repo>]
|
|
1567
|
+
cos app credentials [--check --for ios|android|record]
|
|
1568
|
+
cos app build-info [--env <name>] [--json]
|
|
1569
|
+
cos app record [--env <name>] --platform ios,android --build <n> [--commit <sha>]
|
|
1570
|
+
cos app upload --platform android [--env <name>] --file <app.aab> [--listing] [--draft]`;
|
|
1571
|
+
var DEFAULT_BRAND = {
|
|
1572
|
+
primary: "#18181b",
|
|
1573
|
+
onPrimary: "#fafafa",
|
|
1574
|
+
background: "#ffffff",
|
|
1575
|
+
text: "#18181b"
|
|
1576
|
+
};
|
|
1577
|
+
function brandPath(product) {
|
|
1578
|
+
return product.mobile ? join4(product.mobile.dir, "src", "blocks", "brand.ts") : null;
|
|
1579
|
+
}
|
|
1580
|
+
function onPrimary(primary) {
|
|
1581
|
+
return contrastRatio("#ffffff", primary) >= contrastRatio("#18181b", primary) ? "#ffffff" : "#18181b";
|
|
1582
|
+
}
|
|
1583
|
+
function brandText(product) {
|
|
1584
|
+
const colours = product.mobile?.app?.colours;
|
|
1585
|
+
const brand = colours ? { ...colours, onPrimary: onPrimary(colours.primary) } : DEFAULT_BRAND;
|
|
1586
|
+
return `// Written by cos from product.ts (mobile.app.colours): do not edit. Change product.ts and run
|
|
1587
|
+
// \`pnpm cos client generate\`. The native base theme reads it (native-base/theme.ts).
|
|
1588
|
+
export const brand = {
|
|
1589
|
+
primary: ${JSON.stringify(brand.primary)},
|
|
1590
|
+
onPrimary: ${JSON.stringify(brand.onPrimary)},
|
|
1591
|
+
background: ${JSON.stringify(brand.background)},
|
|
1592
|
+
text: ${JSON.stringify(brand.text)},
|
|
1593
|
+
} as const;
|
|
1594
|
+
`;
|
|
1595
|
+
}
|
|
1596
|
+
function writeBrand(root, product) {
|
|
1597
|
+
const path = brandPath(product);
|
|
1598
|
+
if (!path) return null;
|
|
1599
|
+
const text = brandText(product);
|
|
1600
|
+
const file = join4(root, path);
|
|
1601
|
+
if (existsSync4(file) && readFileSync4(file, "utf8") === text) return path;
|
|
1602
|
+
mkdirSync3(dirname4(file), { recursive: true });
|
|
1603
|
+
writeFileSync4(file, text);
|
|
1604
|
+
return path;
|
|
1605
|
+
}
|
|
1606
|
+
var LISTING_FILES = [
|
|
1607
|
+
{ file: "name.txt", max: 30, what: "the name in the store" },
|
|
1608
|
+
{
|
|
1609
|
+
file: "subtitle.txt",
|
|
1610
|
+
max: 30,
|
|
1611
|
+
what: "the subtitle (the Android store's short description too)"
|
|
1612
|
+
},
|
|
1613
|
+
{ file: "description.txt", max: 4e3, what: "the description" },
|
|
1614
|
+
{ file: "keywords.txt", max: 100, what: "the keywords, comma separated (iPhone store)" },
|
|
1615
|
+
{ file: "release-notes.txt", max: 500, what: "what is new in this version" },
|
|
1616
|
+
{ file: "support-url.txt", url: true, what: "the support page's address" },
|
|
1617
|
+
{ file: "privacy-url.txt", url: true, what: "the privacy policy's address" }
|
|
1618
|
+
];
|
|
1619
|
+
var LOCALE = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
1620
|
+
function listingLocales(root, listing) {
|
|
1621
|
+
const dir = join4(root, listing);
|
|
1622
|
+
if (!existsSync4(dir)) return [];
|
|
1623
|
+
return readdirSync2(dir).filter((name) => LOCALE.test(name) && statSync2(join4(dir, name)).isDirectory()).sort();
|
|
1624
|
+
}
|
|
1625
|
+
function listingText(root, listing, locale, file) {
|
|
1626
|
+
const path = join4(root, listing, locale, file);
|
|
1627
|
+
return existsSync4(path) ? readFileSync4(path, "utf8").trim() : null;
|
|
1628
|
+
}
|
|
1629
|
+
function listingProblems(root, listing) {
|
|
1630
|
+
const problems = [];
|
|
1631
|
+
const notes = [];
|
|
1632
|
+
const locales = listingLocales(root, listing);
|
|
1633
|
+
if (!locales.length) {
|
|
1634
|
+
problems.push(
|
|
1635
|
+
`${listing} has no locale folder (${listing}/en-AU/ with ${LISTING_FILES.map((f) => f.file).join(", ")})`
|
|
1636
|
+
);
|
|
1637
|
+
return { problems, notes };
|
|
1638
|
+
}
|
|
1639
|
+
for (const locale of locales) {
|
|
1640
|
+
for (const field of LISTING_FILES) {
|
|
1641
|
+
const where = `${listing}/${locale}/${field.file}`;
|
|
1642
|
+
const text = listingText(root, listing, locale, field.file);
|
|
1643
|
+
if (!text) {
|
|
1644
|
+
problems.push(`${where} is missing or empty: ${field.what}`);
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
if ("url" in field) {
|
|
1648
|
+
if (!/^https:\/\/[^\s/]+\.[^\s]+$/.test(text))
|
|
1649
|
+
problems.push(`${where} is not an https:// address`);
|
|
1650
|
+
continue;
|
|
1651
|
+
}
|
|
1652
|
+
const length = [...text].length;
|
|
1653
|
+
if (length > field.max) {
|
|
1654
|
+
problems.push(`${where} is ${length} characters: the stores take at most ${field.max}`);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
const shots = join4(root, listing, locale, "screenshots");
|
|
1658
|
+
if (!existsSync4(shots) || !readdirSync2(shots).some((f) => /\.(png|jpe?g)$/i.test(f))) {
|
|
1659
|
+
notes.push(
|
|
1660
|
+
`${listing}/${locale}/screenshots/ has none: the testing tracks take a build without them, a store review does not`
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
return { problems, notes };
|
|
1665
|
+
}
|
|
1666
|
+
function pngInfo(bytes) {
|
|
1667
|
+
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
1668
|
+
if (bytes.length < 33 || signature.some((b, i) => bytes[i] !== b)) return null;
|
|
1669
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1670
|
+
const width = view.getUint32(16);
|
|
1671
|
+
const height = view.getUint32(20);
|
|
1672
|
+
const colourType = bytes[25];
|
|
1673
|
+
let alpha = colourType === 4 || colourType === 6;
|
|
1674
|
+
for (let at = 8; at + 8 <= bytes.length && !alpha; ) {
|
|
1675
|
+
const length = view.getUint32(at);
|
|
1676
|
+
const type = String.fromCharCode(...bytes.subarray(at + 4, at + 8));
|
|
1677
|
+
if (type === "tRNS") alpha = true;
|
|
1678
|
+
if (type === "IDAT" || type === "IEND") break;
|
|
1679
|
+
at += 12 + length;
|
|
1680
|
+
}
|
|
1681
|
+
return { width, height, alpha };
|
|
1682
|
+
}
|
|
1683
|
+
function imageProblem(root, path, what, rule) {
|
|
1684
|
+
const file = join4(root, path);
|
|
1685
|
+
if (!existsSync4(file)) return `${what} ${path} is not in the repo`;
|
|
1686
|
+
const info = pngInfo(new Uint8Array(readFileSync4(file)));
|
|
1687
|
+
if (!info) return `${what} ${path} is not a PNG`;
|
|
1688
|
+
if (rule.size && (info.width !== rule.size || info.height !== rule.size)) {
|
|
1689
|
+
return `${what} ${path} is ${info.width} by ${info.height}: it must be ${rule.size} by ${rule.size}`;
|
|
1690
|
+
}
|
|
1691
|
+
if (rule.opaque && info.alpha) {
|
|
1692
|
+
return `${what} ${path} can be transparent (an alpha channel): the iPhone store refuses an icon that is not opaque`;
|
|
1693
|
+
}
|
|
1694
|
+
return null;
|
|
1695
|
+
}
|
|
1696
|
+
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".expo", ".wrangler", ".turbo", "build"]);
|
|
1697
|
+
function walk(dir, base, out) {
|
|
1698
|
+
if (!existsSync4(dir)) return;
|
|
1699
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1700
|
+
if (SKIP.has(entry.name)) continue;
|
|
1701
|
+
const path = join4(dir, entry.name);
|
|
1702
|
+
if (entry.isDirectory()) walk(path, base, out);
|
|
1703
|
+
else if (entry.isFile()) out.push(relative3(base, path).split("\\").join("/"));
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
function repoFiles(root) {
|
|
1707
|
+
try {
|
|
1708
|
+
const listed = execFileSync2(
|
|
1709
|
+
"git",
|
|
1710
|
+
["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
1711
|
+
{ cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
1712
|
+
);
|
|
1713
|
+
return listed.split("\0").filter(Boolean).filter((f) => existsSync4(join4(root, f)) && !f.split("/").some((p) => SKIP.has(p)));
|
|
1714
|
+
} catch {
|
|
1715
|
+
const out = [];
|
|
1716
|
+
walk(root, root, out);
|
|
1717
|
+
return out;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
var KEY_FILE = /(^|\/)AuthKey_[A-Za-z0-9]+\.p8$|\.(p8|p12|pfx|jks|keystore|mobileprovision|provisionprofile)$/i;
|
|
1721
|
+
var PRIVATE_KEY = /-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----/;
|
|
1722
|
+
var SERVICE_ACCOUNT = /"type"\s*:\s*"service_account"[\s\S]*"private_key"|"private_key"[\s\S]*"type"\s*:\s*"service_account"/;
|
|
1723
|
+
function keyFiles(root) {
|
|
1724
|
+
const found = [];
|
|
1725
|
+
for (const file of repoFiles(root)) {
|
|
1726
|
+
if (KEY_FILE.test(file)) {
|
|
1727
|
+
found.push(file);
|
|
1728
|
+
continue;
|
|
1729
|
+
}
|
|
1730
|
+
const path = join4(root, file);
|
|
1731
|
+
if (statSync2(path).size > 1e6) continue;
|
|
1732
|
+
const text = readFileSync4(path, "latin1");
|
|
1733
|
+
if (PRIVATE_KEY.test(text) || SERVICE_ACCOUNT.test(text)) found.push(file);
|
|
1734
|
+
}
|
|
1735
|
+
return found;
|
|
1736
|
+
}
|
|
1737
|
+
function appCode(root, product) {
|
|
1738
|
+
const mobile = product.mobile;
|
|
1739
|
+
const generated = join4(mobile.dir, mobile.clientDir ?? "src/client").split("\\").join("/");
|
|
1740
|
+
const files = [];
|
|
1741
|
+
walk(join4(root, mobile.dir), root, files);
|
|
1742
|
+
return files.filter(
|
|
1743
|
+
(f) => /\.(tsx?|jsx?|mjs|cjs)$/.test(f) && !f.startsWith(`${generated}/`) && !/^(android|ios)\//.test(f.slice(mobile.dir.length + 1))
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
var DELETE_ACCOUNT = /["'`]me\.deleteAccount["'`]/;
|
|
1747
|
+
var DELETE_BLOCK = "native-account-delete";
|
|
1748
|
+
function hasDeleteBlock(root, product) {
|
|
1749
|
+
const mobile = product.mobile;
|
|
1750
|
+
const lockPath = join4(root, "blocks.lock.json");
|
|
1751
|
+
if (!existsSync4(lockPath)) return false;
|
|
1752
|
+
const entry = JSON.parse(readFileSync4(lockPath, "utf8"))[DELETE_BLOCK];
|
|
1753
|
+
if (entry?.app !== mobile.dir) return false;
|
|
1754
|
+
const file = join4(root, mobile.dir, "src", "blocks", DELETE_BLOCK, "delete.tsx");
|
|
1755
|
+
return existsSync4(file) && /\bexport\s+function\s+DeleteAccount\b/.test(readFileSync4(file, "utf8"));
|
|
1756
|
+
}
|
|
1757
|
+
function envFlag(product, flags) {
|
|
1758
|
+
const env = str(flags, "env") ?? str(flags, "environment");
|
|
1759
|
+
if (!environmentNames(product).length && env === LIVE_ENVIRONMENT) return void 0;
|
|
1760
|
+
return env;
|
|
1761
|
+
}
|
|
1762
|
+
function buildFor(product, environment) {
|
|
1763
|
+
try {
|
|
1764
|
+
return appBuild(product, environment);
|
|
1765
|
+
} catch (error) {
|
|
1766
|
+
throw new CliError(error.message);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
async function hostOf(flags, deps, product, build) {
|
|
1770
|
+
const env = deps.env;
|
|
1771
|
+
const token = str(flags, "token") ?? env.CLOUDFLARE_API_TOKEN;
|
|
1772
|
+
if (!token) return null;
|
|
1773
|
+
deps.redactor.add(token);
|
|
1774
|
+
const api = new CloudflareClient({
|
|
1775
|
+
token,
|
|
1776
|
+
...env.COS_CLOUDFLARE_API ? { apiBase: env.COS_CLOUDFLARE_API } : {},
|
|
1777
|
+
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
1778
|
+
});
|
|
1779
|
+
let accountId = str(flags, "account") ?? env.CLOUDFLARE_ACCOUNT_ID;
|
|
1780
|
+
if (!accountId) {
|
|
1781
|
+
const accounts = await api.listAccounts();
|
|
1782
|
+
if (accounts.length !== 1)
|
|
1783
|
+
throw new CliError("Pass --account <id> (or CLOUDFLARE_ACCOUNT_ID).");
|
|
1784
|
+
accountId = accounts[0].id;
|
|
1785
|
+
}
|
|
1786
|
+
const named = environmentNames(product).length ? build.environment : void 0;
|
|
1787
|
+
let located = await locateDeployment(api, accountId, clientNames(product, named).database);
|
|
1788
|
+
if (!located?.state && build.environment === LIVE_ENVIRONMENT) {
|
|
1789
|
+
const known = deps.products ?? { all: products, default: DEFAULT_PRODUCT };
|
|
1790
|
+
const release = known.all[product.platform.release];
|
|
1791
|
+
if (release) located = await locateDeployment(api, accountId, release.names.database);
|
|
1792
|
+
}
|
|
1793
|
+
if (!located?.state) {
|
|
1794
|
+
throw new CliError(
|
|
1795
|
+
`There is no ${build.environment} host in this account to record builds in: deploy it first (cos deploy${named ? ` --env ${named}` : ""}).`
|
|
1796
|
+
);
|
|
1797
|
+
}
|
|
1798
|
+
return { api, accountId, databaseId: located.databaseId };
|
|
1799
|
+
}
|
|
1800
|
+
function generatedApiVersion(root, product) {
|
|
1801
|
+
const mobile = product.mobile;
|
|
1802
|
+
const file = join4(root, mobile.dir, mobile.clientDir ?? "src/client", "customer.ts");
|
|
1803
|
+
const found = existsSync4(file) ? /export const API_VERSION = "([^"]+)"/.exec(readFileSync4(file, "utf8")) : null;
|
|
1804
|
+
if (!found) {
|
|
1805
|
+
throw new CliError(
|
|
1806
|
+
`${relative3(root, file)} has no API_VERSION: run pnpm cos client generate first.`
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
return found[1];
|
|
1810
|
+
}
|
|
1811
|
+
function storeOf(build) {
|
|
1812
|
+
if (!build.store) {
|
|
1813
|
+
throw new CliError(
|
|
1814
|
+
"product.ts gives no mobile.app: the app's name, version, store ids, icon, splash, colours and listing (docs: the start-client-app skill)."
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
return build.store;
|
|
1818
|
+
}
|
|
1819
|
+
async function check(flags, deps) {
|
|
1820
|
+
const { io } = deps;
|
|
1821
|
+
const root = resolve2(str(flags, "dir") ?? process.cwd());
|
|
1822
|
+
const product = await loadClientProduct(root);
|
|
1823
|
+
const mobile = product.mobile;
|
|
1824
|
+
if (!mobile) throw new CliError("product.ts has no mobile app (mobile: { dir }).");
|
|
1825
|
+
const problems = [];
|
|
1826
|
+
const notes = [];
|
|
1827
|
+
if (!mobile.app) {
|
|
1828
|
+
problems.push(
|
|
1829
|
+
"product.ts gives no mobile.app: the app's name, version, store ids, icon, splash, colours and listing"
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1832
|
+
const envs = environmentNames(product);
|
|
1833
|
+
const builds = (envs.length ? envs : [void 0]).map((env) => buildFor(product, env));
|
|
1834
|
+
const listings = /* @__PURE__ */ new Set();
|
|
1835
|
+
const images = /* @__PURE__ */ new Set();
|
|
1836
|
+
for (const build of mobile.app ? builds : []) {
|
|
1837
|
+
const store = build.store;
|
|
1838
|
+
const where = envs.length ? `environment ${build.environment}` : "the app";
|
|
1839
|
+
if (!build.hostUrl) {
|
|
1840
|
+
problems.push(
|
|
1841
|
+
envs.length ? `${where}: product.ts gives the host no hostname (environments.${build.environment}.hostname), so the app would not know its host` : "product.ts declares no environments with a hostname, so the app would not know its host's address"
|
|
1842
|
+
);
|
|
1843
|
+
}
|
|
1844
|
+
for (const [path, what, rule] of [
|
|
1845
|
+
[store.icon, "The icon", { size: 1024, opaque: true }],
|
|
1846
|
+
[store.splash.image, "The splash image", {}]
|
|
1847
|
+
]) {
|
|
1848
|
+
if (images.has(path)) continue;
|
|
1849
|
+
images.add(path);
|
|
1850
|
+
const problem = imageProblem(root, path, what, rule);
|
|
1851
|
+
if (problem) problems.push(problem);
|
|
1852
|
+
}
|
|
1853
|
+
if (!listings.has(store.listing)) {
|
|
1854
|
+
listings.add(store.listing);
|
|
1855
|
+
const listed = listingProblems(root, store.listing);
|
|
1856
|
+
problems.push(...listed.problems);
|
|
1857
|
+
notes.push(...listed.notes);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
if (!existsSync4(join4(root, mobile.dir, "app.config.ts"))) {
|
|
1861
|
+
problems.push(
|
|
1862
|
+
`${mobile.dir} has no app.config.ts: the app's name, ids and host come from product.ts through it (the template's app.config.ts)`
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1865
|
+
const brand = brandPath(product);
|
|
1866
|
+
if (!existsSync4(join4(root, brand)) || readFileSync4(join4(root, brand), "utf8") !== brandText(product)) {
|
|
1867
|
+
problems.push(`${brand} is not product.ts's colours: run pnpm cos client generate`);
|
|
1868
|
+
}
|
|
1869
|
+
const code = appCode(root, product);
|
|
1870
|
+
let deletes = hasDeleteBlock(root, product);
|
|
1871
|
+
for (const file of code) {
|
|
1872
|
+
const text = readFileSync4(join4(root, file), "utf8");
|
|
1873
|
+
for (const p of scanPurchases(text)) {
|
|
1874
|
+
problems.push(
|
|
1875
|
+
`${file}:${p.line} names ${p.names}: nothing is bought in the app (ADR 0490); buying and billing stay on the website`
|
|
1876
|
+
);
|
|
1877
|
+
}
|
|
1878
|
+
if (DELETE_ACCOUNT.test(text)) deletes = true;
|
|
1879
|
+
}
|
|
1880
|
+
if (!deletes) {
|
|
1881
|
+
problems.push(
|
|
1882
|
+
`${mobile.dir} has no "Delete my account" (nothing in it calls me.deleteAccount): the stores require it of an app accounts are made in. Add the native account shell's delete section (stage 48)`
|
|
1883
|
+
);
|
|
1884
|
+
}
|
|
1885
|
+
for (const file of keyFiles(root)) {
|
|
1886
|
+
problems.push(
|
|
1887
|
+
`${file} looks like a signing or store key: keys are CI secrets a person sets, never in the repository (cos app credentials). Remove it, and revoke the key if it was ever pushed`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
if (mobile.app) {
|
|
1891
|
+
const env = deps.env;
|
|
1892
|
+
if (str(flags, "token") ?? env.CLOUDFLARE_API_TOKEN) {
|
|
1893
|
+
for (const build of builds) {
|
|
1894
|
+
const host = await hostOf(flags, deps, product, build).catch((error) => {
|
|
1895
|
+
notes.push(`${build.environment}: recorded builds not read: ${error.message}`);
|
|
1896
|
+
return null;
|
|
1897
|
+
});
|
|
1898
|
+
if (!host) continue;
|
|
1899
|
+
const recorded = await appBuildsViaApi(
|
|
1900
|
+
host.api,
|
|
1901
|
+
host.accountId,
|
|
1902
|
+
host.databaseId,
|
|
1903
|
+
build.environment
|
|
1904
|
+
);
|
|
1905
|
+
for (const platform of APP_PLATFORMS) {
|
|
1906
|
+
const store = build.store;
|
|
1907
|
+
const problem = recordedIdProblem(recorded ?? [], platform, store.ids[platform]);
|
|
1908
|
+
if (problem) problems.push(`${build.environment}: ${problem}`);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
} else {
|
|
1912
|
+
notes.push(
|
|
1913
|
+
"Store ids not compared with recorded builds: no Cloudflare token (CLOUDFLARE_API_TOKEN). cos app record compares them too."
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
for (const note of notes) io.out(`note: ${note}`);
|
|
1918
|
+
for (const problem of problems) io.err(`\u2717 ${problem}`);
|
|
1919
|
+
if (problems.length) {
|
|
1920
|
+
io.err(
|
|
1921
|
+
`cos app check: ${problems.length} problem${problems.length > 1 ? "s" : ""}. No store build until each is fixed.`
|
|
1922
|
+
);
|
|
1923
|
+
return 1;
|
|
1924
|
+
}
|
|
1925
|
+
io.out(
|
|
1926
|
+
`cos app check: ready for the stores' testing tracks (${builds.map((b) => `${b.environment}: ${b.name}, ${b.store?.ids.ios} / ${b.store?.ids.android}`).join("; ")}).`
|
|
1927
|
+
);
|
|
1928
|
+
return 0;
|
|
1929
|
+
}
|
|
1930
|
+
var UPLOAD_ENVIRONMENT = "app-upload";
|
|
1931
|
+
var RECORD_ENVIRONMENT = "app-record";
|
|
1932
|
+
var prompt = (name, environment) => `gh secret set ${name} --env ${environment} (asks for the value)`;
|
|
1933
|
+
var APP_SECRETS = [
|
|
1934
|
+
{
|
|
1935
|
+
name: "IOS_STORE_API_KEY",
|
|
1936
|
+
job: "ios",
|
|
1937
|
+
what: "the iPhone store's API key (.p8), made in the client's account with a role that may upload",
|
|
1938
|
+
set: `gh secret set IOS_STORE_API_KEY --env ${UPLOAD_ENVIRONMENT} < AuthKey_<key id>.p8`
|
|
1939
|
+
},
|
|
1940
|
+
{
|
|
1941
|
+
name: "IOS_STORE_API_KEY_ID",
|
|
1942
|
+
job: "ios",
|
|
1943
|
+
what: "that key's id",
|
|
1944
|
+
set: prompt("IOS_STORE_API_KEY_ID", UPLOAD_ENVIRONMENT)
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
name: "IOS_STORE_API_ISSUER_ID",
|
|
1948
|
+
job: "ios",
|
|
1949
|
+
what: "the issuer id shown beside the client's API keys",
|
|
1950
|
+
set: prompt("IOS_STORE_API_ISSUER_ID", UPLOAD_ENVIRONMENT)
|
|
1951
|
+
},
|
|
1952
|
+
{
|
|
1953
|
+
name: "IOS_TEAM_ID",
|
|
1954
|
+
job: "ios",
|
|
1955
|
+
what: "the client's developer team id",
|
|
1956
|
+
set: prompt("IOS_TEAM_ID", UPLOAD_ENVIRONMENT)
|
|
1957
|
+
},
|
|
1958
|
+
{
|
|
1959
|
+
name: "IOS_DISTRIBUTION_CERTIFICATE",
|
|
1960
|
+
job: "ios",
|
|
1961
|
+
what: "the distribution certificate and its private key, exported as .p12, in base64",
|
|
1962
|
+
set: `base64 < distribution.p12 | gh secret set IOS_DISTRIBUTION_CERTIFICATE --env ${UPLOAD_ENVIRONMENT}`
|
|
1963
|
+
},
|
|
1964
|
+
{
|
|
1965
|
+
name: "IOS_DISTRIBUTION_CERTIFICATE_PASSWORD",
|
|
1966
|
+
job: "ios",
|
|
1967
|
+
what: "the .p12's password",
|
|
1968
|
+
set: prompt("IOS_DISTRIBUTION_CERTIFICATE_PASSWORD", UPLOAD_ENVIRONMENT)
|
|
1969
|
+
},
|
|
1970
|
+
{
|
|
1971
|
+
name: "ANDROID_UPLOAD_KEYSTORE",
|
|
1972
|
+
job: "android",
|
|
1973
|
+
what: "the Android upload key (a keystore with the key under the alias upload), in base64; the store keeps the app's own signing key",
|
|
1974
|
+
set: `base64 < upload.jks | gh secret set ANDROID_UPLOAD_KEYSTORE --env ${UPLOAD_ENVIRONMENT}`
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
name: "ANDROID_UPLOAD_KEYSTORE_PASSWORD",
|
|
1978
|
+
job: "android",
|
|
1979
|
+
what: "the keystore's password (the key's too)",
|
|
1980
|
+
set: prompt("ANDROID_UPLOAD_KEYSTORE_PASSWORD", UPLOAD_ENVIRONMENT)
|
|
1981
|
+
},
|
|
1982
|
+
{
|
|
1983
|
+
name: "ANDROID_STORE_SERVICE_ACCOUNT",
|
|
1984
|
+
job: "android",
|
|
1985
|
+
what: "the Android store's upload account key (JSON), invited to the client's account with the release role for testing tracks",
|
|
1986
|
+
set: `gh secret set ANDROID_STORE_SERVICE_ACCOUNT --env ${UPLOAD_ENVIRONMENT} < service-account.json`
|
|
1987
|
+
},
|
|
1988
|
+
{
|
|
1989
|
+
name: "CLOUDFLARE_API_TOKEN",
|
|
1990
|
+
job: "record",
|
|
1991
|
+
what: "the deploy credential, to read and record builds in the host's database: only the small Linux jobs that run cos hold it, never a build job",
|
|
1992
|
+
set: prompt("CLOUDFLARE_API_TOKEN", RECORD_ENVIRONMENT)
|
|
1993
|
+
},
|
|
1994
|
+
{
|
|
1995
|
+
name: "CLOUDFLARE_ACCOUNT_ID",
|
|
1996
|
+
job: "record",
|
|
1997
|
+
what: "the Cloudflare account the host is in",
|
|
1998
|
+
set: prompt("CLOUDFLARE_ACCOUNT_ID", RECORD_ENVIRONMENT)
|
|
1999
|
+
}
|
|
2000
|
+
];
|
|
2001
|
+
var JOBS = ["ios", "android", "record"];
|
|
2002
|
+
async function credentials(flags, deps) {
|
|
2003
|
+
const { io } = deps;
|
|
2004
|
+
const job = str(flags, "for");
|
|
2005
|
+
if (job && !JOBS.includes(job)) {
|
|
2006
|
+
throw new CliError(`--for is one of ${JOBS.join(", ")}.`);
|
|
2007
|
+
}
|
|
2008
|
+
const wanted = APP_SECRETS.filter((s) => !job || s.job === job);
|
|
2009
|
+
if (flags.check) {
|
|
2010
|
+
const env = deps.env;
|
|
2011
|
+
const missing = wanted.filter((s) => !env[s.name]?.trim());
|
|
2012
|
+
if (!missing.length) {
|
|
2013
|
+
io.out(`Every secret ${job ? `the ${job} job needs` : "the workflow needs"} is set.`);
|
|
2014
|
+
return 0;
|
|
2015
|
+
}
|
|
2016
|
+
io.err(
|
|
2017
|
+
`Missing ${missing.length === 1 ? "a secret" : `${missing.length} secrets`}${job ? ` for the ${job} job` : ""}: ${missing.map((s) => s.name).join(", ")}. A person sets each (never an AI, never in the repository):`
|
|
2018
|
+
);
|
|
2019
|
+
for (const s of missing) io.err(` ${s.name}: ${s.what}
|
|
2020
|
+
${s.set}`);
|
|
2021
|
+
return 1;
|
|
2022
|
+
}
|
|
2023
|
+
io.out(
|
|
2024
|
+
`The app workflow's secrets (stage 63). Each is made in the client's own store or Cloudflare account and set by a person as a secret of a protected CI environment (${UPLOAD_ENVIRONMENT} for the build jobs, ${RECORD_ENVIRONMENT} for the jobs that read and record builds). cos never prints a value.`
|
|
2025
|
+
);
|
|
2026
|
+
for (const j of JOBS) {
|
|
2027
|
+
const list = wanted.filter((s) => s.job === j);
|
|
2028
|
+
if (!list.length) continue;
|
|
2029
|
+
io.out(
|
|
2030
|
+
`
|
|
2031
|
+
${j === "record" ? "build numbers and records" : `${j} build and upload`} (${j === "record" ? RECORD_ENVIRONMENT : UPLOAD_ENVIRONMENT}):`
|
|
2032
|
+
);
|
|
2033
|
+
for (const s of list) io.out(` ${s.name}: ${s.what}
|
|
2034
|
+
${s.set}`);
|
|
2035
|
+
}
|
|
2036
|
+
return 0;
|
|
2037
|
+
}
|
|
2038
|
+
async function buildInfo(flags, deps) {
|
|
2039
|
+
const root = resolve2(str(flags, "dir") ?? process.cwd());
|
|
2040
|
+
const product = await loadClientProduct(root);
|
|
2041
|
+
if (!product.mobile) throw new CliError("product.ts has no mobile app (mobile: { dir }).");
|
|
2042
|
+
const build = buildFor(product, envFlag(product, flags));
|
|
2043
|
+
const store = storeOf(build);
|
|
2044
|
+
const apiVersion = generatedApiVersion(root, product);
|
|
2045
|
+
const host = await hostOf(flags, deps, product, build);
|
|
2046
|
+
if (!host) {
|
|
2047
|
+
throw new CliError(
|
|
2048
|
+
"The next build number is read from the host's recorded builds: give the deploy credential (CLOUDFLARE_API_TOKEN)."
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
const recorded = await appBuildsViaApi(
|
|
2052
|
+
host.api,
|
|
2053
|
+
host.accountId,
|
|
2054
|
+
host.databaseId,
|
|
2055
|
+
build.environment
|
|
2056
|
+
);
|
|
2057
|
+
const info = {
|
|
2058
|
+
environment: build.environment,
|
|
2059
|
+
version: build.version,
|
|
2060
|
+
build: nextBuildNumber(recorded ?? []),
|
|
2061
|
+
apiVersion,
|
|
2062
|
+
ids: store.ids
|
|
2063
|
+
};
|
|
2064
|
+
if (flags.json) deps.io.out(JSON.stringify(info));
|
|
2065
|
+
else {
|
|
2066
|
+
deps.io.out(
|
|
2067
|
+
`${build.name} (${info.environment}) ${info.version}, build ${info.build}, API ${info.apiVersion}: ${info.ids.ios} / ${info.ids.android}`
|
|
2068
|
+
);
|
|
2069
|
+
}
|
|
2070
|
+
return 0;
|
|
2071
|
+
}
|
|
2072
|
+
function platformsOf(flags) {
|
|
2073
|
+
const list = (str(flags, "platform") ?? "").split(",").map((p) => p.trim()).filter(Boolean);
|
|
2074
|
+
const bad = list.filter((p) => !APP_PLATFORMS.includes(p));
|
|
2075
|
+
if (!list.length || bad.length) {
|
|
2076
|
+
throw new CliError(
|
|
2077
|
+
`--platform is ios, android or both (ios,android)${bad.length ? `, not ${bad.join(", ")}` : ""}.`
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
return [...new Set(list)];
|
|
2081
|
+
}
|
|
2082
|
+
function commitOf(flags, deps, root) {
|
|
2083
|
+
const given = str(flags, "commit") ?? deps.env.GITHUB_SHA;
|
|
2084
|
+
if (given) {
|
|
2085
|
+
if (!/^[0-9a-f]{7,40}$/.test(given)) throw new CliError("--commit is a commit's sha.");
|
|
2086
|
+
return given;
|
|
2087
|
+
}
|
|
2088
|
+
try {
|
|
2089
|
+
return execFileSync2("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" }).trim();
|
|
2090
|
+
} catch {
|
|
2091
|
+
return null;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
async function record(flags, deps) {
|
|
2095
|
+
const root = resolve2(str(flags, "dir") ?? process.cwd());
|
|
2096
|
+
const product = await loadClientProduct(root);
|
|
2097
|
+
if (!product.mobile) throw new CliError("product.ts has no mobile app (mobile: { dir }).");
|
|
2098
|
+
const build = buildFor(product, envFlag(product, flags));
|
|
2099
|
+
const store = storeOf(build);
|
|
2100
|
+
const platforms = platformsOf(flags);
|
|
2101
|
+
const number = Number(str(flags, "build"));
|
|
2102
|
+
if (!Number.isInteger(number) || number < 1) {
|
|
2103
|
+
throw new CliError("--build is the build number the run used (cos app build-info).");
|
|
2104
|
+
}
|
|
2105
|
+
const apiVersion = generatedApiVersion(root, product);
|
|
2106
|
+
const host = await hostOf(flags, deps, product, build);
|
|
2107
|
+
if (!host) {
|
|
2108
|
+
throw new CliError(
|
|
2109
|
+
"cos app record writes the host's database: give the deploy credential (CLOUDFLARE_API_TOKEN)."
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
const commit = commitOf(flags, deps, root);
|
|
2113
|
+
const uploadedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2114
|
+
for (const platform of platforms) {
|
|
2115
|
+
const row = {
|
|
2116
|
+
environment: build.environment,
|
|
2117
|
+
platform,
|
|
2118
|
+
app_version: build.version,
|
|
2119
|
+
build_number: number,
|
|
2120
|
+
api_version: apiVersion,
|
|
2121
|
+
app_id: store.ids[platform],
|
|
2122
|
+
commit_sha: commit,
|
|
2123
|
+
uploaded_at: uploadedAt,
|
|
2124
|
+
supported: 1
|
|
2125
|
+
};
|
|
2126
|
+
let result;
|
|
2127
|
+
try {
|
|
2128
|
+
result = await recordAppBuildViaApi(host.api, host.accountId, host.databaseId, row);
|
|
2129
|
+
} catch (error) {
|
|
2130
|
+
if (error instanceof AppBuildRefused) throw new CliError(`Not recorded: ${error.message}.`);
|
|
2131
|
+
throw error;
|
|
2132
|
+
}
|
|
2133
|
+
deps.io.out(
|
|
2134
|
+
`${result === "recorded" ? "Recorded" : "Already recorded"}: ${platform} build ${number} of ${build.name} ${build.version} (${row.app_id}, API ${apiVersion}) for ${build.environment}.`
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2137
|
+
return 0;
|
|
2138
|
+
}
|
|
2139
|
+
async function runApp(argv, deps) {
|
|
2140
|
+
const commands = {
|
|
2141
|
+
check,
|
|
2142
|
+
credentials,
|
|
2143
|
+
"build-info": buildInfo,
|
|
2144
|
+
record,
|
|
2145
|
+
upload: async (flags2, d) => (await import("./app-upload-LH4PXKI4.js")).upload(flags2, d)
|
|
2146
|
+
};
|
|
2147
|
+
const command = commands[argv[0] ?? ""];
|
|
2148
|
+
if (!command) {
|
|
2149
|
+
deps.io.err(APP_USAGE);
|
|
2150
|
+
return 2;
|
|
2151
|
+
}
|
|
2152
|
+
let flags;
|
|
2153
|
+
try {
|
|
2154
|
+
flags = parseArgs([argv[0], ...argv.slice(1)]).flags;
|
|
2155
|
+
} catch (error) {
|
|
2156
|
+
deps.io.err(error.message);
|
|
2157
|
+
return 2;
|
|
2158
|
+
}
|
|
2159
|
+
try {
|
|
2160
|
+
return await command(flags, deps);
|
|
2161
|
+
} catch (error) {
|
|
2162
|
+
deps.io.err(`Error: ${error.message}`);
|
|
2163
|
+
return 1;
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
|
|
1401
2167
|
export {
|
|
2168
|
+
APP_USAGE,
|
|
2169
|
+
brandPath,
|
|
2170
|
+
brandText,
|
|
2171
|
+
writeBrand,
|
|
2172
|
+
LISTING_FILES,
|
|
2173
|
+
listingLocales,
|
|
2174
|
+
listingText,
|
|
2175
|
+
pngInfo,
|
|
2176
|
+
keyFiles,
|
|
2177
|
+
envFlag,
|
|
2178
|
+
buildFor,
|
|
2179
|
+
generatedApiVersion,
|
|
2180
|
+
UPLOAD_ENVIRONMENT,
|
|
2181
|
+
RECORD_ENVIRONMENT,
|
|
2182
|
+
APP_SECRETS,
|
|
2183
|
+
runApp,
|
|
1402
2184
|
lineDiff,
|
|
1403
2185
|
hostRoutes,
|
|
1404
2186
|
edgeRuleStep,
|
|
@@ -1420,6 +2202,7 @@ export {
|
|
|
1420
2202
|
deploy,
|
|
1421
2203
|
upgradeRepo,
|
|
1422
2204
|
kitPacks,
|
|
2205
|
+
requiredPacks,
|
|
1423
2206
|
regenerate,
|
|
1424
2207
|
isClientRepo
|
|
1425
2208
|
};
|