@jtl-software/create-cloud-app 0.9.1 → 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 +233 -72
- package/package.json +6 -1
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,13 +384,13 @@ 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
|
}
|
|
@@ -752,6 +763,48 @@ var COMMANDS = {
|
|
|
752
763
|
examples: [
|
|
753
764
|
`${BIN} listing --yes --tenant my-tenant --distribution-type PRIVATE`
|
|
754
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`]
|
|
755
808
|
}
|
|
756
809
|
};
|
|
757
810
|
function flagTable(flags) {
|
|
@@ -777,7 +830,7 @@ function renderOverview(version) {
|
|
|
777
830
|
...flagTable(GLOBAL_FLAGS),
|
|
778
831
|
"",
|
|
779
832
|
`Run \`${BIN} <command> --help\` for the command's flags.`,
|
|
780
|
-
"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.",
|
|
781
834
|
""
|
|
782
835
|
].join("\n");
|
|
783
836
|
}
|
|
@@ -1418,7 +1471,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1418
1471
|
].filter(Boolean).join("\n"),
|
|
1419
1472
|
"Target"
|
|
1420
1473
|
);
|
|
1421
|
-
const
|
|
1474
|
+
const spinner5 = p2.spinner();
|
|
1422
1475
|
let jwt;
|
|
1423
1476
|
try {
|
|
1424
1477
|
jwt = await acquireAccessToken({
|
|
@@ -1426,7 +1479,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1426
1479
|
clientId: opts.clientId,
|
|
1427
1480
|
scope: opts.scope,
|
|
1428
1481
|
reauth: opts.reauth,
|
|
1429
|
-
spinner:
|
|
1482
|
+
spinner: spinner5,
|
|
1430
1483
|
captureOptions: runOpts.captureOptions
|
|
1431
1484
|
});
|
|
1432
1485
|
} catch (err) {
|
|
@@ -1456,15 +1509,15 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1456
1509
|
for (; ; ) {
|
|
1457
1510
|
const identityJwt = jwt;
|
|
1458
1511
|
const apiJwt = jwt;
|
|
1459
|
-
|
|
1512
|
+
spinner5.start("Fetching tenants");
|
|
1460
1513
|
let tenants;
|
|
1461
1514
|
try {
|
|
1462
1515
|
tenants = await fetchTenants(opts.api, identityJwt);
|
|
1463
|
-
|
|
1516
|
+
spinner5.stop(
|
|
1464
1517
|
`Found ${tenants.length} tenant${tenants.length === 1 ? "" : "s"}`
|
|
1465
1518
|
);
|
|
1466
1519
|
} catch (err) {
|
|
1467
|
-
|
|
1520
|
+
spinner5.stop("Failed to fetch tenants");
|
|
1468
1521
|
bail(err.message);
|
|
1469
1522
|
}
|
|
1470
1523
|
let tenant;
|
|
@@ -1478,7 +1531,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1478
1531
|
} else {
|
|
1479
1532
|
tenant = await selectTenant(tenants, opts);
|
|
1480
1533
|
}
|
|
1481
|
-
|
|
1534
|
+
spinner5.start("Looking for apps matching this manifest");
|
|
1482
1535
|
let matches;
|
|
1483
1536
|
try {
|
|
1484
1537
|
const apps = await listTenantApps(
|
|
@@ -1488,11 +1541,11 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1488
1541
|
opts.appServicePath
|
|
1489
1542
|
);
|
|
1490
1543
|
matches = apps.filter((a) => a.technicalName === summary.technicalName);
|
|
1491
|
-
|
|
1544
|
+
spinner5.stop(
|
|
1492
1545
|
`Found ${matches.length} app${matches.length === 1 ? "" : "s"} with technical name ${pc2.cyan(summary.technicalName)}`
|
|
1493
1546
|
);
|
|
1494
1547
|
} catch (err) {
|
|
1495
|
-
|
|
1548
|
+
spinner5.stop("Failed to look up tenant apps");
|
|
1496
1549
|
bail(err.message);
|
|
1497
1550
|
}
|
|
1498
1551
|
const existing = await selectExistingOrNew(matches, opts);
|
|
@@ -1518,7 +1571,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1518
1571
|
scope: opts.scope,
|
|
1519
1572
|
reauth: true,
|
|
1520
1573
|
// forces prompt=select_account so the user re-picks the organization
|
|
1521
|
-
spinner:
|
|
1574
|
+
spinner: spinner5,
|
|
1522
1575
|
captureOptions: runOpts.captureOptions
|
|
1523
1576
|
});
|
|
1524
1577
|
} catch (err) {
|
|
@@ -1527,7 +1580,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1527
1580
|
continue;
|
|
1528
1581
|
}
|
|
1529
1582
|
if (existing) {
|
|
1530
|
-
|
|
1583
|
+
spinner5.start("Updating manifest");
|
|
1531
1584
|
try {
|
|
1532
1585
|
await updateAppManifest(
|
|
1533
1586
|
opts.api,
|
|
@@ -1537,13 +1590,13 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1537
1590
|
manifest,
|
|
1538
1591
|
opts.appServicePath
|
|
1539
1592
|
);
|
|
1540
|
-
|
|
1593
|
+
spinner5.stop("Manifest updated");
|
|
1541
1594
|
} catch (err) {
|
|
1542
|
-
|
|
1595
|
+
spinner5.stop("Failed to update manifest");
|
|
1543
1596
|
bail(err.message);
|
|
1544
1597
|
}
|
|
1545
1598
|
if (existing.provisioningStatus === "DRAFT") {
|
|
1546
|
-
|
|
1599
|
+
spinner5.start("Provisioning app");
|
|
1547
1600
|
let provisioned2;
|
|
1548
1601
|
try {
|
|
1549
1602
|
provisioned2 = await provisionApp(
|
|
@@ -1553,9 +1606,9 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1553
1606
|
existing.id,
|
|
1554
1607
|
opts.appServicePath
|
|
1555
1608
|
);
|
|
1556
|
-
|
|
1609
|
+
spinner5.stop("Provisioned");
|
|
1557
1610
|
} catch (err) {
|
|
1558
|
-
|
|
1611
|
+
spinner5.stop("Failed to provision app");
|
|
1559
1612
|
bail(err.message);
|
|
1560
1613
|
}
|
|
1561
1614
|
await applyProvisionResult(
|
|
@@ -1624,7 +1677,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1624
1677
|
}
|
|
1625
1678
|
return { ...registerTelemetry, is_new_app: false };
|
|
1626
1679
|
}
|
|
1627
|
-
|
|
1680
|
+
spinner5.start("Creating draft app");
|
|
1628
1681
|
let appId;
|
|
1629
1682
|
try {
|
|
1630
1683
|
appId = await createDraftApp(
|
|
@@ -1634,9 +1687,9 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1634
1687
|
manifest,
|
|
1635
1688
|
opts.appServicePath
|
|
1636
1689
|
);
|
|
1637
|
-
|
|
1690
|
+
spinner5.stop(`Created app ${pc2.cyan(appId)}`);
|
|
1638
1691
|
} catch (err) {
|
|
1639
|
-
|
|
1692
|
+
spinner5.stop("Failed to create app");
|
|
1640
1693
|
if (isMissingPublisherError(err)) {
|
|
1641
1694
|
const url = buildPartnerPortalOnboardingUrl(opts.partner, tenant.slug);
|
|
1642
1695
|
p2.note(pc2.cyan(terminalLink(url)), "Register as publisher");
|
|
@@ -1646,7 +1699,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1646
1699
|
}
|
|
1647
1700
|
bail(err.message);
|
|
1648
1701
|
}
|
|
1649
|
-
|
|
1702
|
+
spinner5.start("Provisioning app");
|
|
1650
1703
|
let provisioned;
|
|
1651
1704
|
try {
|
|
1652
1705
|
provisioned = await provisionApp(
|
|
@@ -1656,9 +1709,9 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1656
1709
|
appId,
|
|
1657
1710
|
opts.appServicePath
|
|
1658
1711
|
);
|
|
1659
|
-
|
|
1712
|
+
spinner5.stop("Provisioned");
|
|
1660
1713
|
} catch (err) {
|
|
1661
|
-
|
|
1714
|
+
spinner5.stop("Failed to provision app");
|
|
1662
1715
|
bail(err.message);
|
|
1663
1716
|
}
|
|
1664
1717
|
await applyProvisionResult(
|
|
@@ -1853,7 +1906,7 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1853
1906
|
].join("\n"),
|
|
1854
1907
|
"Target"
|
|
1855
1908
|
);
|
|
1856
|
-
const
|
|
1909
|
+
const spinner5 = p3.spinner();
|
|
1857
1910
|
let jwt;
|
|
1858
1911
|
try {
|
|
1859
1912
|
jwt = await acquireAccessToken({
|
|
@@ -1861,22 +1914,22 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1861
1914
|
clientId: opts.clientId,
|
|
1862
1915
|
scope: opts.scope,
|
|
1863
1916
|
reauth: opts.reauth,
|
|
1864
|
-
spinner:
|
|
1917
|
+
spinner: spinner5,
|
|
1865
1918
|
captureOptions: runOpts.captureOptions
|
|
1866
1919
|
});
|
|
1867
1920
|
} catch (err) {
|
|
1868
1921
|
bail(err.message);
|
|
1869
1922
|
}
|
|
1870
1923
|
const identityJwt = jwt;
|
|
1871
|
-
|
|
1924
|
+
spinner5.start("Fetching tenants");
|
|
1872
1925
|
let tenants;
|
|
1873
1926
|
try {
|
|
1874
1927
|
tenants = await fetchTenants(opts.api, identityJwt);
|
|
1875
|
-
|
|
1928
|
+
spinner5.stop(
|
|
1876
1929
|
`Found ${tenants.length} tenant${tenants.length === 1 ? "" : "s"}`
|
|
1877
1930
|
);
|
|
1878
1931
|
} catch (err) {
|
|
1879
|
-
|
|
1932
|
+
spinner5.stop("Failed to fetch tenants");
|
|
1880
1933
|
bail(err.message);
|
|
1881
1934
|
}
|
|
1882
1935
|
const tenant = await selectTenant(tenants, opts);
|
|
@@ -1889,13 +1942,13 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1889
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.`
|
|
1890
1943
|
);
|
|
1891
1944
|
}
|
|
1892
|
-
|
|
1945
|
+
spinner5.start("Looking up the registered app");
|
|
1893
1946
|
let appId;
|
|
1894
1947
|
try {
|
|
1895
1948
|
appId = await resolveAppId(opts.api, jwt, tenant.id, technicalName);
|
|
1896
|
-
|
|
1949
|
+
spinner5.stop(`Found app ${pc3.cyan(appId)}`);
|
|
1897
1950
|
} catch (err) {
|
|
1898
|
-
|
|
1951
|
+
spinner5.stop("Failed to look up the app");
|
|
1899
1952
|
bail(err.message);
|
|
1900
1953
|
}
|
|
1901
1954
|
const reviewLines = [
|
|
@@ -1912,7 +1965,7 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1912
1965
|
true
|
|
1913
1966
|
);
|
|
1914
1967
|
if (!confirm2) bail("Cancelled.");
|
|
1915
|
-
|
|
1968
|
+
spinner5.start("Creating listing");
|
|
1916
1969
|
let slug;
|
|
1917
1970
|
let publisherId;
|
|
1918
1971
|
try {
|
|
@@ -1923,9 +1976,9 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1923
1976
|
appId,
|
|
1924
1977
|
listingData
|
|
1925
1978
|
));
|
|
1926
|
-
|
|
1979
|
+
spinner5.stop(`Listing created (${pc3.cyan(slug)})`);
|
|
1927
1980
|
} catch (err) {
|
|
1928
|
-
|
|
1981
|
+
spinner5.stop("Failed to create listing");
|
|
1929
1982
|
const message = err.message;
|
|
1930
1983
|
if (/AppListingAlreadyExists/.test(message)) {
|
|
1931
1984
|
bail(
|
|
@@ -1934,12 +1987,12 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1934
1987
|
}
|
|
1935
1988
|
bail(message);
|
|
1936
1989
|
}
|
|
1937
|
-
|
|
1990
|
+
spinner5.start("Pushing listing details");
|
|
1938
1991
|
try {
|
|
1939
1992
|
await updateAppListing(opts.api, jwt, tenant.id, slug, appId, listingData);
|
|
1940
|
-
|
|
1993
|
+
spinner5.stop("Listing updated");
|
|
1941
1994
|
} catch (err) {
|
|
1942
|
-
|
|
1995
|
+
spinner5.stop("Failed to push listing details");
|
|
1943
1996
|
bail(err.message);
|
|
1944
1997
|
}
|
|
1945
1998
|
const hubUrl = buildHubAppOverviewUrl(opts.hub, tenant.slug);
|
|
@@ -1953,6 +2006,110 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1953
2006
|
p3.outro(pc3.green("Done. Listing pushed."));
|
|
1954
2007
|
}
|
|
1955
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
|
+
|
|
1956
2113
|
// src/scaffold.ts
|
|
1957
2114
|
import crypto2 from "crypto";
|
|
1958
2115
|
import fs4 from "fs";
|
|
@@ -2246,7 +2403,7 @@ async function scaffold({
|
|
|
2246
2403
|
}
|
|
2247
2404
|
|
|
2248
2405
|
// src/scaffold-args.ts
|
|
2249
|
-
import { parseArgs as
|
|
2406
|
+
import { parseArgs as parseArgs4 } from "util";
|
|
2250
2407
|
var SCAFFOLD_ARG_OPTIONS = {
|
|
2251
2408
|
name: { type: "string" },
|
|
2252
2409
|
description: { type: "string" },
|
|
@@ -2278,7 +2435,7 @@ function pickTemplate(flag, value, templates) {
|
|
|
2278
2435
|
function resolveScaffoldArgs(args, templates, isTTY = Boolean(process.stdin.isTTY)) {
|
|
2279
2436
|
let parsed;
|
|
2280
2437
|
try {
|
|
2281
|
-
parsed =
|
|
2438
|
+
parsed = parseArgs4({
|
|
2282
2439
|
args,
|
|
2283
2440
|
options: SCAFFOLD_ARG_OPTIONS,
|
|
2284
2441
|
strict: true,
|
|
@@ -2359,7 +2516,7 @@ import os2 from "os";
|
|
|
2359
2516
|
import path6 from "path";
|
|
2360
2517
|
import { PostHog } from "posthog-node";
|
|
2361
2518
|
var TOKEN = "phc_SkFAxTIa4RUQxotci1Ftdw7xefZK2Ax0LEIGcl8zuD2";
|
|
2362
|
-
var CLI_VERSION = "0.
|
|
2519
|
+
var CLI_VERSION = "0.10.0";
|
|
2363
2520
|
var client = TOKEN ? new PostHog(TOKEN, { host: "https://e.jtl-cloud.com" }) : null;
|
|
2364
2521
|
function telemetryDisabledByEnv() {
|
|
2365
2522
|
const dnt = process.env.DO_NOT_TRACK;
|
|
@@ -2454,37 +2611,37 @@ function halfSelectOptions(templates, noneHint) {
|
|
|
2454
2611
|
];
|
|
2455
2612
|
}
|
|
2456
2613
|
function cancelScaffold() {
|
|
2457
|
-
|
|
2614
|
+
p5.cancel("Cancelled.");
|
|
2458
2615
|
process.exit(0);
|
|
2459
2616
|
}
|
|
2460
2617
|
async function runScaffold(argv) {
|
|
2461
2618
|
console.log();
|
|
2462
|
-
|
|
2619
|
+
p5.intro(pc5.bgCyan(pc5.black(" create-cloud-app ")));
|
|
2463
2620
|
const templates = discoverTemplates();
|
|
2464
2621
|
const backends = getTemplatesByType(templates, "backend");
|
|
2465
2622
|
const frontends = getTemplatesByType(templates, "frontend");
|
|
2466
2623
|
const shared = templates.find((t) => t.meta.type === "shared");
|
|
2467
2624
|
if (!backends.length || !frontends.length || !shared) {
|
|
2468
|
-
|
|
2625
|
+
p5.cancel("No templates found. Ensure template packages are installed.");
|
|
2469
2626
|
process.exit(1);
|
|
2470
2627
|
}
|
|
2471
2628
|
const args = resolveScaffoldArgs(argv, { frontends, backends });
|
|
2472
|
-
const answers = await
|
|
2629
|
+
const answers = await p5.group(
|
|
2473
2630
|
{
|
|
2474
|
-
appName: () => args.name !== void 0 ? Promise.resolve(args.name) :
|
|
2631
|
+
appName: () => args.name !== void 0 ? Promise.resolve(args.name) : p5.text({
|
|
2475
2632
|
message: "App name",
|
|
2476
2633
|
placeholder: "my-jtl-app",
|
|
2477
2634
|
validate: validateAppName
|
|
2478
2635
|
}),
|
|
2479
|
-
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({
|
|
2480
2637
|
message: "Description",
|
|
2481
2638
|
placeholder: "A JTL Platform app"
|
|
2482
2639
|
}),
|
|
2483
|
-
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({
|
|
2484
2641
|
message: "Frontend (adds a public client for browser login)",
|
|
2485
2642
|
options: halfSelectOptions(frontends, "no frontend")
|
|
2486
2643
|
}),
|
|
2487
|
-
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({
|
|
2488
2645
|
message: "Backend (adds a service account for the JTL API)",
|
|
2489
2646
|
options: halfSelectOptions(backends, "no backend")
|
|
2490
2647
|
})
|
|
@@ -2507,7 +2664,7 @@ async function runScaffold(argv) {
|
|
|
2507
2664
|
if (fs7.existsSync(path7.resolve(process.cwd(), answers.appName))) {
|
|
2508
2665
|
bail(`Directory "${answers.appName}" already exists.`);
|
|
2509
2666
|
}
|
|
2510
|
-
const s =
|
|
2667
|
+
const s = p5.spinner();
|
|
2511
2668
|
s.start("Scaffolding project");
|
|
2512
2669
|
const frontendPort = selectedFrontend ? await pickFrontendPort() : void 0;
|
|
2513
2670
|
await scaffold({
|
|
@@ -2525,37 +2682,37 @@ async function runScaffold(argv) {
|
|
|
2525
2682
|
});
|
|
2526
2683
|
s.stop("Project scaffolded");
|
|
2527
2684
|
if (selectedFrontend) {
|
|
2528
|
-
|
|
2529
|
-
`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.`,
|
|
2530
2687
|
"Frontend login"
|
|
2531
2688
|
);
|
|
2532
2689
|
}
|
|
2533
2690
|
if (legacy && selectedBackend) {
|
|
2534
|
-
|
|
2691
|
+
p5.note(
|
|
2535
2692
|
"The backend is scaffolded for the legacy Ory M2M flow. `npm run register` will write its Ory client credentials.",
|
|
2536
2693
|
"Legacy backend"
|
|
2537
2694
|
);
|
|
2538
2695
|
}
|
|
2539
2696
|
printNextSteps(answers.appName);
|
|
2540
|
-
|
|
2697
|
+
p5.outro(pc5.green("Done! Happy building."));
|
|
2541
2698
|
return {
|
|
2542
2699
|
...scaffoldChoice(selectedBackend, selectedFrontend, legacy),
|
|
2543
2700
|
non_interactive: args.nonInteractive
|
|
2544
2701
|
};
|
|
2545
2702
|
}
|
|
2546
2703
|
function printNextSteps(appName) {
|
|
2547
|
-
|
|
2704
|
+
p5.note(
|
|
2548
2705
|
[
|
|
2549
|
-
`${
|
|
2550
|
-
`${
|
|
2551
|
-
`${
|
|
2552
|
-
`${
|
|
2553
|
-
`${
|
|
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)")}`
|
|
2554
2711
|
].join("\n"),
|
|
2555
2712
|
"Next steps"
|
|
2556
2713
|
);
|
|
2557
2714
|
}
|
|
2558
|
-
var SUBCOMMANDS = ["register", "listing"];
|
|
2715
|
+
var SUBCOMMANDS = ["register", "listing", "login", "logout"];
|
|
2559
2716
|
function handleMeta(argv) {
|
|
2560
2717
|
const [first, second] = argv;
|
|
2561
2718
|
if (first === "-v" || first === "--version") {
|
|
@@ -2596,6 +2753,10 @@ async function main() {
|
|
|
2596
2753
|
detail = await register(argv.slice(1));
|
|
2597
2754
|
} else if (command === "listing") {
|
|
2598
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));
|
|
2599
2760
|
} else {
|
|
2600
2761
|
detail = await runScaffold(argv);
|
|
2601
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
|
},
|