@sap/cli-core 2023.17.0 → 2023.19.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +185 -2
  2. package/cache/secrets/SecretsStorageImpl.d.ts +22 -0
  3. package/cache/secrets/SecretsStorageImpl.js +151 -0
  4. package/cache/secrets/SecretsStorageSingleton.d.ts +4 -0
  5. package/cache/secrets/SecretsStorageSingleton.js +7 -0
  6. package/cache/secrets/types.d.ts +11 -0
  7. package/cache/secrets/types.js +2 -0
  8. package/cache/secrets/utils.d.ts +2 -0
  9. package/cache/secrets/utils.js +18 -0
  10. package/commands/{cache.command → config.command/cache.command}/clean.command.d.ts +1 -1
  11. package/commands/{cache.command → config.command/cache.command}/clean.command.js +3 -3
  12. package/commands/{cache.command → config.command/cache.command}/index.d.ts +1 -1
  13. package/commands/config.command/cache.command/init.command.d.ts +4 -0
  14. package/commands/{cache.command → config.command/cache.command}/init.command.js +15 -8
  15. package/commands/{cache.command → config.command/cache.command}/show.command.d.ts +1 -1
  16. package/commands/{cache.command → config.command/cache.command}/show.command.js +4 -4
  17. package/commands/{host.command.d.ts → config.command/host.command.d.ts} +1 -1
  18. package/commands/{host.command.js → config.command/host.command.js} +12 -12
  19. package/commands/config.command/index.d.ts +2 -0
  20. package/commands/config.command/index.js +19 -0
  21. package/commands/{passcode.command.d.ts → config.command/passcode.command.d.ts} +1 -1
  22. package/commands/{passcode.command.js → config.command/passcode.command.js} +8 -8
  23. package/commands/{secrets.command → config.command/secrets.command}/index.d.ts +1 -1
  24. package/commands/{secrets.command → config.command/secrets.command}/index.js +2 -1
  25. package/commands/config.command/secrets.command/reset.command.d.ts +3 -0
  26. package/commands/config.command/secrets.command/reset.command.js +17 -0
  27. package/commands/{secrets.command → config.command/secrets.command}/show.command.d.ts +1 -1
  28. package/commands/{secrets.command → config.command/secrets.command}/show.command.js +14 -7
  29. package/commands/handler/authentication/oauth/secretsProvider/cache.js +4 -5
  30. package/commands/handler/authentication/oauth/secretsProvider/file.js +3 -3
  31. package/commands/handler/authentication/oauth/secretsProvider/options.js +12 -6
  32. package/commands/handler/authentication/oauth/tokenProvider/getToken.js +5 -61
  33. package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +1 -1
  34. package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +4 -4
  35. package/commands/handler/authentication/oauth/tokenProvider/utils.d.ts +2 -0
  36. package/commands/handler/authentication/oauth/tokenProvider/utils.js +77 -4
  37. package/commands/handler/authentication/oauth/utils.d.ts +0 -4
  38. package/commands/handler/authentication/oauth/utils.js +13 -27
  39. package/commands/handler/authentication/passcode/function.js +1 -1
  40. package/commands/handler/authentication/passcode/input.js +2 -2
  41. package/commands/handler/authentication/passcode/setPasscode.js +1 -1
  42. package/commands/handler/authentication/technicalJWT/index.js +2 -2
  43. package/commands/handler/authentication/technicalJWT/utils.js +1 -1
  44. package/commands/handler/checkOptionsExistence.js +1 -1
  45. package/commands/handler/error.js +2 -2
  46. package/commands/handler/fail.js +1 -1
  47. package/commands/handler/fetch/fetch.js +1 -1
  48. package/commands/handler/fetch/utils.js +1 -1
  49. package/commands/handler/input/file.js +1 -1
  50. package/commands/handler/input/input.js +2 -2
  51. package/commands/handler/mandatoryOptions.js +1 -1
  52. package/commands/handler/next.js +3 -2
  53. package/commands/handler/options/env.js +1 -2
  54. package/commands/handler/options/file.js +1 -1
  55. package/commands/handler/options/index.js +5 -4
  56. package/commands/handler/options/option.js +1 -1
  57. package/commands/handler/options/pipe.js +1 -1
  58. package/commands/handler/options/utils.d.ts +1 -1
  59. package/commands/handler/options/utils.js +11 -4
  60. package/commands/handler/or.js +3 -2
  61. package/commands/handler/parseArguments.js +1 -1
  62. package/commands/handler/resilient.js +2 -2
  63. package/commands/handler/root/index.js +2 -2
  64. package/commands/handler/stackTrace.js +2 -2
  65. package/commands/handler/succeed.js +1 -1
  66. package/commands/login.command.js +34 -4
  67. package/commands/logout.command.js +16 -6
  68. package/commands/openAPI.command/index.js +3 -8
  69. package/commands/openAPI.command/utils.js +4 -13
  70. package/commands/utils.d.ts +2 -0
  71. package/commands/utils.js +8 -0
  72. package/config/core.d.ts +1 -0
  73. package/config/core.js +5 -1
  74. package/config/index.js +1 -0
  75. package/constants.d.ts +3 -1
  76. package/constants.js +34 -5
  77. package/discovery/index.js +0 -4
  78. package/dwc/dwc.js +16 -26
  79. package/dwc/run.js +2 -0
  80. package/dwc/utils.d.ts +2 -0
  81. package/dwc/utils.js +34 -2
  82. package/index.d.ts +2 -1
  83. package/index.js +4 -1
  84. package/logger/index.d.ts +1 -10
  85. package/logger/types.d.ts +10 -0
  86. package/logger/types.js +2 -0
  87. package/logger/utils.d.ts +2 -0
  88. package/logger/utils.js +12 -0
  89. package/package.json +3 -2
  90. package/types.d.ts +9 -3
  91. package/utils/commands.d.ts +2 -2
  92. package/utils/commands.js +23 -11
  93. package/utils/http/index.js +0 -1
  94. package/utils/utils.d.ts +5 -1
  95. package/utils/utils.js +15 -4
  96. package/commands/cache.command/init.command.d.ts +0 -3
  97. /package/commands/{cache.command → config.command/cache.command}/index.js +0 -0
package/CHANGELOG.md CHANGED
@@ -5,14 +5,197 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2023.19.0
9
+
10
+ ### Fixed
11
+
12
+ - Logging in failed if required information such as the client ID or client secret were provided via interactive input prompt. When the information were provided using a secrets file or via options, the login worked as expected.
13
+
14
+ ## 2023.18.0
15
+
16
+ ### Added
17
+
18
+ - Support for managing multiple logins/secrets for different tenants in parallel. The `<cli> login` and `<cli> logout` commands have been updated, allowing you to login to multiple tenants in parallel. When running a command, the CLI uses the secret matching the currently maintained tenant URL via the `-H, --host` option or set via `<cli> config host set <host>`. You now must specify the host which you are logging in to using option `-H, --host`, or by setting the host globally first by calling `<cli> config host set <host>`, to allow the CLI to store the secret for the defined tenant URL.
19
+
20
+ You can list all locally stored secrets by running `<cli> config secrets show`.
21
+
22
+ ```javascript
23
+ $ <cli> config secrets show
24
+ [
25
+ {
26
+ "id": 0,
27
+ "client_id": "sb-0d85e619...",
28
+ "client_secret": "1dcc0522-...",
29
+ "tenantUrl": "https://somehost.eu10.cloud.sap",
30
+ ...
31
+ },
32
+ {
33
+ "id": 1,
34
+ "client_id": "sb-0d85e619...",
35
+ "client_secret": "1dcc0522-...",
36
+ "tenantUrl": "https://somehost.us10.cloud.sap",
37
+ ...
38
+ }
39
+ ]
40
+ ```
41
+
42
+ In order to logout again, the `<cli> logout` command allows you to optionally specify the ID of the login/secret to remove using option `-l, --login-id <id>`.
43
+
44
+ ```javascript
45
+ <cli> logout --help
46
+ Usage: <cli> logout [options]
47
+
48
+ log out from your account
49
+
50
+ Options:
51
+ -l, --login-id <id> specifies the login ID (optional) (choices: "0", default: "0")
52
+ -h, --help display help for command
53
+ ```
54
+
55
+ By default, when you omit option `-l, --login-id <id>`, the login/secret with ID _0_ is removed.
56
+
57
+ You cannot login to the same tenant with different _access tokens_ at the same time. There can only be a single login/secret per tenant, but you can login into multiple tenants in parallel. If you need to login with different users into the same tenant, you have to logout first, then login again with a different user.
58
+
59
+ - Support for predefined OAuth clients where the client ID _does not_ start with the term `sb-`. When using a predefined OAuth client where the client ID _does not_ start with the term `sb-`, the CLI uses a different default port `65000` to retrieve the temporary code to retrieve the access token and refresh token. The port can be changed using the environment variable mentioned in the [README.md](README.md) file.
60
+
61
+ - Improved OAuth authorization URL and token URL support. You do not have to specify the options for the _OAuth Client Authorization URL_ and _Token URL_ anymore, if you specify the tenant URL using the _-H, --host_ option. The CLI calculates the required authorization and token URLs automatically based on the given _Client ID_, _Client Secret_, and _Tenant URL_. You can still use the respective options to provide values for the authorization URL and token URL to override the calculated values.
62
+
63
+ ### Changed
64
+
65
+ - Generic options are hidden for all commands. Before, all options where shown, including generic options applicable to any command.
66
+
67
+ ```bash
68
+ $ <cli> spaces read --help
69
+ Usage: <cli> spaces read [options]
70
+ fetch space details for a specified space
71
+ Options:
72
+ -V, --verbose print detailed log information to console (optional)
73
+ -O, --options-file <file> path to options file (optional)
74
+ -H, --host <host> specifies the url where the tenant is hosted (optional)
75
+ -c, --client-id <id> client id for interactive oauth session authentication (optional)
76
+ -C, --client-secret <secret> client secret for interactive oauth session authentication (optional)
77
+ -a, --access-token <token> access token for interactive oauth session authentication (optional)
78
+ -r, --refresh-token <token> refresh token for interactive oauth session authentication (optional)
79
+ -b, --code <code> code for oauth token retrieval (optional)
80
+ -t, --token-url <url> token url for interactive oauth session authentication (optional)
81
+ -A, --authorization-url <url> authorization url for interactive oauth session authentication (optional)
82
+ -p, --passcode <passcode> passcode for interactive session authentication (optional)
83
+ -s, --secrets-file <file> path to secrets file (optional)
84
+ -e, --expires-in <expires> expires in information for interactive oauth session authentication (optional)
85
+ -o, --output <output> specifies the file to store the output of the command (optional)
86
+ -P, --pretty pretty-formats JSON responses (optional)
87
+ -S, --space <space> space ID (optional)
88
+ -N, --no-space-definition do not read space definition (optional)
89
+ -m, --definitions [definitions] read definitions (optional)
90
+ -q, --connections [connections] read connections (optional)
91
+ -h, --help display help for command
92
+ ```
93
+
94
+ Now, only command-specific options are shown.
95
+
96
+ ```bash
97
+ $ <cli> spaces read --help
98
+ Usage: <cli> spaces read [options]
99
+ fetch space details for a specified space
100
+ Options:
101
+ -S, --space <space> space ID (optional)
102
+ -N, --no-space-definition do not read space definition (optional)
103
+ -m, --definitions [definitions] read definitions (optional)
104
+ -q, --connections [connections] read connections (optional)
105
+ -h, --help display help for command
106
+ Only command-specific options are listed here. To learn more about available generic options, visit https://your.generic.options.help.url
107
+ ```
108
+
109
+ - Option `-P, --pretty` changes to `-n, --no-pretty`. You can now supply option `-n, --no-pretty` to not pretty-format the response of a command. By default, the response of a command is pretty-formatted. When adding the option `-h, --help` to any command, the help tells you about the possible uses.
110
+
111
+ ```bash
112
+ $ <cli> spaces read --help
113
+ Usage: <cli> spaces read [options]
114
+
115
+ fetch space details for a specified space
116
+
117
+ Options:
118
+ -n, --no-pretty do not pretty-format JSON responses (optional)
119
+ -h, --help display help for command
120
+ ```
121
+
122
+ When calling a command that supports the `-P, --pretty` option you can explicitly specify to pretty-print the result.
123
+
124
+ `$ <cli> spaces read --pretty true`
125
+
126
+ To disable pretty-printing, set `-P, --pretty` to `false`.
127
+
128
+ `$ <cli> spaces read --pretty false`
129
+
130
+ Calling a command without specifying the `-P, --pretty` option explicitly yields the same output as when calling the command with `--pretty true`.
131
+
132
+ - A new top-level command `config` has been introduced. This command groups all the CLI configuration-related commands such as `cache`, `secrets`, `host`, ...
133
+
134
+ **Old Structure**
135
+
136
+ ```bash
137
+ $ <cli>
138
+ Usage: <cli> [options] [command]
139
+
140
+ <Your CLI description>
141
+
142
+ Options:
143
+ -v, --version output the current version
144
+ -H, --host <host> specifies the url where the tenant is hosted (optional)
145
+ -O, --options-file <file> path to options file (optional)
146
+ -h, --help display help for command
147
+
148
+ Commands:
149
+ cache work with the local CLI cache
150
+ dbusers [options] manage and orchestrate database users
151
+ help [command] display help for command
152
+ host configure host properties
153
+ login [options] log in to your account using interactive OAuth authentication
154
+ logout log out from your account
155
+ marketplace [options] manage and orchestrate your SAP Data Marketplace
156
+ passcode-url [options] display the passcode url
157
+ secrets work with the locally stored secrets
158
+ spaces [options] manage and orchestrate spaces
159
+ tasks [options] manage tasks
160
+ ```
161
+
162
+ **New Structure**
163
+
164
+ ```bash
165
+ $ <cli>
166
+ Usage: <cli> [options] [command]
167
+
168
+ <Your CLI description>
169
+
170
+ Options:
171
+ -v, --version output the current version
172
+ -H, --host <host> specifies the url where the tenant is hosted (optional)
173
+ -O, --options-file <file> path to options file (optional)
174
+ -h, --help display help for command
175
+
176
+ Commands:
177
+ config configure your CLI
178
+ dbusers [options] manage and orchestrate database users
179
+ help [command] display help for command
180
+ login [options] log in to your account using interactive OAuth authentication
181
+ logout log out from your account
182
+ marketplace [options] manage and orchestrate your SAP Data Marketplace
183
+ spaces [options] manage and orchestrate spaces
184
+ tasks [options] manage tasks
185
+ ```
186
+
187
+ ### Fixed
188
+
189
+ - Values entered for the _Authorization URL_ and _Token URL_ could be entered including query parameters like `https://some.authorization.url?some.parameter=some.value`. The CLI did not remove the query parameters when using the URLs to retrieve the temporary code. This has been changed, the query parameters are now removed. The CLI changes an URL from `https://some.authorization.url?some.parameter=some.value` to `https://some.authorization.url` to retrieve the temporary code.
190
+
8
191
  ## 2023.11.0
9
192
 
10
193
  ### Changed
11
194
 
12
195
  - When using the CLI as a dependency in your Node.js project, calling a command now returns the result directly, if there's any. You don't need to provide a custom logger function anymore to catch the `output` logs. You can now write the following code to work with the result of a command:
13
196
 
14
- ```
15
- import cli from "@sap/dwc-cli";
197
+ ```bash
198
+ import cli from "@sap/<cli>";
16
199
 
17
200
  const commands = await cli.getCommands("https://somehost.eu10.cloud.sap");
18
201
  const result = await commands["some command"](options);
@@ -0,0 +1,22 @@
1
+ import { Secret } from "../../types";
2
+ import { SecretsStorage } from "./types";
3
+ export declare class SecretsStorageImpl implements SecretsStorage {
4
+ private secrets;
5
+ private logger;
6
+ constructor();
7
+ deleteAllSecrets(): Promise<void>;
8
+ private recreateCalculatedValues;
9
+ initializeStorage(): Promise<void>;
10
+ getDefaultSecret(): Promise<Readonly<Secret>>;
11
+ getDefaultSecretId(): Promise<number>;
12
+ private ensureSecretsExist;
13
+ private throwIfSecretsDoesntExist;
14
+ getSecretById(id: number): Promise<Readonly<Secret>>;
15
+ private removeSecretsFromArray;
16
+ private updateSecret;
17
+ private updateUrls;
18
+ storeSecret(secret: Omit<Secret, "id" | "host" | "customClient">): Promise<void>;
19
+ deleteSecretById(id: number): void;
20
+ synchronizeSecretsToStorage(): Promise<void>;
21
+ getAllSecrets(): ReadonlyArray<Secret>;
22
+ }
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecretsStorageImpl = void 0;
4
+ const config_1 = require("../../config");
5
+ const constants_1 = require("../../constants");
6
+ const logger_1 = require("../../logger");
7
+ const http_1 = require("../../utils/http");
8
+ const utils_1 = require("../../utils/utils");
9
+ const cache_1 = require("../cache");
10
+ const utils_2 = require("./utils");
11
+ class SecretsStorageImpl {
12
+ secrets = [];
13
+ logger;
14
+ constructor() {
15
+ this.logger = (0, logger_1.get)("SecretsStorageImpl");
16
+ }
17
+ async deleteAllSecrets() {
18
+ await (0, cache_1.deleteFile)(constants_1.CACHE_SECRETS_FILE);
19
+ this.secrets = [];
20
+ }
21
+ async recreateCalculatedValues() {
22
+ for (let i = 0; i < this.secrets.length; i++) {
23
+ this.secrets[i].id = i;
24
+ if (!this.secrets[i].client_id) {
25
+ this.logger.warn(`client id is not set for secret with ID ${i}, skipping update of secret information`);
26
+ // eslint-disable-next-line no-continue
27
+ continue;
28
+ }
29
+ this.secrets[i].customClient = (0, utils_2.isCustomClient)(this.secrets[i].client_id);
30
+ // eslint-disable-next-line no-await-in-loop
31
+ await this.updateUrls(i);
32
+ }
33
+ }
34
+ async initializeStorage() {
35
+ try {
36
+ this.secrets = JSON.parse(await (0, cache_1.readFile)(constants_1.CACHE_SECRETS_FILE));
37
+ if (!Array.isArray(this.secrets)) {
38
+ this.logger.warn("secrets data is no array, initializing secrets to empty array");
39
+ this.secrets = [];
40
+ }
41
+ await this.recreateCalculatedValues();
42
+ }
43
+ catch (err) {
44
+ this.logger.warn("failed to read or parse secrets file", err);
45
+ }
46
+ }
47
+ async getDefaultSecret() {
48
+ return this.getSecretById(await this.getDefaultSecretId());
49
+ }
50
+ async getDefaultSecretId() {
51
+ const tenantUrl = (0, utils_2.getTenantUrl)();
52
+ const secret = this.secrets.find((s) => new URL(s.tenantUrl).host === new URL(tenantUrl).host);
53
+ if (!secret) {
54
+ throw new Error("Method not implemented.");
55
+ }
56
+ return secret.id;
57
+ }
58
+ ensureSecretsExist(id) {
59
+ return !!this.secrets.at(id);
60
+ }
61
+ throwIfSecretsDoesntExist(id) {
62
+ if (!this.ensureSecretsExist(id)) {
63
+ throw new Error(`no secrets exist for id ${id}`);
64
+ }
65
+ }
66
+ async getSecretById(id) {
67
+ this.throwIfSecretsDoesntExist(id);
68
+ return this.secrets.at(id);
69
+ }
70
+ removeSecretsFromArray(id) {
71
+ this.secrets.splice(id, 1);
72
+ }
73
+ updateSecret(secret) {
74
+ const tenantUrl = (0, utils_2.getTenantUrl)();
75
+ let prevSecretIx = this.secrets.findIndex((s) => s.tenantUrl === tenantUrl);
76
+ let newSecret;
77
+ if (prevSecretIx > -1) {
78
+ newSecret = { ...this.secrets[prevSecretIx], ...secret };
79
+ this.secrets[prevSecretIx] = newSecret;
80
+ }
81
+ else {
82
+ newSecret = {
83
+ ...secret,
84
+ id: this.secrets.length,
85
+ tenantUrl,
86
+ customClient: false,
87
+ };
88
+ this.secrets.push(newSecret);
89
+ prevSecretIx = this.secrets.length - 1;
90
+ }
91
+ return prevSecretIx;
92
+ }
93
+ async updateUrls(secretIndex) {
94
+ const secret = this.secrets[secretIndex];
95
+ if (secret.client_id) {
96
+ const config = (0, config_1.get)();
97
+ let oauth = {};
98
+ if (!secret.customClient &&
99
+ (!secret.authorization_url || !secret.token_url)) {
100
+ oauth = (await (0, http_1.fetch)({
101
+ method: "GET",
102
+ url: `${config.tenantUrl}/oauth`,
103
+ })).data;
104
+ }
105
+ let authorizationUrl = secret.authorization_url;
106
+ if (!authorizationUrl) {
107
+ if (!secret.customClient) {
108
+ authorizationUrl = oauth.authorizationUrl;
109
+ }
110
+ else {
111
+ authorizationUrl = config.authorizationUrl;
112
+ }
113
+ }
114
+ let tokenUrl = secret.token_url;
115
+ if (!tokenUrl) {
116
+ if (!secret.customClient) {
117
+ tokenUrl = oauth.tokenUrl;
118
+ }
119
+ else {
120
+ tokenUrl = config.tokenUrl;
121
+ }
122
+ }
123
+ if (!tokenUrl || !authorizationUrl) {
124
+ throw new Error("invalid token url or authorization url");
125
+ }
126
+ this.secrets[secretIndex].authorization_url =
127
+ (0, utils_1.removeQueryParametersFromUrl)(authorizationUrl);
128
+ this.secrets[secretIndex].token_url = (0, utils_1.removeQueryParametersFromUrl)(tokenUrl);
129
+ }
130
+ }
131
+ async storeSecret(secret) {
132
+ this.updateSecret(secret);
133
+ await this.recreateCalculatedValues();
134
+ }
135
+ deleteSecretById(id) {
136
+ this.throwIfSecretsDoesntExist(id);
137
+ this.removeSecretsFromArray(id);
138
+ }
139
+ async synchronizeSecretsToStorage() {
140
+ try {
141
+ await (0, cache_1.writeFile)(constants_1.CACHE_SECRETS_FILE, JSON.stringify(this.secrets));
142
+ }
143
+ catch (err) {
144
+ this.logger.error("failed to synchronize secrets to storage", err);
145
+ }
146
+ }
147
+ getAllSecrets() {
148
+ return this.secrets;
149
+ }
150
+ }
151
+ exports.SecretsStorageImpl = SecretsStorageImpl;
@@ -0,0 +1,4 @@
1
+ import { SecretsStorage } from "./types";
2
+ export declare class SecretsStorageSingleton {
3
+ static SINGLETON: SecretsStorage;
4
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecretsStorageSingleton = void 0;
4
+ class SecretsStorageSingleton {
5
+ static SINGLETON;
6
+ }
7
+ exports.SecretsStorageSingleton = SecretsStorageSingleton;
@@ -0,0 +1,11 @@
1
+ import { Secret } from "../../types";
2
+ export interface SecretsStorage {
3
+ getDefaultSecretId(): Promise<number>;
4
+ getDefaultSecret(): Promise<Readonly<Secret>>;
5
+ getSecretById(id: number): Promise<Readonly<Secret>>;
6
+ storeSecret(secret: Partial<Secret>): Promise<void>;
7
+ deleteSecretById(id: number): void;
8
+ synchronizeSecretsToStorage(): Promise<void>;
9
+ getAllSecrets(): ReadonlyArray<Secret>;
10
+ deleteAllSecrets(): Promise<void>;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare const isCustomClient: (clientId?: string) => boolean;
2
+ export declare const getTenantUrl: () => string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTenantUrl = exports.isCustomClient = void 0;
4
+ const config_1 = require("../../config");
5
+ const constants_1 = require("../../constants");
6
+ // Pre-delivered OAuth Client ID: 5a638330-5899-366e-ac00-ab62cc32dcda
7
+ // Custom OAuth Client ID: sb-00bb7bc2-cc32-423c-921c-2abdee11a29d!b49931|client!b3650
8
+ const isCustomClient = (clientId) => clientId ? clientId.startsWith("sb-") : true;
9
+ exports.isCustomClient = isCustomClient;
10
+ const getTenantUrl = () => {
11
+ const config = (0, config_1.get)();
12
+ const tenantUrl = config.tenantUrl ?? config.options[constants_1.OPTION_HOST.longName];
13
+ if (!tenantUrl) {
14
+ throw new Error("no tenant url found");
15
+ }
16
+ return tenantUrl;
17
+ };
18
+ exports.getTenantUrl = getTenantUrl;
@@ -1,3 +1,3 @@
1
- import { Command } from "../../types";
1
+ import { Command } from "../../../types";
2
2
  declare const cleanCommand: Command;
3
3
  export default cleanCommand;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const cache_1 = require("../../cache");
4
- const constants_1 = require("../../constants");
5
- const cleanHandler = () => async () => {
3
+ const cache_1 = require("../../../cache");
4
+ const constants_1 = require("../../../constants");
5
+ const cleanHandler = async () => async () => {
6
6
  const files = (await (0, cache_1.getFiles)()).filter((file) => file.startsWith(constants_1.DISCOVERY_DOCUMENT_PREFIX));
7
7
  await Promise.all(files.map(async (file) => (0, cache_1.deleteFile)(file)));
8
8
  };
@@ -1,3 +1,3 @@
1
- import { TopCommand } from "../../types";
1
+ import { TopCommand } from "../../../types";
2
2
  declare const cacheCommand: TopCommand;
3
3
  export default cacheCommand;
@@ -0,0 +1,4 @@
1
+ import { CommanderHandler, LeafCommand } from "../../../types";
2
+ export declare const init: () => Promise<CommanderHandler>;
3
+ declare const initCommand: LeafCommand;
4
+ export default initCommand;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const constants_1 = require("../../constants");
4
- const discovery_1 = require("../../discovery");
5
- const handler_1 = require("../handler");
6
- const config_1 = require("../../config");
7
- const core_1 = require("../../config/core");
8
- const pre = () => async () => {
3
+ exports.init = void 0;
4
+ const constants_1 = require("../../../constants");
5
+ const discovery_1 = require("../../../discovery");
6
+ const handler_1 = require("../../handler");
7
+ const config_1 = require("../../../config");
8
+ const core_1 = require("../../../config/core");
9
+ const pre = () => {
9
10
  const config = (0, config_1.get)();
10
11
  (0, config_1.set)({
11
12
  options: {
@@ -15,7 +16,7 @@ const pre = () => async () => {
15
16
  doNotStoreResult: true,
16
17
  });
17
18
  };
18
- const post = () => async () => {
19
+ const post = async () => {
19
20
  const config = (0, config_1.get)();
20
21
  await (0, discovery_1.addMetadata)({
21
22
  tenant: config.publicfqdn,
@@ -26,11 +27,17 @@ const post = () => async () => {
26
27
  delete options[constants_1.OPTION_OUTPUT.longName];
27
28
  (0, config_1.set)({ options });
28
29
  };
30
+ const init = async () => async () => {
31
+ pre();
32
+ await (await (0, handler_1.createFetchHandler)("GET", (0, core_1.getDiscoveryPath)())({}))();
33
+ await post();
34
+ };
35
+ exports.init = init;
29
36
  const initCommand = {
30
37
  type: "command",
31
38
  command: "init",
32
39
  description: "initialize the local CLI cache",
33
40
  options: [],
34
- handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), pre, (0, handler_1.createFetchHandler)("GET", (0, core_1.getDiscoveryPath)()), post),
41
+ handler: (0, handler_1.createNextHandler)((0, handler_1.createParseArgumentsHandler)(), (0, handler_1.createMandatoryOptionsHandler)(), (0, handler_1.createAuthenticationHandler)(), exports.init),
35
42
  };
36
43
  exports.default = initCommand;
@@ -1,3 +1,3 @@
1
- import { Command } from "../../types";
1
+ import { Command } from "../../../types";
2
2
  declare const showCommand: Command;
3
3
  export default showCommand;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const discovery_1 = require("../../discovery");
4
- const logger_1 = require("../../logger");
5
- const handler_1 = require("../handler");
6
- const show = () => async () => {
3
+ const discovery_1 = require("../../../discovery");
4
+ const logger_1 = require("../../../logger");
5
+ const handler_1 = require("../../handler");
6
+ const show = async () => async () => {
7
7
  const { output } = (0, logger_1.get)("commands.show");
8
8
  const metadata = await (0, discovery_1.getMetadata)();
9
9
  if (metadata.length === 0) {
@@ -1,2 +1,2 @@
1
- import { AddCommands } from "../types";
1
+ import { AddCommands } from "../../types";
2
2
  export declare const addCommands: AddCommands;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addCommands = void 0;
4
- const config_1 = require("../config");
5
- const constants_1 = require("../constants");
6
- const logger_1 = require("../logger");
7
- const settings_1 = require("../settings");
8
- const commands_1 = require("../utils/commands");
9
- const utils_1 = require("../utils/utils");
10
- const handler_1 = require("./handler");
4
+ const config_1 = require("../../config");
5
+ const constants_1 = require("../../constants");
6
+ const logger_1 = require("../../logger");
7
+ const settings_1 = require("../../settings");
8
+ const commands_1 = require("../../utils/commands");
9
+ const utils_1 = require("../../utils/utils");
10
+ const handler_1 = require("../handler");
11
11
  const getLogger = () => (0, logger_1.get)("commands.host");
12
- const set = () => async () => {
12
+ const set = async () => async () => {
13
13
  const config = (0, config_1.get)();
14
14
  try {
15
15
  // throws if host is not valid
@@ -23,22 +23,22 @@ const set = () => async () => {
23
23
  throw new Error("failed to set host");
24
24
  }
25
25
  };
26
- const show = () => async () => {
26
+ const show = async () => async () => {
27
27
  const { output } = getLogger();
28
28
  const settings = await (0, settings_1.get)();
29
29
  if (settings[constants_1.OPTION_HOST.longName]) {
30
30
  output(settings[constants_1.OPTION_HOST.longName]);
31
31
  }
32
32
  else {
33
- output("no global host set. use dwc host set <host> to set a global host");
33
+ output(`no global host set. use ${(0, utils_1.getBin)()} config host set <host> to set a global host`);
34
34
  throw new Error("no global host set");
35
35
  }
36
36
  };
37
- const clean = () => async () => {
37
+ const clean = async () => async () => {
38
38
  await (0, settings_1.remove)(constants_1.OPTION_HOST.longName);
39
39
  };
40
40
  const addCommands = async (program) => {
41
- (0, commands_1.buildCommand)(program, {
41
+ await (0, commands_1.buildCommand)(program, {
42
42
  type: "topCommand",
43
43
  command: "host",
44
44
  description: "configure host properties",
@@ -0,0 +1,2 @@
1
+ import { AddCommands } from "../../types";
2
+ export declare const addCommands: AddCommands;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addCommands = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const commands_1 = require("../../utils/commands");
9
+ const utils_1 = require("../../dwc/utils");
10
+ const addCommands = async (program) => {
11
+ const configCommand = await (0, commands_1.buildCommand)(program, {
12
+ type: "topCommand",
13
+ command: "config",
14
+ description: "configure your CLI",
15
+ subCommands: [],
16
+ });
17
+ await (0, utils_1.addCommandsFromFolder)(path_1.default.join(__dirname), configCommand);
18
+ };
19
+ exports.addCommands = addCommands;
@@ -1,2 +1,2 @@
1
- import { AddCommands } from "../types";
1
+ import { AddCommands } from "../../types";
2
2
  export declare const addCommands: AddCommands;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addCommands = void 0;
4
- const config_1 = require("../config");
5
- const core_1 = require("../config/core");
6
- const constants_1 = require("../constants");
7
- const logger_1 = require("../logger");
8
- const commands_1 = require("../utils/commands");
9
- const handler_1 = require("./handler");
10
- const passcode = () => async () => {
4
+ const config_1 = require("../../config");
5
+ const core_1 = require("../../config/core");
6
+ const constants_1 = require("../../constants");
7
+ const logger_1 = require("../../logger");
8
+ const commands_1 = require("../../utils/commands");
9
+ const handler_1 = require("../handler");
10
+ const passcode = async () => async () => {
11
11
  const { output } = (0, logger_1.get)("commands.passcode");
12
12
  const config = (0, config_1.get)();
13
13
  output(config.passcodeUrl);
@@ -20,7 +20,7 @@ const passcodeCommand = {
20
20
  };
21
21
  const addCommands = async (program) => {
22
22
  if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
23
- (0, commands_1.buildCommand)(program, passcodeCommand);
23
+ await (0, commands_1.buildCommand)(program, passcodeCommand);
24
24
  }
25
25
  };
26
26
  exports.addCommands = addCommands;
@@ -1,3 +1,3 @@
1
- import { TopCommand } from "../../types";
1
+ import { TopCommand } from "../../../types";
2
2
  declare const secretsCommand: TopCommand;
3
3
  export default secretsCommand;