@jtl-software/create-cloud-app 0.9.0 → 0.10.0
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/README.md +15 -1
- package/dist/index.js +261 -74
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -8,11 +8,12 @@ Node.js **24** (current LTS) or newer. The scaffolded project sets the same floo
|
|
|
8
8
|
|
|
9
9
|
## Commands
|
|
10
10
|
|
|
11
|
-
The CLI has
|
|
11
|
+
The CLI has these entry points:
|
|
12
12
|
|
|
13
13
|
- The default invocation (no arguments) scaffolds a new project.
|
|
14
14
|
- `register` registers or updates the app's identity (`app.json`) against the JTL Cloud — do this when you start building.
|
|
15
15
|
- `listing` pushes the app's store listing (`listing.json`) — do this once you're done building and ready to publish.
|
|
16
|
+
- `login` signs in, or switches to another account. `logout` signs out.
|
|
16
17
|
|
|
17
18
|
Registration and listing are two independent resources on two independent files. `register` must happen first — `listing` pushes against the app that `register` created and will fail with a clear error if it hasn't run yet.
|
|
18
19
|
|
|
@@ -141,6 +142,19 @@ Flags: `--api-host`, `--auth-host`, `--hub-host`, `--partner-host`, `--client-id
|
|
|
141
142
|
- `--distribution-type <PUBLIC|PRIVATE>`
|
|
142
143
|
- `--default-locale <locale>`, e.g. `de-DE`
|
|
143
144
|
|
|
145
|
+
### `login` and `logout`
|
|
146
|
+
|
|
147
|
+
```shell
|
|
148
|
+
npx @jtl-software/create-cloud-app login
|
|
149
|
+
npx @jtl-software/create-cloud-app login --auth-host https://id.dev.jtl-cloud.com
|
|
150
|
+
npx @jtl-software/create-cloud-app logout
|
|
151
|
+
npx @jtl-software/create-cloud-app logout --all
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`login` opens the browser and caches the login in `~/.config/jtl-cli/tokens.json`, one per auth host. It always asks which account to use, so it also switches accounts. `register`, `listing` and the [Terraform provider for JTL App Store apps](https://github.com/jtl-software/terraform-provider-jtl) reuse the cached login.
|
|
155
|
+
|
|
156
|
+
`logout` revokes the login at the IdP and removes it from the cache. Without `--all` it signs out of one auth host (`--auth-host`, default `https://id.jtl-cloud.com`).
|
|
157
|
+
|
|
144
158
|
## CI usage: keep your deployed app.json and listing.json in sync with the repo
|
|
145
159
|
|
|
146
160
|
A common setup is to commit `app.json` and `listing.json` to source control and have CI push them to the cloud whenever they change, so the deployed app always matches what's on `main`.
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import * as
|
|
4
|
+
import * as p5 from "@clack/prompts";
|
|
5
5
|
import fs7 from "fs";
|
|
6
6
|
import path7 from "path";
|
|
7
|
-
import
|
|
7
|
+
import pc5 from "picocolors";
|
|
8
8
|
|
|
9
9
|
// src/platform-client.ts
|
|
10
10
|
import * as p from "@clack/prompts";
|
|
@@ -93,6 +93,16 @@ function getCachedToken(authBaseUrl, clientId, scope) {
|
|
|
93
93
|
}
|
|
94
94
|
return entry;
|
|
95
95
|
}
|
|
96
|
+
function removeCachedToken(authBaseUrl) {
|
|
97
|
+
const cache = readTokenCache();
|
|
98
|
+
const key = cacheKey(authBaseUrl);
|
|
99
|
+
const entry = cache[key] ?? null;
|
|
100
|
+
if (entry) {
|
|
101
|
+
delete cache[key];
|
|
102
|
+
writeTokenCache(cache);
|
|
103
|
+
}
|
|
104
|
+
return entry;
|
|
105
|
+
}
|
|
96
106
|
function saveCachedToken(authBaseUrl, token) {
|
|
97
107
|
const cache = readTokenCache();
|
|
98
108
|
cache[cacheKey(authBaseUrl)] = token;
|
|
@@ -269,7 +279,8 @@ async function discoverOidc(authBaseUrl) {
|
|
|
269
279
|
}
|
|
270
280
|
return {
|
|
271
281
|
authorization_endpoint: doc.authorization_endpoint,
|
|
272
|
-
token_endpoint: doc.token_endpoint
|
|
282
|
+
token_endpoint: doc.token_endpoint,
|
|
283
|
+
revocation_endpoint: doc.revocation_endpoint
|
|
273
284
|
};
|
|
274
285
|
})();
|
|
275
286
|
oidcMetadataCache.set(authBaseUrl, pending);
|
|
@@ -325,16 +336,16 @@ async function refreshAccessToken(authBaseUrl, clientId, refreshToken) {
|
|
|
325
336
|
);
|
|
326
337
|
}
|
|
327
338
|
async function acquireAccessToken(opts) {
|
|
328
|
-
const { auth, clientId, scope, reauth, spinner:
|
|
339
|
+
const { auth, clientId, scope, reauth, spinner: spinner5, captureOptions } = opts;
|
|
329
340
|
const now = Math.floor(Date.now() / 1e3);
|
|
330
341
|
const cached = reauth ? null : getCachedToken(auth, clientId, scope);
|
|
331
342
|
if (cached && cached.expires_at > now + TOKEN_EXPIRY_MARGIN_S) {
|
|
332
|
-
|
|
333
|
-
|
|
343
|
+
spinner5?.start("Using cached session");
|
|
344
|
+
spinner5?.stop("Signed in (cached)");
|
|
334
345
|
return cached.access_token;
|
|
335
346
|
}
|
|
336
347
|
if (cached?.refresh_token) {
|
|
337
|
-
|
|
348
|
+
spinner5?.start("Refreshing session");
|
|
338
349
|
try {
|
|
339
350
|
const refreshed = await refreshAccessToken(
|
|
340
351
|
auth,
|
|
@@ -345,10 +356,10 @@ async function acquireAccessToken(opts) {
|
|
|
345
356
|
auth,
|
|
346
357
|
makeCachedToken(clientId, refreshed, cached.refresh_token, scope)
|
|
347
358
|
);
|
|
348
|
-
|
|
359
|
+
spinner5?.stop("Signed in (refreshed)");
|
|
349
360
|
return refreshed.access_token;
|
|
350
361
|
} catch {
|
|
351
|
-
|
|
362
|
+
spinner5?.stop("Refresh failed, opening browser");
|
|
352
363
|
}
|
|
353
364
|
}
|
|
354
365
|
const pkce = generatePkce();
|
|
@@ -365,7 +376,7 @@ async function acquireAccessToken(opts) {
|
|
|
365
376
|
if (reauth) {
|
|
366
377
|
authorizeUrl.searchParams.set("prompt", "select_account");
|
|
367
378
|
}
|
|
368
|
-
|
|
379
|
+
spinner5?.start("Waiting for browser login");
|
|
369
380
|
try {
|
|
370
381
|
const { code, verifier } = await captureAuthCode(
|
|
371
382
|
authorizeUrl,
|
|
@@ -373,16 +384,26 @@ async function acquireAccessToken(opts) {
|
|
|
373
384
|
pkce.verifier,
|
|
374
385
|
captureOptions
|
|
375
386
|
);
|
|
376
|
-
|
|
387
|
+
spinner5?.message("Exchanging authorization code");
|
|
377
388
|
const tokens = await exchangeCodeForToken(auth, clientId, code, verifier);
|
|
378
389
|
saveCachedToken(auth, makeCachedToken(clientId, tokens, void 0, scope));
|
|
379
|
-
|
|
390
|
+
spinner5?.stop("Signed in");
|
|
380
391
|
return tokens.access_token;
|
|
381
392
|
} catch (err) {
|
|
382
|
-
|
|
393
|
+
spinner5?.stop("Login failed");
|
|
383
394
|
throw err;
|
|
384
395
|
}
|
|
385
396
|
}
|
|
397
|
+
var ApiError = class extends Error {
|
|
398
|
+
constructor(message, status, code) {
|
|
399
|
+
super(message);
|
|
400
|
+
this.status = status;
|
|
401
|
+
this.code = code;
|
|
402
|
+
this.name = "ApiError";
|
|
403
|
+
}
|
|
404
|
+
status;
|
|
405
|
+
code;
|
|
406
|
+
};
|
|
386
407
|
async function apiCall(url, init) {
|
|
387
408
|
const res = await fetch(url, init);
|
|
388
409
|
const text3 = await res.text();
|
|
@@ -394,8 +415,11 @@ async function apiCall(url, init) {
|
|
|
394
415
|
}
|
|
395
416
|
if (!res.ok) {
|
|
396
417
|
const detail = typeof body === "string" ? body : JSON.stringify(body);
|
|
397
|
-
|
|
398
|
-
|
|
418
|
+
const code = typeof body === "object" && body !== null && "code" in body ? String(body.code) : void 0;
|
|
419
|
+
throw new ApiError(
|
|
420
|
+
`${init.method ?? "GET"} ${url} returned ${res.status}: ${detail}`,
|
|
421
|
+
res.status,
|
|
422
|
+
code
|
|
399
423
|
);
|
|
400
424
|
}
|
|
401
425
|
return body;
|
|
@@ -591,6 +615,9 @@ function buildHubAppOverviewUrl(hubHost, tenantSlug) {
|
|
|
591
615
|
function buildPartnerPortalPublishUrl(partnerHost, tenantSlug, publisherId) {
|
|
592
616
|
return `${partnerHost}/${tenantSlug}/${publisherId}/apps/publish`;
|
|
593
617
|
}
|
|
618
|
+
function buildPartnerPortalOnboardingUrl(partnerHost, tenantSlug) {
|
|
619
|
+
return `${partnerHost}/${tenantSlug}/onboarding`;
|
|
620
|
+
}
|
|
594
621
|
function terminalLink(url, text3 = url) {
|
|
595
622
|
const OSC = "\x1B]";
|
|
596
623
|
const ST = "\x1B\\";
|
|
@@ -736,6 +763,48 @@ var COMMANDS = {
|
|
|
736
763
|
examples: [
|
|
737
764
|
`${BIN} listing --yes --tenant my-tenant --distribution-type PRIVATE`
|
|
738
765
|
]
|
|
766
|
+
},
|
|
767
|
+
login: {
|
|
768
|
+
name: "login",
|
|
769
|
+
usage: `${BIN} login [options]`,
|
|
770
|
+
summary: "Sign in, or switch to another account.",
|
|
771
|
+
description: "Opens the browser to sign in and caches the login in ~/.config/jtl-cli/tokens.json, one per auth host. register, listing and the Terraform provider for JTL App Store apps reuse it. Always asks which account to use, so it also switches accounts.",
|
|
772
|
+
flags: [
|
|
773
|
+
{
|
|
774
|
+
flag: "--auth-host <url>",
|
|
775
|
+
description: `OAuth host. Default ${DEFAULT_AUTH_HOST}.`
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
flag: "--client-id <id>",
|
|
779
|
+
description: "OAuth client id. Only needed for an unknown --auth-host."
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
flag: "--scope <scope>",
|
|
783
|
+
description: "OAuth scope. Default depends on --auth-host."
|
|
784
|
+
}
|
|
785
|
+
],
|
|
786
|
+
examples: [
|
|
787
|
+
`${BIN} login`,
|
|
788
|
+
`${BIN} login --auth-host https://id.dev.jtl-cloud.com`
|
|
789
|
+
]
|
|
790
|
+
},
|
|
791
|
+
logout: {
|
|
792
|
+
name: "logout",
|
|
793
|
+
usage: `${BIN} logout [options]`,
|
|
794
|
+
summary: "Sign out and remove the cached login.",
|
|
795
|
+
description: "Revokes the login at the IdP and removes it from ~/.config/jtl-cli/tokens.json, for one auth host or, with --all, for every host.",
|
|
796
|
+
flags: [
|
|
797
|
+
{
|
|
798
|
+
flag: "--auth-host <url>",
|
|
799
|
+
description: `OAuth host. Default ${DEFAULT_AUTH_HOST}.`
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
flag: "--client-id <id>",
|
|
803
|
+
description: "OAuth client id. Only needed for an unknown --auth-host."
|
|
804
|
+
},
|
|
805
|
+
{ flag: "--all", description: "Sign out of every auth host." }
|
|
806
|
+
],
|
|
807
|
+
examples: [`${BIN} logout`, `${BIN} logout --all`]
|
|
739
808
|
}
|
|
740
809
|
};
|
|
741
810
|
function flagTable(flags) {
|
|
@@ -761,7 +830,7 @@ function renderOverview(version) {
|
|
|
761
830
|
...flagTable(GLOBAL_FLAGS),
|
|
762
831
|
"",
|
|
763
832
|
`Run \`${BIN} <command> --help\` for the command's flags.`,
|
|
764
|
-
"Every prompt has a matching flag. register and listing
|
|
833
|
+
"Every prompt has a matching flag. register and listing need a browser sign-in once; run login to sign in or switch accounts.",
|
|
765
834
|
""
|
|
766
835
|
].join("\n");
|
|
767
836
|
}
|
|
@@ -1219,6 +1288,9 @@ async function updateAppManifest(apiBaseUrl, jwt, tenantId, appId, manifest, app
|
|
|
1219
1288
|
}
|
|
1220
1289
|
);
|
|
1221
1290
|
}
|
|
1291
|
+
function isMissingPublisherError(err) {
|
|
1292
|
+
return err instanceof ApiError && err.status === 404 && (err.code === "PublisherNotFound" || err.code === "EntityNotFound");
|
|
1293
|
+
}
|
|
1222
1294
|
async function createDraftApp(apiBaseUrl, jwt, tenantId, manifest, appServicePath = "app-service") {
|
|
1223
1295
|
const created = await apiCall(
|
|
1224
1296
|
`${apiBaseUrl}/${appServicePath}/store/apps`,
|
|
@@ -1399,7 +1471,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1399
1471
|
].filter(Boolean).join("\n"),
|
|
1400
1472
|
"Target"
|
|
1401
1473
|
);
|
|
1402
|
-
const
|
|
1474
|
+
const spinner5 = p2.spinner();
|
|
1403
1475
|
let jwt;
|
|
1404
1476
|
try {
|
|
1405
1477
|
jwt = await acquireAccessToken({
|
|
@@ -1407,7 +1479,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1407
1479
|
clientId: opts.clientId,
|
|
1408
1480
|
scope: opts.scope,
|
|
1409
1481
|
reauth: opts.reauth,
|
|
1410
|
-
spinner:
|
|
1482
|
+
spinner: spinner5,
|
|
1411
1483
|
captureOptions: runOpts.captureOptions
|
|
1412
1484
|
});
|
|
1413
1485
|
} catch (err) {
|
|
@@ -1437,15 +1509,15 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1437
1509
|
for (; ; ) {
|
|
1438
1510
|
const identityJwt = jwt;
|
|
1439
1511
|
const apiJwt = jwt;
|
|
1440
|
-
|
|
1512
|
+
spinner5.start("Fetching tenants");
|
|
1441
1513
|
let tenants;
|
|
1442
1514
|
try {
|
|
1443
1515
|
tenants = await fetchTenants(opts.api, identityJwt);
|
|
1444
|
-
|
|
1516
|
+
spinner5.stop(
|
|
1445
1517
|
`Found ${tenants.length} tenant${tenants.length === 1 ? "" : "s"}`
|
|
1446
1518
|
);
|
|
1447
1519
|
} catch (err) {
|
|
1448
|
-
|
|
1520
|
+
spinner5.stop("Failed to fetch tenants");
|
|
1449
1521
|
bail(err.message);
|
|
1450
1522
|
}
|
|
1451
1523
|
let tenant;
|
|
@@ -1459,7 +1531,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1459
1531
|
} else {
|
|
1460
1532
|
tenant = await selectTenant(tenants, opts);
|
|
1461
1533
|
}
|
|
1462
|
-
|
|
1534
|
+
spinner5.start("Looking for apps matching this manifest");
|
|
1463
1535
|
let matches;
|
|
1464
1536
|
try {
|
|
1465
1537
|
const apps = await listTenantApps(
|
|
@@ -1469,11 +1541,11 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1469
1541
|
opts.appServicePath
|
|
1470
1542
|
);
|
|
1471
1543
|
matches = apps.filter((a) => a.technicalName === summary.technicalName);
|
|
1472
|
-
|
|
1544
|
+
spinner5.stop(
|
|
1473
1545
|
`Found ${matches.length} app${matches.length === 1 ? "" : "s"} with technical name ${pc2.cyan(summary.technicalName)}`
|
|
1474
1546
|
);
|
|
1475
1547
|
} catch (err) {
|
|
1476
|
-
|
|
1548
|
+
spinner5.stop("Failed to look up tenant apps");
|
|
1477
1549
|
bail(err.message);
|
|
1478
1550
|
}
|
|
1479
1551
|
const existing = await selectExistingOrNew(matches, opts);
|
|
@@ -1499,7 +1571,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1499
1571
|
scope: opts.scope,
|
|
1500
1572
|
reauth: true,
|
|
1501
1573
|
// forces prompt=select_account so the user re-picks the organization
|
|
1502
|
-
spinner:
|
|
1574
|
+
spinner: spinner5,
|
|
1503
1575
|
captureOptions: runOpts.captureOptions
|
|
1504
1576
|
});
|
|
1505
1577
|
} catch (err) {
|
|
@@ -1508,7 +1580,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1508
1580
|
continue;
|
|
1509
1581
|
}
|
|
1510
1582
|
if (existing) {
|
|
1511
|
-
|
|
1583
|
+
spinner5.start("Updating manifest");
|
|
1512
1584
|
try {
|
|
1513
1585
|
await updateAppManifest(
|
|
1514
1586
|
opts.api,
|
|
@@ -1518,13 +1590,13 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1518
1590
|
manifest,
|
|
1519
1591
|
opts.appServicePath
|
|
1520
1592
|
);
|
|
1521
|
-
|
|
1593
|
+
spinner5.stop("Manifest updated");
|
|
1522
1594
|
} catch (err) {
|
|
1523
|
-
|
|
1595
|
+
spinner5.stop("Failed to update manifest");
|
|
1524
1596
|
bail(err.message);
|
|
1525
1597
|
}
|
|
1526
1598
|
if (existing.provisioningStatus === "DRAFT") {
|
|
1527
|
-
|
|
1599
|
+
spinner5.start("Provisioning app");
|
|
1528
1600
|
let provisioned2;
|
|
1529
1601
|
try {
|
|
1530
1602
|
provisioned2 = await provisionApp(
|
|
@@ -1534,9 +1606,9 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1534
1606
|
existing.id,
|
|
1535
1607
|
opts.appServicePath
|
|
1536
1608
|
);
|
|
1537
|
-
|
|
1609
|
+
spinner5.stop("Provisioned");
|
|
1538
1610
|
} catch (err) {
|
|
1539
|
-
|
|
1611
|
+
spinner5.stop("Failed to provision app");
|
|
1540
1612
|
bail(err.message);
|
|
1541
1613
|
}
|
|
1542
1614
|
await applyProvisionResult(
|
|
@@ -1605,7 +1677,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1605
1677
|
}
|
|
1606
1678
|
return { ...registerTelemetry, is_new_app: false };
|
|
1607
1679
|
}
|
|
1608
|
-
|
|
1680
|
+
spinner5.start("Creating draft app");
|
|
1609
1681
|
let appId;
|
|
1610
1682
|
try {
|
|
1611
1683
|
appId = await createDraftApp(
|
|
@@ -1615,12 +1687,19 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1615
1687
|
manifest,
|
|
1616
1688
|
opts.appServicePath
|
|
1617
1689
|
);
|
|
1618
|
-
|
|
1690
|
+
spinner5.stop(`Created app ${pc2.cyan(appId)}`);
|
|
1619
1691
|
} catch (err) {
|
|
1620
|
-
|
|
1692
|
+
spinner5.stop("Failed to create app");
|
|
1693
|
+
if (isMissingPublisherError(err)) {
|
|
1694
|
+
const url = buildPartnerPortalOnboardingUrl(opts.partner, tenant.slug);
|
|
1695
|
+
p2.note(pc2.cyan(terminalLink(url)), "Register as publisher");
|
|
1696
|
+
bail(
|
|
1697
|
+
`Organization "${tenant.name}" is not registered as a publisher yet. Complete the Partner Portal onboarding for it, then run this command again.`
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1621
1700
|
bail(err.message);
|
|
1622
1701
|
}
|
|
1623
|
-
|
|
1702
|
+
spinner5.start("Provisioning app");
|
|
1624
1703
|
let provisioned;
|
|
1625
1704
|
try {
|
|
1626
1705
|
provisioned = await provisionApp(
|
|
@@ -1630,9 +1709,9 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1630
1709
|
appId,
|
|
1631
1710
|
opts.appServicePath
|
|
1632
1711
|
);
|
|
1633
|
-
|
|
1712
|
+
spinner5.stop("Provisioned");
|
|
1634
1713
|
} catch (err) {
|
|
1635
|
-
|
|
1714
|
+
spinner5.stop("Failed to provision app");
|
|
1636
1715
|
bail(err.message);
|
|
1637
1716
|
}
|
|
1638
1717
|
await applyProvisionResult(
|
|
@@ -1827,7 +1906,7 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1827
1906
|
].join("\n"),
|
|
1828
1907
|
"Target"
|
|
1829
1908
|
);
|
|
1830
|
-
const
|
|
1909
|
+
const spinner5 = p3.spinner();
|
|
1831
1910
|
let jwt;
|
|
1832
1911
|
try {
|
|
1833
1912
|
jwt = await acquireAccessToken({
|
|
@@ -1835,22 +1914,22 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1835
1914
|
clientId: opts.clientId,
|
|
1836
1915
|
scope: opts.scope,
|
|
1837
1916
|
reauth: opts.reauth,
|
|
1838
|
-
spinner:
|
|
1917
|
+
spinner: spinner5,
|
|
1839
1918
|
captureOptions: runOpts.captureOptions
|
|
1840
1919
|
});
|
|
1841
1920
|
} catch (err) {
|
|
1842
1921
|
bail(err.message);
|
|
1843
1922
|
}
|
|
1844
1923
|
const identityJwt = jwt;
|
|
1845
|
-
|
|
1924
|
+
spinner5.start("Fetching tenants");
|
|
1846
1925
|
let tenants;
|
|
1847
1926
|
try {
|
|
1848
1927
|
tenants = await fetchTenants(opts.api, identityJwt);
|
|
1849
|
-
|
|
1928
|
+
spinner5.stop(
|
|
1850
1929
|
`Found ${tenants.length} tenant${tenants.length === 1 ? "" : "s"}`
|
|
1851
1930
|
);
|
|
1852
1931
|
} catch (err) {
|
|
1853
|
-
|
|
1932
|
+
spinner5.stop("Failed to fetch tenants");
|
|
1854
1933
|
bail(err.message);
|
|
1855
1934
|
}
|
|
1856
1935
|
const tenant = await selectTenant(tenants, opts);
|
|
@@ -1863,13 +1942,13 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1863
1942
|
`listing.json has distributionType "PUBLIC" but no pricing.subscriptionTiers \u2014 public listings require at least one tier. Add one, or set distributionType to "PRIVATE" if this app isn't ready for App Store review yet.`
|
|
1864
1943
|
);
|
|
1865
1944
|
}
|
|
1866
|
-
|
|
1945
|
+
spinner5.start("Looking up the registered app");
|
|
1867
1946
|
let appId;
|
|
1868
1947
|
try {
|
|
1869
1948
|
appId = await resolveAppId(opts.api, jwt, tenant.id, technicalName);
|
|
1870
|
-
|
|
1949
|
+
spinner5.stop(`Found app ${pc3.cyan(appId)}`);
|
|
1871
1950
|
} catch (err) {
|
|
1872
|
-
|
|
1951
|
+
spinner5.stop("Failed to look up the app");
|
|
1873
1952
|
bail(err.message);
|
|
1874
1953
|
}
|
|
1875
1954
|
const reviewLines = [
|
|
@@ -1886,7 +1965,7 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1886
1965
|
true
|
|
1887
1966
|
);
|
|
1888
1967
|
if (!confirm2) bail("Cancelled.");
|
|
1889
|
-
|
|
1968
|
+
spinner5.start("Creating listing");
|
|
1890
1969
|
let slug;
|
|
1891
1970
|
let publisherId;
|
|
1892
1971
|
try {
|
|
@@ -1897,9 +1976,9 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1897
1976
|
appId,
|
|
1898
1977
|
listingData
|
|
1899
1978
|
));
|
|
1900
|
-
|
|
1979
|
+
spinner5.stop(`Listing created (${pc3.cyan(slug)})`);
|
|
1901
1980
|
} catch (err) {
|
|
1902
|
-
|
|
1981
|
+
spinner5.stop("Failed to create listing");
|
|
1903
1982
|
const message = err.message;
|
|
1904
1983
|
if (/AppListingAlreadyExists/.test(message)) {
|
|
1905
1984
|
bail(
|
|
@@ -1908,12 +1987,12 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1908
1987
|
}
|
|
1909
1988
|
bail(message);
|
|
1910
1989
|
}
|
|
1911
|
-
|
|
1990
|
+
spinner5.start("Pushing listing details");
|
|
1912
1991
|
try {
|
|
1913
1992
|
await updateAppListing(opts.api, jwt, tenant.id, slug, appId, listingData);
|
|
1914
|
-
|
|
1993
|
+
spinner5.stop("Listing updated");
|
|
1915
1994
|
} catch (err) {
|
|
1916
|
-
|
|
1995
|
+
spinner5.stop("Failed to push listing details");
|
|
1917
1996
|
bail(err.message);
|
|
1918
1997
|
}
|
|
1919
1998
|
const hubUrl = buildHubAppOverviewUrl(opts.hub, tenant.slug);
|
|
@@ -1927,6 +2006,110 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1927
2006
|
p3.outro(pc3.green("Done. Listing pushed."));
|
|
1928
2007
|
}
|
|
1929
2008
|
|
|
2009
|
+
// src/session.ts
|
|
2010
|
+
import * as p4 from "@clack/prompts";
|
|
2011
|
+
import { parseArgs as parseArgs3 } from "util";
|
|
2012
|
+
import pc4 from "picocolors";
|
|
2013
|
+
var SESSION_ARG_OPTIONS = {
|
|
2014
|
+
"auth-host": { type: "string" },
|
|
2015
|
+
"client-id": { type: "string" },
|
|
2016
|
+
scope: { type: "string" }
|
|
2017
|
+
};
|
|
2018
|
+
var LOGOUT_ARG_OPTIONS = {
|
|
2019
|
+
"auth-host": { type: "string" },
|
|
2020
|
+
"client-id": { type: "string" },
|
|
2021
|
+
all: { type: "boolean" }
|
|
2022
|
+
};
|
|
2023
|
+
function parse(args, options) {
|
|
2024
|
+
try {
|
|
2025
|
+
return parseArgs3({ args, options, strict: true, allowPositionals: false });
|
|
2026
|
+
} catch (err) {
|
|
2027
|
+
bail(`${err.message}. Run with --help for usage.`);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
function describeAccount(jwt) {
|
|
2031
|
+
const claims = decodeJwtClaims(jwt);
|
|
2032
|
+
const name = claims.email ?? claims.preferred_username ?? claims.name ?? claims.sub;
|
|
2033
|
+
return name ?? "unknown account";
|
|
2034
|
+
}
|
|
2035
|
+
async function login(argv = [], runOpts = {}) {
|
|
2036
|
+
const parsed = parse(argv, SESSION_ARG_OPTIONS);
|
|
2037
|
+
const opts = resolveCommonOptions(parsed.values);
|
|
2038
|
+
console.log();
|
|
2039
|
+
p4.intro(pc4.bgCyan(pc4.black(" sign in ")));
|
|
2040
|
+
const spinner5 = p4.spinner();
|
|
2041
|
+
let jwt;
|
|
2042
|
+
try {
|
|
2043
|
+
jwt = await acquireAccessToken({
|
|
2044
|
+
auth: opts.auth,
|
|
2045
|
+
clientId: opts.clientId,
|
|
2046
|
+
scope: opts.scope,
|
|
2047
|
+
reauth: true,
|
|
2048
|
+
spinner: spinner5,
|
|
2049
|
+
captureOptions: runOpts.captureOptions
|
|
2050
|
+
});
|
|
2051
|
+
} catch (err) {
|
|
2052
|
+
bail(err.message);
|
|
2053
|
+
}
|
|
2054
|
+
p4.outro(`Signed in to ${opts.auth} as ${pc4.bold(describeAccount(jwt))}.`);
|
|
2055
|
+
}
|
|
2056
|
+
async function revokeRefreshToken(authBaseUrl, clientId, refreshToken) {
|
|
2057
|
+
try {
|
|
2058
|
+
const { revocation_endpoint } = await discoverOidc(authBaseUrl);
|
|
2059
|
+
if (!revocation_endpoint) return false;
|
|
2060
|
+
const res = await fetch(revocation_endpoint, {
|
|
2061
|
+
method: "POST",
|
|
2062
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
2063
|
+
body: new URLSearchParams({
|
|
2064
|
+
token: refreshToken,
|
|
2065
|
+
token_type_hint: "refresh_token",
|
|
2066
|
+
client_id: clientId
|
|
2067
|
+
})
|
|
2068
|
+
});
|
|
2069
|
+
return res.ok;
|
|
2070
|
+
} catch {
|
|
2071
|
+
return false;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
async function logout(argv = []) {
|
|
2075
|
+
const parsed = parse(argv, LOGOUT_ARG_OPTIONS);
|
|
2076
|
+
console.log();
|
|
2077
|
+
p4.intro(pc4.bgCyan(pc4.black(" sign out ")));
|
|
2078
|
+
if (parsed.values.all) {
|
|
2079
|
+
const cache = readTokenCache();
|
|
2080
|
+
const hosts = Object.keys(cache);
|
|
2081
|
+
for (const host of hosts) {
|
|
2082
|
+
const entry = cache[host];
|
|
2083
|
+
if (entry.refresh_token) {
|
|
2084
|
+
await revokeRefreshToken(
|
|
2085
|
+
`https://${host}`,
|
|
2086
|
+
entry.client_id,
|
|
2087
|
+
entry.refresh_token
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
writeTokenCache({});
|
|
2092
|
+
p4.outro(
|
|
2093
|
+
hosts.length > 0 ? `Signed out of ${hosts.join(", ")}.` : "No cached logins to remove."
|
|
2094
|
+
);
|
|
2095
|
+
return;
|
|
2096
|
+
}
|
|
2097
|
+
const opts = resolveCommonOptions(parsed.values);
|
|
2098
|
+
const removed = removeCachedToken(opts.auth);
|
|
2099
|
+
if (!removed) {
|
|
2100
|
+
p4.outro(`Not signed in to ${cacheKey(opts.auth)}.`);
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
const revoked = removed.refresh_token ? await revokeRefreshToken(
|
|
2104
|
+
opts.auth,
|
|
2105
|
+
removed.client_id,
|
|
2106
|
+
removed.refresh_token
|
|
2107
|
+
) : false;
|
|
2108
|
+
p4.outro(
|
|
2109
|
+
revoked ? `Signed out of ${cacheKey(opts.auth)}.` : `Removed the cached login for ${cacheKey(opts.auth)}. The IdP session was not revoked; it expires on its own.`
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
|
|
1930
2113
|
// src/scaffold.ts
|
|
1931
2114
|
import crypto2 from "crypto";
|
|
1932
2115
|
import fs4 from "fs";
|
|
@@ -2220,7 +2403,7 @@ async function scaffold({
|
|
|
2220
2403
|
}
|
|
2221
2404
|
|
|
2222
2405
|
// src/scaffold-args.ts
|
|
2223
|
-
import { parseArgs as
|
|
2406
|
+
import { parseArgs as parseArgs4 } from "util";
|
|
2224
2407
|
var SCAFFOLD_ARG_OPTIONS = {
|
|
2225
2408
|
name: { type: "string" },
|
|
2226
2409
|
description: { type: "string" },
|
|
@@ -2252,7 +2435,7 @@ function pickTemplate(flag, value, templates) {
|
|
|
2252
2435
|
function resolveScaffoldArgs(args, templates, isTTY = Boolean(process.stdin.isTTY)) {
|
|
2253
2436
|
let parsed;
|
|
2254
2437
|
try {
|
|
2255
|
-
parsed =
|
|
2438
|
+
parsed = parseArgs4({
|
|
2256
2439
|
args,
|
|
2257
2440
|
options: SCAFFOLD_ARG_OPTIONS,
|
|
2258
2441
|
strict: true,
|
|
@@ -2333,7 +2516,7 @@ import os2 from "os";
|
|
|
2333
2516
|
import path6 from "path";
|
|
2334
2517
|
import { PostHog } from "posthog-node";
|
|
2335
2518
|
var TOKEN = "phc_SkFAxTIa4RUQxotci1Ftdw7xefZK2Ax0LEIGcl8zuD2";
|
|
2336
|
-
var CLI_VERSION = "0.
|
|
2519
|
+
var CLI_VERSION = "0.10.0";
|
|
2337
2520
|
var client = TOKEN ? new PostHog(TOKEN, { host: "https://e.jtl-cloud.com" }) : null;
|
|
2338
2521
|
function telemetryDisabledByEnv() {
|
|
2339
2522
|
const dnt = process.env.DO_NOT_TRACK;
|
|
@@ -2428,37 +2611,37 @@ function halfSelectOptions(templates, noneHint) {
|
|
|
2428
2611
|
];
|
|
2429
2612
|
}
|
|
2430
2613
|
function cancelScaffold() {
|
|
2431
|
-
|
|
2614
|
+
p5.cancel("Cancelled.");
|
|
2432
2615
|
process.exit(0);
|
|
2433
2616
|
}
|
|
2434
2617
|
async function runScaffold(argv) {
|
|
2435
2618
|
console.log();
|
|
2436
|
-
|
|
2619
|
+
p5.intro(pc5.bgCyan(pc5.black(" create-cloud-app ")));
|
|
2437
2620
|
const templates = discoverTemplates();
|
|
2438
2621
|
const backends = getTemplatesByType(templates, "backend");
|
|
2439
2622
|
const frontends = getTemplatesByType(templates, "frontend");
|
|
2440
2623
|
const shared = templates.find((t) => t.meta.type === "shared");
|
|
2441
2624
|
if (!backends.length || !frontends.length || !shared) {
|
|
2442
|
-
|
|
2625
|
+
p5.cancel("No templates found. Ensure template packages are installed.");
|
|
2443
2626
|
process.exit(1);
|
|
2444
2627
|
}
|
|
2445
2628
|
const args = resolveScaffoldArgs(argv, { frontends, backends });
|
|
2446
|
-
const answers = await
|
|
2629
|
+
const answers = await p5.group(
|
|
2447
2630
|
{
|
|
2448
|
-
appName: () => args.name !== void 0 ? Promise.resolve(args.name) :
|
|
2631
|
+
appName: () => args.name !== void 0 ? Promise.resolve(args.name) : p5.text({
|
|
2449
2632
|
message: "App name",
|
|
2450
2633
|
placeholder: "my-jtl-app",
|
|
2451
2634
|
validate: validateAppName
|
|
2452
2635
|
}),
|
|
2453
|
-
description: () => args.description !== void 0 || args.nonInteractive ? Promise.resolve(args.description ?? "") :
|
|
2636
|
+
description: () => args.description !== void 0 || args.nonInteractive ? Promise.resolve(args.description ?? "") : p5.text({
|
|
2454
2637
|
message: "Description",
|
|
2455
2638
|
placeholder: "A JTL Platform app"
|
|
2456
2639
|
}),
|
|
2457
|
-
frontend: () => args.frontend !== void 0 ? Promise.resolve(args.frontend?.packageName ?? NONE2) :
|
|
2640
|
+
frontend: () => args.frontend !== void 0 ? Promise.resolve(args.frontend?.packageName ?? NONE2) : p5.select({
|
|
2458
2641
|
message: "Frontend (adds a public client for browser login)",
|
|
2459
2642
|
options: halfSelectOptions(frontends, "no frontend")
|
|
2460
2643
|
}),
|
|
2461
|
-
backend: () => args.backend !== void 0 ? Promise.resolve(args.backend?.packageName ?? NONE2) :
|
|
2644
|
+
backend: () => args.backend !== void 0 ? Promise.resolve(args.backend?.packageName ?? NONE2) : p5.select({
|
|
2462
2645
|
message: "Backend (adds a service account for the JTL API)",
|
|
2463
2646
|
options: halfSelectOptions(backends, "no backend")
|
|
2464
2647
|
})
|
|
@@ -2481,7 +2664,7 @@ async function runScaffold(argv) {
|
|
|
2481
2664
|
if (fs7.existsSync(path7.resolve(process.cwd(), answers.appName))) {
|
|
2482
2665
|
bail(`Directory "${answers.appName}" already exists.`);
|
|
2483
2666
|
}
|
|
2484
|
-
const s =
|
|
2667
|
+
const s = p5.spinner();
|
|
2485
2668
|
s.start("Scaffolding project");
|
|
2486
2669
|
const frontendPort = selectedFrontend ? await pickFrontendPort() : void 0;
|
|
2487
2670
|
await scaffold({
|
|
@@ -2499,37 +2682,37 @@ async function runScaffold(argv) {
|
|
|
2499
2682
|
});
|
|
2500
2683
|
s.stop("Project scaffolded");
|
|
2501
2684
|
if (selectedFrontend) {
|
|
2502
|
-
|
|
2503
|
-
`The frontend dev server runs on ${
|
|
2685
|
+
p5.note(
|
|
2686
|
+
`The frontend dev server runs on ${pc5.cyan(`http://localhost:${frontendPort}`)}, and its ${pc5.cyan("/callback")} route is registered as the public client's redirect URI.`,
|
|
2504
2687
|
"Frontend login"
|
|
2505
2688
|
);
|
|
2506
2689
|
}
|
|
2507
2690
|
if (legacy && selectedBackend) {
|
|
2508
|
-
|
|
2691
|
+
p5.note(
|
|
2509
2692
|
"The backend is scaffolded for the legacy Ory M2M flow. `npm run register` will write its Ory client credentials.",
|
|
2510
2693
|
"Legacy backend"
|
|
2511
2694
|
);
|
|
2512
2695
|
}
|
|
2513
2696
|
printNextSteps(answers.appName);
|
|
2514
|
-
|
|
2697
|
+
p5.outro(pc5.green("Done! Happy building."));
|
|
2515
2698
|
return {
|
|
2516
2699
|
...scaffoldChoice(selectedBackend, selectedFrontend, legacy),
|
|
2517
2700
|
non_interactive: args.nonInteractive
|
|
2518
2701
|
};
|
|
2519
2702
|
}
|
|
2520
2703
|
function printNextSteps(appName) {
|
|
2521
|
-
|
|
2704
|
+
p5.note(
|
|
2522
2705
|
[
|
|
2523
|
-
`${
|
|
2524
|
-
`${
|
|
2525
|
-
`${
|
|
2526
|
-
`${
|
|
2527
|
-
`${
|
|
2706
|
+
`${pc5.cyan("cd")} ${appName}`,
|
|
2707
|
+
`${pc5.cyan("npm install")}`,
|
|
2708
|
+
`${pc5.cyan("npm run register")}`,
|
|
2709
|
+
`${pc5.cyan("npm run dev")}`,
|
|
2710
|
+
`${pc5.cyan("npm run listing")} ${pc5.dim("(once you're ready to publish)")}`
|
|
2528
2711
|
].join("\n"),
|
|
2529
2712
|
"Next steps"
|
|
2530
2713
|
);
|
|
2531
2714
|
}
|
|
2532
|
-
var SUBCOMMANDS = ["register", "listing"];
|
|
2715
|
+
var SUBCOMMANDS = ["register", "listing", "login", "logout"];
|
|
2533
2716
|
function handleMeta(argv) {
|
|
2534
2717
|
const [first, second] = argv;
|
|
2535
2718
|
if (first === "-v" || first === "--version") {
|
|
@@ -2570,6 +2753,10 @@ async function main() {
|
|
|
2570
2753
|
detail = await register(argv.slice(1));
|
|
2571
2754
|
} else if (command === "listing") {
|
|
2572
2755
|
await listing(argv.slice(1));
|
|
2756
|
+
} else if (command === "login") {
|
|
2757
|
+
await login(argv.slice(1));
|
|
2758
|
+
} else if (command === "logout") {
|
|
2759
|
+
await logout(argv.slice(1));
|
|
2573
2760
|
} else {
|
|
2574
2761
|
detail = await runScaffold(argv);
|
|
2575
2762
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jtl-software/create-cloud-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI tool for scaffolding JTL Platform cloud apps",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/jtl-software/cloud-apps-cli.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
6
11
|
"bin": {
|
|
7
12
|
"create-cloud-app": "./dist/index.js"
|
|
8
13
|
},
|
|
@@ -17,20 +22,20 @@
|
|
|
17
22
|
"dev": "tsx src/index.ts"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@clack/prompts": "^1.
|
|
25
|
+
"@clack/prompts": "^1.8.1",
|
|
21
26
|
"@jtl-software/cloud-app-template-backend-dotnet": "0.2.0",
|
|
22
|
-
"@jtl-software/cloud-app-template-backend-node": "0.3.
|
|
27
|
+
"@jtl-software/cloud-app-template-backend-node": "0.3.2",
|
|
23
28
|
"@jtl-software/cloud-app-template-backend-php": "0.3.0",
|
|
24
|
-
"@jtl-software/cloud-app-template-frontend-react": "0.3.
|
|
29
|
+
"@jtl-software/cloud-app-template-frontend-react": "0.3.3",
|
|
25
30
|
"@jtl-software/cloud-app-template-shared": "0.2.0",
|
|
26
31
|
"picocolors": "^1.1.1",
|
|
27
|
-
"posthog-node": "^5.
|
|
32
|
+
"posthog-node": "^5.55.3"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
|
-
"@types/node": "^26.
|
|
35
|
+
"@types/node": "^26.6.5",
|
|
31
36
|
"msw": "^2.15.0",
|
|
32
37
|
"tsup": "^8.5.1",
|
|
33
|
-
"tsx": "^4.23.
|
|
38
|
+
"tsx": "^4.23.15",
|
|
34
39
|
"typescript": "^6.0.3"
|
|
35
40
|
},
|
|
36
41
|
"publishConfig": {
|