@composable-os/cli 0.1.0-beta.11 → 0.1.0-beta.13
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-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-DE4RRWPJ.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-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-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-MBIKVRAC.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-PDD2ETVF.js → chunk-QQ3YSL5F.js} +172 -16
- 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-NNUCHQ2Y.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-QQ3YSL5F.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";
|
|
@@ -143,15 +159,16 @@ function recordHostModules(root, product, kit, version) {
|
|
|
143
159
|
function upgradeHostModules(root, product, kit, version, io) {
|
|
144
160
|
const state = readState(root);
|
|
145
161
|
state.hostModules ??= {};
|
|
162
|
+
const modules = state.hostModules;
|
|
146
163
|
const replaced = [];
|
|
147
164
|
const edited = [];
|
|
148
165
|
for (const place of hostModulePlaces(product)) {
|
|
149
166
|
const next = templateText(kit, place);
|
|
150
167
|
if (next === null) continue;
|
|
151
168
|
const path = join(root, place.path);
|
|
152
|
-
const recorded =
|
|
153
|
-
const
|
|
154
|
-
|
|
169
|
+
const recorded = modules[place.path];
|
|
170
|
+
const record2 = () => {
|
|
171
|
+
modules[place.path] = {
|
|
155
172
|
template: place.template,
|
|
156
173
|
version,
|
|
157
174
|
sha256: sha(next)
|
|
@@ -160,18 +177,18 @@ function upgradeHostModules(root, product, kit, version, io) {
|
|
|
160
177
|
if (!existsSync(path)) {
|
|
161
178
|
mkdirSync(dirname(path), { recursive: true });
|
|
162
179
|
writeFileSync(path, next);
|
|
163
|
-
|
|
180
|
+
record2();
|
|
164
181
|
replaced.push(`${place.path} (new)`);
|
|
165
182
|
continue;
|
|
166
183
|
}
|
|
167
184
|
const current = readFileSync(path, "utf8");
|
|
168
185
|
if (current === next) {
|
|
169
|
-
|
|
186
|
+
record2();
|
|
170
187
|
continue;
|
|
171
188
|
}
|
|
172
189
|
if (recorded && sha(current) === recorded.sha256) {
|
|
173
190
|
writeFileSync(path, next);
|
|
174
|
-
|
|
191
|
+
record2();
|
|
175
192
|
replaced.push(place.path);
|
|
176
193
|
continue;
|
|
177
194
|
}
|
|
@@ -300,13 +317,18 @@ function hostRoutes(product) {
|
|
|
300
317
|
];
|
|
301
318
|
}
|
|
302
319
|
function edgeRuleStep(product) {
|
|
303
|
-
const expression =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
320
|
+
const expression = [
|
|
321
|
+
...hostRoutes(product).map((route) => `starts_with(http.request.uri.path, "${route}")`),
|
|
322
|
+
// With Forms, the form page the site forwards to the host (stage 29, ADR 0728): a form's own
|
|
323
|
+
// page and a personal link's, which post to the host as the operation route does.
|
|
324
|
+
...product?.packs?.includes("forms") ? ['starts_with(http.request.uri.path, "/f/")', 'http.request.uri.path eq "/form"'] : []
|
|
325
|
+
].join(" or ");
|
|
326
|
+
return `The host limits calls from the web app itself, per visitor (ADR 0940). Against floods, also
|
|
327
|
+
add a rate limiting rule on the web app's zone (Security > WAF > Rate limiting rules): calls over
|
|
328
|
+
the binding do not pass the host's zone. It names only the routes that reach the host (web.routes in
|
|
307
329
|
product.ts), so the site's own pages and API are not limited by it:
|
|
308
330
|
Expression: (${expression})
|
|
309
|
-
Counting: IP (ip.src),
|
|
331
|
+
Counting: IP (ip.src), 300 requests per 10 seconds; action Block for 10 seconds`;
|
|
310
332
|
}
|
|
311
333
|
var KIT = { template: "template/", skills: "skills/", blocks: "blocks/", contract: "contract/" };
|
|
312
334
|
var decode2 = (bytes) => new TextDecoder().decode(bytes);
|
|
@@ -413,8 +435,8 @@ function appClients(product) {
|
|
|
413
435
|
return out;
|
|
414
436
|
}
|
|
415
437
|
async function generateClients(root, product, kit, io) {
|
|
416
|
-
const { releaseContract, renderClient } = await import("./src-
|
|
417
|
-
const { loadExtension } = await import("./cli-
|
|
438
|
+
const { releaseContract, renderClient } = await import("./src-PHRELWN5.js");
|
|
439
|
+
const { loadExtension } = await import("./cli-OKQHHSOE.js");
|
|
418
440
|
const perAudience = ["customer", "public", "staff"].map((audience) => {
|
|
419
441
|
const bytes = kit.get(`${KIT.contract}${audience}.json`);
|
|
420
442
|
if (!bytes) throw new CliError(`The release's client kit has no ${audience} contract.`);
|
|
@@ -430,33 +452,66 @@ async function generateClients(root, product, kit, io) {
|
|
|
430
452
|
written.push(join3(dir, "customer.ts"));
|
|
431
453
|
}
|
|
432
454
|
const roles = product.mobile?.roles ?? [];
|
|
433
|
-
|
|
434
|
-
|
|
455
|
+
const owner = product.mobile?.owner === true;
|
|
456
|
+
if ((roles.length || owner) && product.mobile) {
|
|
457
|
+
const { renderOwnerClient, renderRoleClient } = await import("./src-PHRELWN5.js");
|
|
435
458
|
const rolesFile = kit.get(`${KIT.contract}roles.json`);
|
|
436
459
|
if (!rolesFile) {
|
|
437
460
|
throw new CliError(
|
|
438
461
|
"The release's client kit has no roles.json: it is older than role clients. Upgrade the platform version first."
|
|
439
462
|
);
|
|
440
463
|
}
|
|
441
|
-
const
|
|
464
|
+
const parsed = JSON.parse(decode2(rolesFile));
|
|
465
|
+
const declared = parsed.roles;
|
|
442
466
|
const staff = perAudience[2];
|
|
443
467
|
const dir = join3(product.mobile.dir, product.mobile.clientDir ?? "src/client", "roles");
|
|
444
468
|
mkdirSync2(join3(root, dir), { recursive: true });
|
|
445
|
-
|
|
469
|
+
if (owner) {
|
|
470
|
+
if (!parsed.owner) {
|
|
471
|
+
throw new CliError(
|
|
472
|
+
"The release's roles.json has no owner's client (mobile.owner): it is older than it. Upgrade the platform version first."
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
writeFileSync3(
|
|
476
|
+
join3(root, dir, "owner.ts"),
|
|
477
|
+
renderOwnerClient(staff, parsed.owner, { product: product.id })
|
|
478
|
+
);
|
|
479
|
+
written.push(join3(dir, "owner.ts"));
|
|
480
|
+
}
|
|
481
|
+
for (const entry of roles) {
|
|
482
|
+
const { role: name, grants } = mobileRole(entry);
|
|
446
483
|
const role = declared.find((r) => r.name === name);
|
|
447
484
|
if (!role) {
|
|
448
485
|
throw new CliError(
|
|
449
486
|
`The release has no pack role ${name}. Its roles: ${declared.map((r) => r.name).join(", ") || "none"}.`
|
|
450
487
|
);
|
|
451
488
|
}
|
|
489
|
+
const granted = [];
|
|
490
|
+
for (const permission of grants) {
|
|
491
|
+
const grant = parsed.grants?.find((g) => g.permission === permission);
|
|
492
|
+
if (!grant) {
|
|
493
|
+
throw new CliError(
|
|
494
|
+
`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)"}.`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
if (grant.restricted) {
|
|
498
|
+
io.out(
|
|
499
|
+
`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.`
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
granted.push(...grant.operations);
|
|
503
|
+
}
|
|
504
|
+
const withGrants = granted.length ? { ...role, operations: [.../* @__PURE__ */ new Set([...role.operations, ...granted])].sort() } : role;
|
|
452
505
|
writeFileSync3(
|
|
453
506
|
join3(root, dir, `${name}.ts`),
|
|
454
|
-
renderRoleClient(staff,
|
|
507
|
+
renderRoleClient(staff, withGrants, { product: product.id, grants })
|
|
455
508
|
);
|
|
456
509
|
written.push(join3(dir, `${name}.ts`));
|
|
457
510
|
}
|
|
458
511
|
}
|
|
459
512
|
if (written.length) io.out(`Typed client: ${written.join(", ")}`);
|
|
513
|
+
const brand = product.mobile && existsSync3(join3(root, product.mobile.dir)) ? writeBrand(root, product) : null;
|
|
514
|
+
if (brand) written.push(brand);
|
|
460
515
|
return written;
|
|
461
516
|
}
|
|
462
517
|
async function typeErrors(root, product) {
|
|
@@ -508,6 +563,8 @@ function appPackage(text, name, version) {
|
|
|
508
563
|
const pkg = JSON.parse(text);
|
|
509
564
|
pkg.name = name;
|
|
510
565
|
delete pkg.description;
|
|
566
|
+
const scripts = pkg.scripts;
|
|
567
|
+
if (scripts?.typecheck?.includes("tsconfig.platform.json")) scripts.typecheck = "tsc --noEmit";
|
|
511
568
|
for (const key of ["dependencies", "devDependencies"]) {
|
|
512
569
|
const deps = pkg[key];
|
|
513
570
|
for (const [dep, range] of Object.entries(deps ?? {})) {
|
|
@@ -532,12 +589,6 @@ function templateFiles(kit, values) {
|
|
|
532
589
|
const app = /^apps\/([^/]+)\/(package\.json|wrangler\.jsonc)$/.exec(rel);
|
|
533
590
|
if (app?.[2] === "package.json")
|
|
534
591
|
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
592
|
if (app?.[2] === "wrangler.jsonc") {
|
|
542
593
|
text = text.replace(/"name":\s*"client-web"/, `"name": "${values.id}-web"`).replace(/"service":\s*"cos-app"/, `"service": "${values.appWorker}"`);
|
|
543
594
|
}
|
|
@@ -548,6 +599,24 @@ function templateFiles(kit, values) {
|
|
|
548
599
|
function slug(name) {
|
|
549
600
|
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
550
601
|
}
|
|
602
|
+
var APP_WORKFLOW = ".github/workflows/app.yml";
|
|
603
|
+
var MOBILE_ENTRY = ` mobile: {
|
|
604
|
+
dir: "apps/mobile",
|
|
605
|
+
// The app's identity in the phone app stores (stage 63): app.config.ts and the app's brand are
|
|
606
|
+
// made from it. Fill it in before the first store build, then run \`pnpm cos app check\`.
|
|
607
|
+
// app: {
|
|
608
|
+
// name: "Example", // under the icon, at most 30 characters
|
|
609
|
+
// version: "1.0.0",
|
|
610
|
+
// ids: { ios: "com.example.app", android: "com.example.app" }, // never change once published
|
|
611
|
+
// icon: "apps/mobile/assets/icon.png", // 1024 by 1024, no transparency
|
|
612
|
+
// splash: { image: "apps/mobile/assets/splash.png", background: "#ffffff" },
|
|
613
|
+
// colours: { primary: "#18181b", background: "#ffffff", text: "#18181b" },
|
|
614
|
+
// listing: "apps/mobile/store", // <locale>/name.txt, subtitle.txt, description.txt, \u2026
|
|
615
|
+
// purchases: "none",
|
|
616
|
+
// },
|
|
617
|
+
// A staging app installs beside the live one with its own name, ids and scheme:
|
|
618
|
+
// environments.staging.mobile: { scheme: "example-staging", app: { name, ids } }.
|
|
619
|
+
},`;
|
|
551
620
|
async function create(argv, flags, deps) {
|
|
552
621
|
const { io } = deps;
|
|
553
622
|
const target = argv[0];
|
|
@@ -582,13 +651,11 @@ async function create(argv, flags, deps) {
|
|
|
582
651
|
const files = templateFiles(kit, values);
|
|
583
652
|
const mobile = Boolean(flags["with-mobile"]);
|
|
584
653
|
for (const path of [...files.keys()])
|
|
585
|
-
if (!mobile && path.startsWith("apps/mobile/")) files.delete(path);
|
|
654
|
+
if (!mobile && (path.startsWith("apps/mobile/") || path === APP_WORKFLOW)) files.delete(path);
|
|
586
655
|
if (mobile) {
|
|
587
656
|
const product2 = files.get("product.ts");
|
|
588
|
-
files.set(
|
|
589
|
-
|
|
590
|
-
product2.replace(/(\n\s*web: \{[^\n]*\},)/, '$1\n mobile: { dir: "apps/mobile" },')
|
|
591
|
-
);
|
|
657
|
+
files.set("product.ts", product2.replace(/(\n\s*web: \{[^\n]*\},)/, `$1
|
|
658
|
+
${MOBILE_ENTRY}`));
|
|
592
659
|
}
|
|
593
660
|
for (const [path, text] of files) {
|
|
594
661
|
mkdirSync2(dirname3(join3(root, path)), { recursive: true });
|
|
@@ -596,6 +663,12 @@ async function create(argv, flags, deps) {
|
|
|
596
663
|
}
|
|
597
664
|
const skills = writeSkills(root, kit);
|
|
598
665
|
const product = await loadClientProduct(root);
|
|
666
|
+
if (mobile && product.mobile && kit.has("blocks/native-account/block.json")) {
|
|
667
|
+
const { copyBlocks, saveLock } = await import("./blocks-DE4RRWPJ.js");
|
|
668
|
+
const lock = {};
|
|
669
|
+
copyBlocks(root, product, kit, version, ["native-account"], lock);
|
|
670
|
+
saveLock(root, lock);
|
|
671
|
+
}
|
|
599
672
|
await generateClients(root, product, kit, io);
|
|
600
673
|
recordHostModules(root, product, kit, version);
|
|
601
674
|
try {
|
|
@@ -717,7 +790,7 @@ async function init(flags, deps) {
|
|
|
717
790
|
};
|
|
718
791
|
const guessWeb = wranglerConfig(root) ? "." : void 0;
|
|
719
792
|
const guessMobile = ["mobile", "app", "apps/mobile"].find(
|
|
720
|
-
(d) => existsSync3(join3(root, d,
|
|
793
|
+
(d) => ["app.json", "app.config.ts", "app.config.js"].some((f) => existsSync3(join3(root, d, f)))
|
|
721
794
|
);
|
|
722
795
|
const webDir = str(flags, "web") ?? await ask("Where is the web app (its Worker)?", guessWeb);
|
|
723
796
|
const mobileDir = str(flags, "mobile") ?? await ask("Where is the mobile app?", guessMobile);
|
|
@@ -921,12 +994,12 @@ ${edgeRuleStep(product)}`);
|
|
|
921
994
|
return 0;
|
|
922
995
|
}
|
|
923
996
|
function orgExtensionSources(root) {
|
|
924
|
-
const
|
|
997
|
+
const SKIP2 = /* @__PURE__ */ new Set(["node_modules", "test", "tests", "dist", ".turbo"]);
|
|
925
998
|
const files = (dir, base, out) => {
|
|
926
999
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
927
1000
|
const path = join3(dir, entry.name);
|
|
928
1001
|
if (entry.isDirectory()) {
|
|
929
|
-
if (!
|
|
1002
|
+
if (!SKIP2.has(entry.name)) files(path, base, out);
|
|
930
1003
|
} else if (/\.(ts|js)$/.test(entry.name) && !/\.(test|config)\.(ts|js)$/.test(entry.name)) {
|
|
931
1004
|
out[relative2(base, path).split("\\").join("/")] = readFileSync3(path, "utf8");
|
|
932
1005
|
}
|
|
@@ -941,7 +1014,7 @@ function orgExtensionSources(root) {
|
|
|
941
1014
|
async function checkOrgExtensions(root, io) {
|
|
942
1015
|
const dirs = orgExtensionDirs(root);
|
|
943
1016
|
if (!dirs.length) return true;
|
|
944
|
-
const { runExt } = await import("./cli-
|
|
1017
|
+
const { runExt } = await import("./cli-VYSD2S4Z.js");
|
|
945
1018
|
let ok = true;
|
|
946
1019
|
for (const dir of dirs) {
|
|
947
1020
|
io.out(`cos ext check ${relative2(root, dir)}`);
|
|
@@ -1134,9 +1207,10 @@ function gatekeeperPlan(manifest, product, environment) {
|
|
|
1134
1207
|
}
|
|
1135
1208
|
vars[worker.name] = { ...vars[worker.name], [key]: String(value) };
|
|
1136
1209
|
}
|
|
1137
|
-
|
|
1210
|
+
const fake = vars[worker.name]?.PAYMENTS_FAKE_PROVIDER === "true" ? "the fake payment provider" : vars[worker.name]?.TEXT_PROVIDER === "fake" ? "the fake text provider" : null;
|
|
1211
|
+
if (fake && isLiveEnvironment(product, environment)) {
|
|
1138
1212
|
return {
|
|
1139
|
-
problem: `${where} is live and turns on
|
|
1213
|
+
problem: `${where} is live and turns on ${fake}: only an environment marked live: false may.`
|
|
1140
1214
|
};
|
|
1141
1215
|
}
|
|
1142
1216
|
}
|
|
@@ -1195,13 +1269,21 @@ async function deploy(flags, deps) {
|
|
|
1195
1269
|
const { bundle } = await verified(source, product.platform.version, scoped);
|
|
1196
1270
|
const manifest = bundle.manifest;
|
|
1197
1271
|
const inRelease = kitPacks(bundle.clientFiles);
|
|
1198
|
-
const
|
|
1272
|
+
const brought = requiredPacks(bundle.clientFiles, product.packs);
|
|
1273
|
+
const missing = [...product.packs, ...brought].filter((pack) => !inRelease.has(pack));
|
|
1199
1274
|
if (missing.length) {
|
|
1200
1275
|
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.`
|
|
1276
|
+
`${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
1277
|
);
|
|
1203
1278
|
return 1;
|
|
1204
1279
|
}
|
|
1280
|
+
if (brought.length) {
|
|
1281
|
+
hostFlags.packs = [...product.packs, ...brought].join(",");
|
|
1282
|
+
const them = brought.length > 1 ? "them" : "it";
|
|
1283
|
+
io.out(
|
|
1284
|
+
`Installing ${brought.join(", ")} too: a pack product.ts lists requires ${them}. Add ${them} to packs in product.ts to say so there.`
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1205
1287
|
const gatekeepers = gatekeeperPlan(manifest, product, environment);
|
|
1206
1288
|
if ("problem" in gatekeepers) {
|
|
1207
1289
|
io.err(`${gatekeepers.problem} Nothing was deployed.`);
|
|
@@ -1248,12 +1330,14 @@ async function deploy(flags, deps) {
|
|
|
1248
1330
|
hostFlags["customer-auth-url"] = webOrigin;
|
|
1249
1331
|
}
|
|
1250
1332
|
hostFlags["native-redirect-uris"] = nativeRedirectUris(product, environment);
|
|
1333
|
+
hostFlags.location = clientLocation(product, environment) ?? "none";
|
|
1251
1334
|
const found = ownHost?.state ? ownHost : legacyHost;
|
|
1252
1335
|
if (found?.state && found.state.version !== product.platform.version) {
|
|
1253
1336
|
io.out(
|
|
1254
1337
|
`The host${envLabel} is on ${found.state.version}; moving it to ${product.platform.version}.`
|
|
1255
1338
|
);
|
|
1256
|
-
const
|
|
1339
|
+
const { location: _location, ...upgradeFlags } = hostFlags;
|
|
1340
|
+
const code2 = await upgrade(upgradeFlags, scoped);
|
|
1257
1341
|
if (code2 !== 0) return code2;
|
|
1258
1342
|
}
|
|
1259
1343
|
const code = await install(hostFlags, scoped);
|
|
@@ -1314,10 +1398,12 @@ async function upgradeRepo(flags, deps) {
|
|
|
1314
1398
|
if (version === product.platform.version) {
|
|
1315
1399
|
io.out(`Already on ${version}. Checking the host modules against its template.`);
|
|
1316
1400
|
upgradeHostModules(root, product, kit, version, io);
|
|
1401
|
+
const { rewriteAccountSections: rewriteAccountSections2 } = await import("./blocks-DE4RRWPJ.js");
|
|
1402
|
+
rewriteAccountSections2(root, product, kit, version, io);
|
|
1317
1403
|
return packagesAndTypes(root, product, version, io);
|
|
1318
1404
|
}
|
|
1319
1405
|
io.out(`Moving from ${product.platform.version} to ${version}.`);
|
|
1320
|
-
const { CONTRACT_VERSION } = await import("./src-
|
|
1406
|
+
const { CONTRACT_VERSION } = await import("./src-52VERUPK.js");
|
|
1321
1407
|
if (orgExtensionDirs(root).length && !manifest.extensionContract.supported.includes(CONTRACT_VERSION)) {
|
|
1322
1408
|
io.err(
|
|
1323
1409
|
`${version} does not support extension contract ${CONTRACT_VERSION}, which extensions/ is written against: nothing changed.`
|
|
@@ -1333,6 +1419,8 @@ async function upgradeRepo(flags, deps) {
|
|
|
1333
1419
|
const moved = await loadClientProduct(root);
|
|
1334
1420
|
await generateClients(root, moved, kit, io);
|
|
1335
1421
|
io.out(`Skills: ${writeSkills(root, kit)} replaced.`);
|
|
1422
|
+
const { rewriteAccountSections } = await import("./blocks-DE4RRWPJ.js");
|
|
1423
|
+
rewriteAccountSections(root, moved, kit, version, io);
|
|
1336
1424
|
upgradeHostModules(root, moved, kit, version, io);
|
|
1337
1425
|
return packagesAndTypes(root, moved, version, io);
|
|
1338
1426
|
}
|
|
@@ -1379,6 +1467,20 @@ function kitPacks(kit) {
|
|
|
1379
1467
|
if (!listed) return /* @__PURE__ */ new Set();
|
|
1380
1468
|
return new Set(JSON.parse(decode2(listed)));
|
|
1381
1469
|
}
|
|
1470
|
+
function requiredPacks(kit, packs) {
|
|
1471
|
+
const file = kit.get(`${KIT.contract}roles.json`);
|
|
1472
|
+
const requires = file ? JSON.parse(decode2(file)).requires ?? {} : {};
|
|
1473
|
+
const brought = [];
|
|
1474
|
+
const visit = (pack) => {
|
|
1475
|
+
for (const needed of requires[pack] ?? []) {
|
|
1476
|
+
if (packs.includes(needed) || brought.includes(needed)) continue;
|
|
1477
|
+
brought.push(needed);
|
|
1478
|
+
visit(needed);
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
for (const pack of packs) visit(pack);
|
|
1482
|
+
return brought;
|
|
1483
|
+
}
|
|
1382
1484
|
async function regenerate(flags, deps) {
|
|
1383
1485
|
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
1384
1486
|
const product = await loadClientProduct(root);
|
|
@@ -1398,7 +1500,683 @@ function isClientRepo(dir) {
|
|
|
1398
1500
|
return existsSync3(file) && readFileSync3(file, "utf8").includes("defineClientProduct");
|
|
1399
1501
|
}
|
|
1400
1502
|
|
|
1503
|
+
// src/purchase-rules.ts
|
|
1504
|
+
function codeOnly(source) {
|
|
1505
|
+
let out = "";
|
|
1506
|
+
let i = 0;
|
|
1507
|
+
while (i < source.length) {
|
|
1508
|
+
const c = source[i];
|
|
1509
|
+
const next = source[i + 1];
|
|
1510
|
+
if (c === "/" && next === "/") {
|
|
1511
|
+
while (i < source.length && source[i] !== "\n") {
|
|
1512
|
+
out += " ";
|
|
1513
|
+
i++;
|
|
1514
|
+
}
|
|
1515
|
+
} else if (c === "/" && next === "*") {
|
|
1516
|
+
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) {
|
|
1517
|
+
out += source[i] === "\n" ? "\n" : " ";
|
|
1518
|
+
i++;
|
|
1519
|
+
}
|
|
1520
|
+
out += " ";
|
|
1521
|
+
i += 2;
|
|
1522
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
1523
|
+
out += c;
|
|
1524
|
+
i++;
|
|
1525
|
+
while (i < source.length && source[i] !== c) {
|
|
1526
|
+
if (source[i] === "\\") {
|
|
1527
|
+
out += " ";
|
|
1528
|
+
i++;
|
|
1529
|
+
}
|
|
1530
|
+
out += source[i] === "\n" ? "\n" : " ";
|
|
1531
|
+
i++;
|
|
1532
|
+
}
|
|
1533
|
+
out += c;
|
|
1534
|
+
i++;
|
|
1535
|
+
} else {
|
|
1536
|
+
out += c;
|
|
1537
|
+
i++;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
return out;
|
|
1541
|
+
}
|
|
1542
|
+
var PURCHASE_OPERATION = /^(?:order\.(?:start|checkout|cancel)|subscription\.(?:start|cancel|resume|portal|change|pause|coolOff)|x\.[a-z0-9]+\.(?:buy|orderStart|checkout|subscribe))$/;
|
|
1543
|
+
var BUY_HOOK = /\b(?:useBuy\w*|useCheckout\w*|useOrderStart|useSubscribe|useCancelSubscription|useResumeSubscription|useBillingPortal|useCoolOff)\b/;
|
|
1544
|
+
var OPERATION_STRING = /["'`]((?:order|subscription|x\.[a-z0-9]+)\.[a-zA-Z]+)["'`]/g;
|
|
1545
|
+
function scanPurchases(source) {
|
|
1546
|
+
const problems = [];
|
|
1547
|
+
const code = codeOnly(source).split("\n");
|
|
1548
|
+
source.split("\n").forEach((line, index) => {
|
|
1549
|
+
for (const match of line.matchAll(OPERATION_STRING)) {
|
|
1550
|
+
if (PURCHASE_OPERATION.test(match[1])) {
|
|
1551
|
+
problems.push({ line: index + 1, names: match[1] });
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
const hook = BUY_HOOK.exec(code[index] ?? "");
|
|
1555
|
+
if (hook) problems.push({ line: index + 1, names: hook[0] });
|
|
1556
|
+
});
|
|
1557
|
+
return problems;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// src/app.ts
|
|
1561
|
+
var APP_USAGE = `Usage:
|
|
1562
|
+
cos app check [--dir <repo>]
|
|
1563
|
+
cos app credentials [--check --for ios|android|record]
|
|
1564
|
+
cos app build-info [--env <name>] [--json]
|
|
1565
|
+
cos app record [--env <name>] --platform ios,android --build <n> [--commit <sha>]
|
|
1566
|
+
cos app upload --platform android [--env <name>] --file <app.aab> [--listing] [--draft]`;
|
|
1567
|
+
var DEFAULT_BRAND = {
|
|
1568
|
+
primary: "#18181b",
|
|
1569
|
+
onPrimary: "#fafafa",
|
|
1570
|
+
background: "#ffffff",
|
|
1571
|
+
text: "#18181b"
|
|
1572
|
+
};
|
|
1573
|
+
function brandPath(product) {
|
|
1574
|
+
return product.mobile ? join4(product.mobile.dir, "src", "blocks", "brand.ts") : null;
|
|
1575
|
+
}
|
|
1576
|
+
function onPrimary(primary) {
|
|
1577
|
+
return contrastRatio("#ffffff", primary) >= contrastRatio("#18181b", primary) ? "#ffffff" : "#18181b";
|
|
1578
|
+
}
|
|
1579
|
+
function brandText(product) {
|
|
1580
|
+
const colours = product.mobile?.app?.colours;
|
|
1581
|
+
const brand = colours ? { ...colours, onPrimary: onPrimary(colours.primary) } : DEFAULT_BRAND;
|
|
1582
|
+
return `// Written by cos from product.ts (mobile.app.colours): do not edit. Change product.ts and run
|
|
1583
|
+
// \`pnpm cos client generate\`. The native base theme reads it (native-base/theme.ts).
|
|
1584
|
+
export const brand = {
|
|
1585
|
+
primary: ${JSON.stringify(brand.primary)},
|
|
1586
|
+
onPrimary: ${JSON.stringify(brand.onPrimary)},
|
|
1587
|
+
background: ${JSON.stringify(brand.background)},
|
|
1588
|
+
text: ${JSON.stringify(brand.text)},
|
|
1589
|
+
} as const;
|
|
1590
|
+
`;
|
|
1591
|
+
}
|
|
1592
|
+
function writeBrand(root, product) {
|
|
1593
|
+
const path = brandPath(product);
|
|
1594
|
+
if (!path) return null;
|
|
1595
|
+
const text = brandText(product);
|
|
1596
|
+
const file = join4(root, path);
|
|
1597
|
+
if (existsSync4(file) && readFileSync4(file, "utf8") === text) return path;
|
|
1598
|
+
mkdirSync3(dirname4(file), { recursive: true });
|
|
1599
|
+
writeFileSync4(file, text);
|
|
1600
|
+
return path;
|
|
1601
|
+
}
|
|
1602
|
+
var LISTING_FILES = [
|
|
1603
|
+
{ file: "name.txt", max: 30, what: "the name in the store" },
|
|
1604
|
+
{
|
|
1605
|
+
file: "subtitle.txt",
|
|
1606
|
+
max: 30,
|
|
1607
|
+
what: "the subtitle (the Android store's short description too)"
|
|
1608
|
+
},
|
|
1609
|
+
{ file: "description.txt", max: 4e3, what: "the description" },
|
|
1610
|
+
{ file: "keywords.txt", max: 100, what: "the keywords, comma separated (iPhone store)" },
|
|
1611
|
+
{ file: "release-notes.txt", max: 500, what: "what is new in this version" },
|
|
1612
|
+
{ file: "support-url.txt", url: true, what: "the support page's address" },
|
|
1613
|
+
{ file: "privacy-url.txt", url: true, what: "the privacy policy's address" }
|
|
1614
|
+
];
|
|
1615
|
+
var LOCALE = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
1616
|
+
function listingLocales(root, listing) {
|
|
1617
|
+
const dir = join4(root, listing);
|
|
1618
|
+
if (!existsSync4(dir)) return [];
|
|
1619
|
+
return readdirSync2(dir).filter((name) => LOCALE.test(name) && statSync2(join4(dir, name)).isDirectory()).sort();
|
|
1620
|
+
}
|
|
1621
|
+
function listingText(root, listing, locale, file) {
|
|
1622
|
+
const path = join4(root, listing, locale, file);
|
|
1623
|
+
return existsSync4(path) ? readFileSync4(path, "utf8").trim() : null;
|
|
1624
|
+
}
|
|
1625
|
+
function listingProblems(root, listing) {
|
|
1626
|
+
const problems = [];
|
|
1627
|
+
const notes = [];
|
|
1628
|
+
const locales = listingLocales(root, listing);
|
|
1629
|
+
if (!locales.length) {
|
|
1630
|
+
problems.push(
|
|
1631
|
+
`${listing} has no locale folder (${listing}/en-AU/ with ${LISTING_FILES.map((f) => f.file).join(", ")})`
|
|
1632
|
+
);
|
|
1633
|
+
return { problems, notes };
|
|
1634
|
+
}
|
|
1635
|
+
for (const locale of locales) {
|
|
1636
|
+
for (const field of LISTING_FILES) {
|
|
1637
|
+
const where = `${listing}/${locale}/${field.file}`;
|
|
1638
|
+
const text = listingText(root, listing, locale, field.file);
|
|
1639
|
+
if (!text) {
|
|
1640
|
+
problems.push(`${where} is missing or empty: ${field.what}`);
|
|
1641
|
+
continue;
|
|
1642
|
+
}
|
|
1643
|
+
if ("url" in field) {
|
|
1644
|
+
if (!/^https:\/\/[^\s/]+\.[^\s]+$/.test(text))
|
|
1645
|
+
problems.push(`${where} is not an https:// address`);
|
|
1646
|
+
continue;
|
|
1647
|
+
}
|
|
1648
|
+
const length = [...text].length;
|
|
1649
|
+
if (length > field.max) {
|
|
1650
|
+
problems.push(`${where} is ${length} characters: the stores take at most ${field.max}`);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
const shots = join4(root, listing, locale, "screenshots");
|
|
1654
|
+
if (!existsSync4(shots) || !readdirSync2(shots).some((f) => /\.(png|jpe?g)$/i.test(f))) {
|
|
1655
|
+
notes.push(
|
|
1656
|
+
`${listing}/${locale}/screenshots/ has none: the testing tracks take a build without them, a store review does not`
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
return { problems, notes };
|
|
1661
|
+
}
|
|
1662
|
+
function pngInfo(bytes) {
|
|
1663
|
+
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
1664
|
+
if (bytes.length < 33 || signature.some((b, i) => bytes[i] !== b)) return null;
|
|
1665
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1666
|
+
const width = view.getUint32(16);
|
|
1667
|
+
const height = view.getUint32(20);
|
|
1668
|
+
const colourType = bytes[25];
|
|
1669
|
+
let alpha = colourType === 4 || colourType === 6;
|
|
1670
|
+
for (let at = 8; at + 8 <= bytes.length && !alpha; ) {
|
|
1671
|
+
const length = view.getUint32(at);
|
|
1672
|
+
const type = String.fromCharCode(...bytes.subarray(at + 4, at + 8));
|
|
1673
|
+
if (type === "tRNS") alpha = true;
|
|
1674
|
+
if (type === "IDAT" || type === "IEND") break;
|
|
1675
|
+
at += 12 + length;
|
|
1676
|
+
}
|
|
1677
|
+
return { width, height, alpha };
|
|
1678
|
+
}
|
|
1679
|
+
function imageProblem(root, path, what, rule) {
|
|
1680
|
+
const file = join4(root, path);
|
|
1681
|
+
if (!existsSync4(file)) return `${what} ${path} is not in the repo`;
|
|
1682
|
+
const info = pngInfo(new Uint8Array(readFileSync4(file)));
|
|
1683
|
+
if (!info) return `${what} ${path} is not a PNG`;
|
|
1684
|
+
if (rule.size && (info.width !== rule.size || info.height !== rule.size)) {
|
|
1685
|
+
return `${what} ${path} is ${info.width} by ${info.height}: it must be ${rule.size} by ${rule.size}`;
|
|
1686
|
+
}
|
|
1687
|
+
if (rule.opaque && info.alpha) {
|
|
1688
|
+
return `${what} ${path} can be transparent (an alpha channel): the iPhone store refuses an icon that is not opaque`;
|
|
1689
|
+
}
|
|
1690
|
+
return null;
|
|
1691
|
+
}
|
|
1692
|
+
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".expo", ".wrangler", ".turbo", "build"]);
|
|
1693
|
+
function walk(dir, base, out) {
|
|
1694
|
+
if (!existsSync4(dir)) return;
|
|
1695
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1696
|
+
if (SKIP.has(entry.name)) continue;
|
|
1697
|
+
const path = join4(dir, entry.name);
|
|
1698
|
+
if (entry.isDirectory()) walk(path, base, out);
|
|
1699
|
+
else if (entry.isFile()) out.push(relative3(base, path).split("\\").join("/"));
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
function repoFiles(root) {
|
|
1703
|
+
try {
|
|
1704
|
+
const listed = execFileSync2(
|
|
1705
|
+
"git",
|
|
1706
|
+
["ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
1707
|
+
{ cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
1708
|
+
);
|
|
1709
|
+
return listed.split("\0").filter(Boolean).filter((f) => existsSync4(join4(root, f)) && !f.split("/").some((p) => SKIP.has(p)));
|
|
1710
|
+
} catch {
|
|
1711
|
+
const out = [];
|
|
1712
|
+
walk(root, root, out);
|
|
1713
|
+
return out;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
var KEY_FILE = /(^|\/)AuthKey_[A-Za-z0-9]+\.p8$|\.(p8|p12|pfx|jks|keystore|mobileprovision|provisionprofile)$/i;
|
|
1717
|
+
var PRIVATE_KEY = /-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----/;
|
|
1718
|
+
var SERVICE_ACCOUNT = /"type"\s*:\s*"service_account"[\s\S]*"private_key"|"private_key"[\s\S]*"type"\s*:\s*"service_account"/;
|
|
1719
|
+
function keyFiles(root) {
|
|
1720
|
+
const found = [];
|
|
1721
|
+
for (const file of repoFiles(root)) {
|
|
1722
|
+
if (KEY_FILE.test(file)) {
|
|
1723
|
+
found.push(file);
|
|
1724
|
+
continue;
|
|
1725
|
+
}
|
|
1726
|
+
const path = join4(root, file);
|
|
1727
|
+
if (statSync2(path).size > 1e6) continue;
|
|
1728
|
+
const text = readFileSync4(path, "latin1");
|
|
1729
|
+
if (PRIVATE_KEY.test(text) || SERVICE_ACCOUNT.test(text)) found.push(file);
|
|
1730
|
+
}
|
|
1731
|
+
return found;
|
|
1732
|
+
}
|
|
1733
|
+
function appCode(root, product) {
|
|
1734
|
+
const mobile = product.mobile;
|
|
1735
|
+
const generated = join4(mobile.dir, mobile.clientDir ?? "src/client").split("\\").join("/");
|
|
1736
|
+
const files = [];
|
|
1737
|
+
walk(join4(root, mobile.dir), root, files);
|
|
1738
|
+
return files.filter(
|
|
1739
|
+
(f) => /\.(tsx?|jsx?|mjs|cjs)$/.test(f) && !f.startsWith(`${generated}/`) && !/^(android|ios)\//.test(f.slice(mobile.dir.length + 1))
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
var DELETE_ACCOUNT = /["'`]me\.deleteAccount["'`]/;
|
|
1743
|
+
var DELETE_BLOCK = "native-account-delete";
|
|
1744
|
+
function hasDeleteBlock(root, product) {
|
|
1745
|
+
const mobile = product.mobile;
|
|
1746
|
+
const lockPath = join4(root, "blocks.lock.json");
|
|
1747
|
+
if (!existsSync4(lockPath)) return false;
|
|
1748
|
+
const entry = JSON.parse(readFileSync4(lockPath, "utf8"))[DELETE_BLOCK];
|
|
1749
|
+
if (entry?.app !== mobile.dir) return false;
|
|
1750
|
+
const file = join4(root, mobile.dir, "src", "blocks", DELETE_BLOCK, "delete.tsx");
|
|
1751
|
+
return existsSync4(file) && /\bexport\s+function\s+DeleteAccount\b/.test(readFileSync4(file, "utf8"));
|
|
1752
|
+
}
|
|
1753
|
+
function envFlag(product, flags) {
|
|
1754
|
+
const env = str(flags, "env") ?? str(flags, "environment");
|
|
1755
|
+
if (!environmentNames(product).length && env === LIVE_ENVIRONMENT) return void 0;
|
|
1756
|
+
return env;
|
|
1757
|
+
}
|
|
1758
|
+
function buildFor(product, environment) {
|
|
1759
|
+
try {
|
|
1760
|
+
return appBuild(product, environment);
|
|
1761
|
+
} catch (error) {
|
|
1762
|
+
throw new CliError(error.message);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
async function hostOf(flags, deps, product, build) {
|
|
1766
|
+
const env = deps.env;
|
|
1767
|
+
const token = str(flags, "token") ?? env.CLOUDFLARE_API_TOKEN;
|
|
1768
|
+
if (!token) return null;
|
|
1769
|
+
deps.redactor.add(token);
|
|
1770
|
+
const api = new CloudflareClient({
|
|
1771
|
+
token,
|
|
1772
|
+
...env.COS_CLOUDFLARE_API ? { apiBase: env.COS_CLOUDFLARE_API } : {},
|
|
1773
|
+
...deps.fetch ? { fetch: deps.fetch } : {}
|
|
1774
|
+
});
|
|
1775
|
+
let accountId = str(flags, "account") ?? env.CLOUDFLARE_ACCOUNT_ID;
|
|
1776
|
+
if (!accountId) {
|
|
1777
|
+
const accounts = await api.listAccounts();
|
|
1778
|
+
if (accounts.length !== 1)
|
|
1779
|
+
throw new CliError("Pass --account <id> (or CLOUDFLARE_ACCOUNT_ID).");
|
|
1780
|
+
accountId = accounts[0].id;
|
|
1781
|
+
}
|
|
1782
|
+
const named = environmentNames(product).length ? build.environment : void 0;
|
|
1783
|
+
let located = await locateDeployment(api, accountId, clientNames(product, named).database);
|
|
1784
|
+
if (!located?.state && build.environment === LIVE_ENVIRONMENT) {
|
|
1785
|
+
const known = deps.products ?? { all: products, default: DEFAULT_PRODUCT };
|
|
1786
|
+
const release = known.all[product.platform.release];
|
|
1787
|
+
if (release) located = await locateDeployment(api, accountId, release.names.database);
|
|
1788
|
+
}
|
|
1789
|
+
if (!located?.state) {
|
|
1790
|
+
throw new CliError(
|
|
1791
|
+
`There is no ${build.environment} host in this account to record builds in: deploy it first (cos deploy${named ? ` --env ${named}` : ""}).`
|
|
1792
|
+
);
|
|
1793
|
+
}
|
|
1794
|
+
return { api, accountId, databaseId: located.databaseId };
|
|
1795
|
+
}
|
|
1796
|
+
function generatedApiVersion(root, product) {
|
|
1797
|
+
const mobile = product.mobile;
|
|
1798
|
+
const file = join4(root, mobile.dir, mobile.clientDir ?? "src/client", "customer.ts");
|
|
1799
|
+
const found = existsSync4(file) ? /export const API_VERSION = "([^"]+)"/.exec(readFileSync4(file, "utf8")) : null;
|
|
1800
|
+
if (!found) {
|
|
1801
|
+
throw new CliError(
|
|
1802
|
+
`${relative3(root, file)} has no API_VERSION: run pnpm cos client generate first.`
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
return found[1];
|
|
1806
|
+
}
|
|
1807
|
+
function storeOf(build) {
|
|
1808
|
+
if (!build.store) {
|
|
1809
|
+
throw new CliError(
|
|
1810
|
+
"product.ts gives no mobile.app: the app's name, version, store ids, icon, splash, colours and listing (docs: the start-client-app skill)."
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
return build.store;
|
|
1814
|
+
}
|
|
1815
|
+
async function check(flags, deps) {
|
|
1816
|
+
const { io } = deps;
|
|
1817
|
+
const root = resolve2(str(flags, "dir") ?? process.cwd());
|
|
1818
|
+
const product = await loadClientProduct(root);
|
|
1819
|
+
const mobile = product.mobile;
|
|
1820
|
+
if (!mobile) throw new CliError("product.ts has no mobile app (mobile: { dir }).");
|
|
1821
|
+
const problems = [];
|
|
1822
|
+
const notes = [];
|
|
1823
|
+
if (!mobile.app) {
|
|
1824
|
+
problems.push(
|
|
1825
|
+
"product.ts gives no mobile.app: the app's name, version, store ids, icon, splash, colours and listing"
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
const envs = environmentNames(product);
|
|
1829
|
+
const builds = (envs.length ? envs : [void 0]).map((env) => buildFor(product, env));
|
|
1830
|
+
const listings = /* @__PURE__ */ new Set();
|
|
1831
|
+
const images = /* @__PURE__ */ new Set();
|
|
1832
|
+
for (const build of mobile.app ? builds : []) {
|
|
1833
|
+
const store = build.store;
|
|
1834
|
+
const where = envs.length ? `environment ${build.environment}` : "the app";
|
|
1835
|
+
if (!build.hostUrl) {
|
|
1836
|
+
problems.push(
|
|
1837
|
+
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"
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
for (const [path, what, rule] of [
|
|
1841
|
+
[store.icon, "The icon", { size: 1024, opaque: true }],
|
|
1842
|
+
[store.splash.image, "The splash image", {}]
|
|
1843
|
+
]) {
|
|
1844
|
+
if (images.has(path)) continue;
|
|
1845
|
+
images.add(path);
|
|
1846
|
+
const problem = imageProblem(root, path, what, rule);
|
|
1847
|
+
if (problem) problems.push(problem);
|
|
1848
|
+
}
|
|
1849
|
+
if (!listings.has(store.listing)) {
|
|
1850
|
+
listings.add(store.listing);
|
|
1851
|
+
const listed = listingProblems(root, store.listing);
|
|
1852
|
+
problems.push(...listed.problems);
|
|
1853
|
+
notes.push(...listed.notes);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
if (!existsSync4(join4(root, mobile.dir, "app.config.ts"))) {
|
|
1857
|
+
problems.push(
|
|
1858
|
+
`${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)`
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
const brand = brandPath(product);
|
|
1862
|
+
if (!existsSync4(join4(root, brand)) || readFileSync4(join4(root, brand), "utf8") !== brandText(product)) {
|
|
1863
|
+
problems.push(`${brand} is not product.ts's colours: run pnpm cos client generate`);
|
|
1864
|
+
}
|
|
1865
|
+
const code = appCode(root, product);
|
|
1866
|
+
let deletes = hasDeleteBlock(root, product);
|
|
1867
|
+
for (const file of code) {
|
|
1868
|
+
const text = readFileSync4(join4(root, file), "utf8");
|
|
1869
|
+
for (const p of scanPurchases(text)) {
|
|
1870
|
+
problems.push(
|
|
1871
|
+
`${file}:${p.line} names ${p.names}: nothing is bought in the app (ADR 0490); buying and billing stay on the website`
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
if (DELETE_ACCOUNT.test(text)) deletes = true;
|
|
1875
|
+
}
|
|
1876
|
+
if (!deletes) {
|
|
1877
|
+
problems.push(
|
|
1878
|
+
`${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)`
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
for (const file of keyFiles(root)) {
|
|
1882
|
+
problems.push(
|
|
1883
|
+
`${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`
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
if (mobile.app) {
|
|
1887
|
+
const env = deps.env;
|
|
1888
|
+
if (str(flags, "token") ?? env.CLOUDFLARE_API_TOKEN) {
|
|
1889
|
+
for (const build of builds) {
|
|
1890
|
+
const host = await hostOf(flags, deps, product, build).catch((error) => {
|
|
1891
|
+
notes.push(`${build.environment}: recorded builds not read: ${error.message}`);
|
|
1892
|
+
return null;
|
|
1893
|
+
});
|
|
1894
|
+
if (!host) continue;
|
|
1895
|
+
const recorded = await appBuildsViaApi(
|
|
1896
|
+
host.api,
|
|
1897
|
+
host.accountId,
|
|
1898
|
+
host.databaseId,
|
|
1899
|
+
build.environment
|
|
1900
|
+
);
|
|
1901
|
+
for (const platform of APP_PLATFORMS) {
|
|
1902
|
+
const store = build.store;
|
|
1903
|
+
const problem = recordedIdProblem(recorded ?? [], platform, store.ids[platform]);
|
|
1904
|
+
if (problem) problems.push(`${build.environment}: ${problem}`);
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
} else {
|
|
1908
|
+
notes.push(
|
|
1909
|
+
"Store ids not compared with recorded builds: no Cloudflare token (CLOUDFLARE_API_TOKEN). cos app record compares them too."
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
for (const note of notes) io.out(`note: ${note}`);
|
|
1914
|
+
for (const problem of problems) io.err(`\u2717 ${problem}`);
|
|
1915
|
+
if (problems.length) {
|
|
1916
|
+
io.err(
|
|
1917
|
+
`cos app check: ${problems.length} problem${problems.length > 1 ? "s" : ""}. No store build until each is fixed.`
|
|
1918
|
+
);
|
|
1919
|
+
return 1;
|
|
1920
|
+
}
|
|
1921
|
+
io.out(
|
|
1922
|
+
`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("; ")}).`
|
|
1923
|
+
);
|
|
1924
|
+
return 0;
|
|
1925
|
+
}
|
|
1926
|
+
var UPLOAD_ENVIRONMENT = "app-upload";
|
|
1927
|
+
var RECORD_ENVIRONMENT = "app-record";
|
|
1928
|
+
var prompt = (name, environment) => `gh secret set ${name} --env ${environment} (asks for the value)`;
|
|
1929
|
+
var APP_SECRETS = [
|
|
1930
|
+
{
|
|
1931
|
+
name: "IOS_STORE_API_KEY",
|
|
1932
|
+
job: "ios",
|
|
1933
|
+
what: "the iPhone store's API key (.p8), made in the client's account with a role that may upload",
|
|
1934
|
+
set: `gh secret set IOS_STORE_API_KEY --env ${UPLOAD_ENVIRONMENT} < AuthKey_<key id>.p8`
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
name: "IOS_STORE_API_KEY_ID",
|
|
1938
|
+
job: "ios",
|
|
1939
|
+
what: "that key's id",
|
|
1940
|
+
set: prompt("IOS_STORE_API_KEY_ID", UPLOAD_ENVIRONMENT)
|
|
1941
|
+
},
|
|
1942
|
+
{
|
|
1943
|
+
name: "IOS_STORE_API_ISSUER_ID",
|
|
1944
|
+
job: "ios",
|
|
1945
|
+
what: "the issuer id shown beside the client's API keys",
|
|
1946
|
+
set: prompt("IOS_STORE_API_ISSUER_ID", UPLOAD_ENVIRONMENT)
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
name: "IOS_TEAM_ID",
|
|
1950
|
+
job: "ios",
|
|
1951
|
+
what: "the client's developer team id",
|
|
1952
|
+
set: prompt("IOS_TEAM_ID", UPLOAD_ENVIRONMENT)
|
|
1953
|
+
},
|
|
1954
|
+
{
|
|
1955
|
+
name: "IOS_DISTRIBUTION_CERTIFICATE",
|
|
1956
|
+
job: "ios",
|
|
1957
|
+
what: "the distribution certificate and its private key, exported as .p12, in base64",
|
|
1958
|
+
set: `base64 < distribution.p12 | gh secret set IOS_DISTRIBUTION_CERTIFICATE --env ${UPLOAD_ENVIRONMENT}`
|
|
1959
|
+
},
|
|
1960
|
+
{
|
|
1961
|
+
name: "IOS_DISTRIBUTION_CERTIFICATE_PASSWORD",
|
|
1962
|
+
job: "ios",
|
|
1963
|
+
what: "the .p12's password",
|
|
1964
|
+
set: prompt("IOS_DISTRIBUTION_CERTIFICATE_PASSWORD", UPLOAD_ENVIRONMENT)
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
name: "ANDROID_UPLOAD_KEYSTORE",
|
|
1968
|
+
job: "android",
|
|
1969
|
+
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",
|
|
1970
|
+
set: `base64 < upload.jks | gh secret set ANDROID_UPLOAD_KEYSTORE --env ${UPLOAD_ENVIRONMENT}`
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
name: "ANDROID_UPLOAD_KEYSTORE_PASSWORD",
|
|
1974
|
+
job: "android",
|
|
1975
|
+
what: "the keystore's password (the key's too)",
|
|
1976
|
+
set: prompt("ANDROID_UPLOAD_KEYSTORE_PASSWORD", UPLOAD_ENVIRONMENT)
|
|
1977
|
+
},
|
|
1978
|
+
{
|
|
1979
|
+
name: "ANDROID_STORE_SERVICE_ACCOUNT",
|
|
1980
|
+
job: "android",
|
|
1981
|
+
what: "the Android store's upload account key (JSON), invited to the client's account with the release role for testing tracks",
|
|
1982
|
+
set: `gh secret set ANDROID_STORE_SERVICE_ACCOUNT --env ${UPLOAD_ENVIRONMENT} < service-account.json`
|
|
1983
|
+
},
|
|
1984
|
+
{
|
|
1985
|
+
name: "CLOUDFLARE_API_TOKEN",
|
|
1986
|
+
job: "record",
|
|
1987
|
+
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",
|
|
1988
|
+
set: prompt("CLOUDFLARE_API_TOKEN", RECORD_ENVIRONMENT)
|
|
1989
|
+
},
|
|
1990
|
+
{
|
|
1991
|
+
name: "CLOUDFLARE_ACCOUNT_ID",
|
|
1992
|
+
job: "record",
|
|
1993
|
+
what: "the Cloudflare account the host is in",
|
|
1994
|
+
set: prompt("CLOUDFLARE_ACCOUNT_ID", RECORD_ENVIRONMENT)
|
|
1995
|
+
}
|
|
1996
|
+
];
|
|
1997
|
+
var JOBS = ["ios", "android", "record"];
|
|
1998
|
+
async function credentials(flags, deps) {
|
|
1999
|
+
const { io } = deps;
|
|
2000
|
+
const job = str(flags, "for");
|
|
2001
|
+
if (job && !JOBS.includes(job)) {
|
|
2002
|
+
throw new CliError(`--for is one of ${JOBS.join(", ")}.`);
|
|
2003
|
+
}
|
|
2004
|
+
const wanted = APP_SECRETS.filter((s) => !job || s.job === job);
|
|
2005
|
+
if (flags.check) {
|
|
2006
|
+
const env = deps.env;
|
|
2007
|
+
const missing = wanted.filter((s) => !env[s.name]?.trim());
|
|
2008
|
+
if (!missing.length) {
|
|
2009
|
+
io.out(`Every secret ${job ? `the ${job} job needs` : "the workflow needs"} is set.`);
|
|
2010
|
+
return 0;
|
|
2011
|
+
}
|
|
2012
|
+
io.err(
|
|
2013
|
+
`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):`
|
|
2014
|
+
);
|
|
2015
|
+
for (const s of missing) io.err(` ${s.name}: ${s.what}
|
|
2016
|
+
${s.set}`);
|
|
2017
|
+
return 1;
|
|
2018
|
+
}
|
|
2019
|
+
io.out(
|
|
2020
|
+
`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.`
|
|
2021
|
+
);
|
|
2022
|
+
for (const j of JOBS) {
|
|
2023
|
+
const list = wanted.filter((s) => s.job === j);
|
|
2024
|
+
if (!list.length) continue;
|
|
2025
|
+
io.out(
|
|
2026
|
+
`
|
|
2027
|
+
${j === "record" ? "build numbers and records" : `${j} build and upload`} (${j === "record" ? RECORD_ENVIRONMENT : UPLOAD_ENVIRONMENT}):`
|
|
2028
|
+
);
|
|
2029
|
+
for (const s of list) io.out(` ${s.name}: ${s.what}
|
|
2030
|
+
${s.set}`);
|
|
2031
|
+
}
|
|
2032
|
+
return 0;
|
|
2033
|
+
}
|
|
2034
|
+
async function buildInfo(flags, deps) {
|
|
2035
|
+
const root = resolve2(str(flags, "dir") ?? process.cwd());
|
|
2036
|
+
const product = await loadClientProduct(root);
|
|
2037
|
+
if (!product.mobile) throw new CliError("product.ts has no mobile app (mobile: { dir }).");
|
|
2038
|
+
const build = buildFor(product, envFlag(product, flags));
|
|
2039
|
+
const store = storeOf(build);
|
|
2040
|
+
const apiVersion = generatedApiVersion(root, product);
|
|
2041
|
+
const host = await hostOf(flags, deps, product, build);
|
|
2042
|
+
if (!host) {
|
|
2043
|
+
throw new CliError(
|
|
2044
|
+
"The next build number is read from the host's recorded builds: give the deploy credential (CLOUDFLARE_API_TOKEN)."
|
|
2045
|
+
);
|
|
2046
|
+
}
|
|
2047
|
+
const recorded = await appBuildsViaApi(
|
|
2048
|
+
host.api,
|
|
2049
|
+
host.accountId,
|
|
2050
|
+
host.databaseId,
|
|
2051
|
+
build.environment
|
|
2052
|
+
);
|
|
2053
|
+
const info = {
|
|
2054
|
+
environment: build.environment,
|
|
2055
|
+
version: build.version,
|
|
2056
|
+
build: nextBuildNumber(recorded ?? []),
|
|
2057
|
+
apiVersion,
|
|
2058
|
+
ids: store.ids
|
|
2059
|
+
};
|
|
2060
|
+
if (flags.json) deps.io.out(JSON.stringify(info));
|
|
2061
|
+
else {
|
|
2062
|
+
deps.io.out(
|
|
2063
|
+
`${build.name} (${info.environment}) ${info.version}, build ${info.build}, API ${info.apiVersion}: ${info.ids.ios} / ${info.ids.android}`
|
|
2064
|
+
);
|
|
2065
|
+
}
|
|
2066
|
+
return 0;
|
|
2067
|
+
}
|
|
2068
|
+
function platformsOf(flags) {
|
|
2069
|
+
const list = (str(flags, "platform") ?? "").split(",").map((p) => p.trim()).filter(Boolean);
|
|
2070
|
+
const bad = list.filter((p) => !APP_PLATFORMS.includes(p));
|
|
2071
|
+
if (!list.length || bad.length) {
|
|
2072
|
+
throw new CliError(
|
|
2073
|
+
`--platform is ios, android or both (ios,android)${bad.length ? `, not ${bad.join(", ")}` : ""}.`
|
|
2074
|
+
);
|
|
2075
|
+
}
|
|
2076
|
+
return [...new Set(list)];
|
|
2077
|
+
}
|
|
2078
|
+
function commitOf(flags, deps, root) {
|
|
2079
|
+
const given = str(flags, "commit") ?? deps.env.GITHUB_SHA;
|
|
2080
|
+
if (given) {
|
|
2081
|
+
if (!/^[0-9a-f]{7,40}$/.test(given)) throw new CliError("--commit is a commit's sha.");
|
|
2082
|
+
return given;
|
|
2083
|
+
}
|
|
2084
|
+
try {
|
|
2085
|
+
return execFileSync2("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" }).trim();
|
|
2086
|
+
} catch {
|
|
2087
|
+
return null;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
async function record(flags, deps) {
|
|
2091
|
+
const root = resolve2(str(flags, "dir") ?? process.cwd());
|
|
2092
|
+
const product = await loadClientProduct(root);
|
|
2093
|
+
if (!product.mobile) throw new CliError("product.ts has no mobile app (mobile: { dir }).");
|
|
2094
|
+
const build = buildFor(product, envFlag(product, flags));
|
|
2095
|
+
const store = storeOf(build);
|
|
2096
|
+
const platforms = platformsOf(flags);
|
|
2097
|
+
const number = Number(str(flags, "build"));
|
|
2098
|
+
if (!Number.isInteger(number) || number < 1) {
|
|
2099
|
+
throw new CliError("--build is the build number the run used (cos app build-info).");
|
|
2100
|
+
}
|
|
2101
|
+
const apiVersion = generatedApiVersion(root, product);
|
|
2102
|
+
const host = await hostOf(flags, deps, product, build);
|
|
2103
|
+
if (!host) {
|
|
2104
|
+
throw new CliError(
|
|
2105
|
+
"cos app record writes the host's database: give the deploy credential (CLOUDFLARE_API_TOKEN)."
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
const commit = commitOf(flags, deps, root);
|
|
2109
|
+
const uploadedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2110
|
+
for (const platform of platforms) {
|
|
2111
|
+
const row = {
|
|
2112
|
+
environment: build.environment,
|
|
2113
|
+
platform,
|
|
2114
|
+
app_version: build.version,
|
|
2115
|
+
build_number: number,
|
|
2116
|
+
api_version: apiVersion,
|
|
2117
|
+
app_id: store.ids[platform],
|
|
2118
|
+
commit_sha: commit,
|
|
2119
|
+
uploaded_at: uploadedAt,
|
|
2120
|
+
supported: 1
|
|
2121
|
+
};
|
|
2122
|
+
let result;
|
|
2123
|
+
try {
|
|
2124
|
+
result = await recordAppBuildViaApi(host.api, host.accountId, host.databaseId, row);
|
|
2125
|
+
} catch (error) {
|
|
2126
|
+
if (error instanceof AppBuildRefused) throw new CliError(`Not recorded: ${error.message}.`);
|
|
2127
|
+
throw error;
|
|
2128
|
+
}
|
|
2129
|
+
deps.io.out(
|
|
2130
|
+
`${result === "recorded" ? "Recorded" : "Already recorded"}: ${platform} build ${number} of ${build.name} ${build.version} (${row.app_id}, API ${apiVersion}) for ${build.environment}.`
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
return 0;
|
|
2134
|
+
}
|
|
2135
|
+
async function runApp(argv, deps) {
|
|
2136
|
+
const commands = {
|
|
2137
|
+
check,
|
|
2138
|
+
credentials,
|
|
2139
|
+
"build-info": buildInfo,
|
|
2140
|
+
record,
|
|
2141
|
+
upload: async (flags2, d) => (await import("./app-upload-YJVEKZC6.js")).upload(flags2, d)
|
|
2142
|
+
};
|
|
2143
|
+
const command = commands[argv[0] ?? ""];
|
|
2144
|
+
if (!command) {
|
|
2145
|
+
deps.io.err(APP_USAGE);
|
|
2146
|
+
return 2;
|
|
2147
|
+
}
|
|
2148
|
+
let flags;
|
|
2149
|
+
try {
|
|
2150
|
+
flags = parseArgs([argv[0], ...argv.slice(1)]).flags;
|
|
2151
|
+
} catch (error) {
|
|
2152
|
+
deps.io.err(error.message);
|
|
2153
|
+
return 2;
|
|
2154
|
+
}
|
|
2155
|
+
try {
|
|
2156
|
+
return await command(flags, deps);
|
|
2157
|
+
} catch (error) {
|
|
2158
|
+
deps.io.err(`Error: ${error.message}`);
|
|
2159
|
+
return 1;
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
|
|
1401
2163
|
export {
|
|
2164
|
+
APP_USAGE,
|
|
2165
|
+
brandPath,
|
|
2166
|
+
brandText,
|
|
2167
|
+
writeBrand,
|
|
2168
|
+
LISTING_FILES,
|
|
2169
|
+
listingLocales,
|
|
2170
|
+
listingText,
|
|
2171
|
+
pngInfo,
|
|
2172
|
+
keyFiles,
|
|
2173
|
+
envFlag,
|
|
2174
|
+
buildFor,
|
|
2175
|
+
generatedApiVersion,
|
|
2176
|
+
UPLOAD_ENVIRONMENT,
|
|
2177
|
+
RECORD_ENVIRONMENT,
|
|
2178
|
+
APP_SECRETS,
|
|
2179
|
+
runApp,
|
|
1402
2180
|
lineDiff,
|
|
1403
2181
|
hostRoutes,
|
|
1404
2182
|
edgeRuleStep,
|
|
@@ -1420,6 +2198,7 @@ export {
|
|
|
1420
2198
|
deploy,
|
|
1421
2199
|
upgradeRepo,
|
|
1422
2200
|
kitPacks,
|
|
2201
|
+
requiredPacks,
|
|
1423
2202
|
regenerate,
|
|
1424
2203
|
isClientRepo
|
|
1425
2204
|
};
|