Skip to content

Commit b7a128c

Browse files
authored
Docs db - get connection string (#128)
* Docs db - get connection string * Example is back * v4.7.2 * rename to database * linter fixes
1 parent e8a9cc8 commit b7a128c

7 files changed

Lines changed: 159 additions & 29 deletions

File tree

README.md

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $ npm install -g @mondaycom/apps-cli
1616
$ mapps COMMAND
1717
running command...
1818
$ mapps (--version)
19-
@mondaycom/apps-cli/4.7.0 darwin-arm64 node-v18.12.1
19+
@mondaycom/apps-cli/4.7.2 darwin-arm64 node-v18.12.1
2020
$ mapps --help [COMMAND]
2121
USAGE
2222
$ mapps COMMAND
@@ -43,6 +43,7 @@ USAGE
4343
* [`mapps code:push`](#mapps-codepush)
4444
* [`mapps code:secret`](#mapps-codesecret)
4545
* [`mapps code:status`](#mapps-codestatus)
46+
* [`mapps database:connection-string`](#mapps-databaseconnection-string)
4647
* [`mapps help [COMMANDS]`](#mapps-help-commands)
4748
* [`mapps init`](#mapps-init)
4849
* [`mapps scheduler:create`](#mapps-schedulercreate)
@@ -71,7 +72,7 @@ DESCRIPTION
7172
[@mondaydotcomorg/setup-api](https://github.com/mondaycom/monday-graphql-api/tree/main/packages/setup-api)
7273
```
7374

74-
_See code: [src/commands/api/generate.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/api/generate.ts)_
75+
_See code: [src/commands/api/generate.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/api/generate.ts)_
7576

7677
## `mapps app-features:build`
7778

@@ -101,7 +102,7 @@ EXAMPLES
101102
$ mapps app-features:build -a APP_ID -i APP_VERSION_ID -d APP_FEATURE_ID -t BUILD_TYPE -u CUSTOM_URL
102103
```
103104

104-
_See code: [src/commands/app-features/build.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app-features/build.ts)_
105+
_See code: [src/commands/app-features/build.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app-features/build.ts)_
105106

106107
## `mapps app-features:create`
107108

@@ -128,7 +129,7 @@ EXAMPLES
128129
$ mapps app-features:create -a APP_ID -i APP_VERSION_ID -t APP-FEATURE-TYPE
129130
```
130131

131-
_See code: [src/commands/app-features/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app-features/create.ts)_
132+
_See code: [src/commands/app-features/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app-features/create.ts)_
132133

133134
## `mapps app-features:list`
134135

@@ -153,7 +154,7 @@ EXAMPLES
153154
$ mapps app-features:list -a APP_ID -i APP_VERSION_ID
154155
```
155156

156-
_See code: [src/commands/app-features/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app-features/list.ts)_
157+
_See code: [src/commands/app-features/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app-features/list.ts)_
157158

158159
## `mapps app-version:builds`
159160

@@ -177,7 +178,7 @@ EXAMPLES
177178
$ mapps app-version:builds -i APP_VERSION_ID
178179
```
179180

180-
_See code: [src/commands/app-version/builds.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app-version/builds.ts)_
181+
_See code: [src/commands/app-version/builds.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app-version/builds.ts)_
181182

182183
## `mapps app-version:list`
183184

@@ -201,7 +202,7 @@ EXAMPLES
201202
$ mapps app-version:list
202203
```
203204

204-
_See code: [src/commands/app-version/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app-version/list.ts)_
205+
_See code: [src/commands/app-version/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app-version/list.ts)_
205206

206207
## `mapps app:create`
207208

@@ -228,7 +229,7 @@ EXAMPLES
228229
$ mapps app:create -n NEW_APP_NAME
229230
```
230231

231-
_See code: [src/commands/app/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app/create.ts)_
232+
_See code: [src/commands/app/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app/create.ts)_
232233

233234
## `mapps app:deploy`
234235

@@ -258,7 +259,7 @@ EXAMPLES
258259
$ mapps app:deploy
259260
```
260261

261-
_See code: [src/commands/app/deploy.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app/deploy.ts)_
262+
_See code: [src/commands/app/deploy.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app/deploy.ts)_
262263

263264
## `mapps app:list`
264265

@@ -279,7 +280,7 @@ EXAMPLES
279280
$ mapps app:list
280281
```
281282

282-
_See code: [src/commands/app/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app/list.ts)_
283+
_See code: [src/commands/app/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app/list.ts)_
283284

284285
## `mapps app:promote`
285286

@@ -306,7 +307,7 @@ EXAMPLES
306307
$ mapps app:promote
307308
```
308309

309-
_See code: [src/commands/app/promote.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/app/promote.ts)_
310+
_See code: [src/commands/app/promote.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/app/promote.ts)_
310311

311312
## `mapps autocomplete [SHELL]`
312313

@@ -368,7 +369,7 @@ EXAMPLES
368369
$ mapps code:env
369370
```
370371

371-
_See code: [src/commands/code/env.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/code/env.ts)_
372+
_See code: [src/commands/code/env.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/code/env.ts)_
372373

373374
## `mapps code:logs`
374375

@@ -403,7 +404,7 @@ EXAMPLES
403404
$ mapps code:logs -i APP_VERSION_ID -t LOGS_TYPE
404405
```
405406

406-
_See code: [src/commands/code/logs.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/code/logs.ts)_
407+
_See code: [src/commands/code/logs.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/code/logs.ts)_
407408

408409
## `mapps code:push`
409410

@@ -438,7 +439,7 @@ EXAMPLES
438439
$ mapps code:push -a APP_ID_TO_PUSH
439440
```
440441

441-
_See code: [src/commands/code/push.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/code/push.ts)_
442+
_See code: [src/commands/code/push.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/code/push.ts)_
442443

443444
## `mapps code:secret`
444445

@@ -469,7 +470,7 @@ EXAMPLES
469470
$ mapps code:secret
470471
```
471472

472-
_See code: [src/commands/code/secret.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/code/secret.ts)_
473+
_See code: [src/commands/code/secret.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/code/secret.ts)_
473474

474475
## `mapps code:status`
475476

@@ -495,18 +496,42 @@ EXAMPLES
495496
$ mapps code:status -i APP_VERSION_ID
496497
```
497498

498-
_See code: [src/commands/code/status.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/code/status.ts)_
499+
_See code: [src/commands/code/status.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/code/status.ts)_
500+
501+
## `mapps database:connection-string`
502+
503+
Get the connection string for your app database.
504+
505+
```
506+
USAGE
507+
$ mapps database:connection-string [--verbose] [--print-command] [-a <value>]
508+
509+
FLAGS
510+
-a, --appId=<value> Select the app that you wish to retrieve the connection string for
511+
512+
GLOBAL FLAGS
513+
--print-command Print the command that was executed (optional).
514+
--verbose Print advanced logs (optional).
515+
516+
DESCRIPTION
517+
Get the connection string for your app database.
518+
519+
EXAMPLES
520+
$ mapps database:connection-string -a APP_ID
521+
```
522+
523+
_See code: [src/commands/database/connection-string.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/database/connection-string.ts)_
499524

500525
## `mapps help [COMMANDS]`
501526

502527
Display help for mapps.
503528

504529
```
505530
USAGE
506-
$ mapps help [COMMANDS...] [-n]
531+
$ mapps help [COMMANDS] [-n]
507532
508533
ARGUMENTS
509-
COMMANDS... Command to show help for.
534+
COMMANDS Command to show help for.
510535
511536
FLAGS
512537
-n, --nested-commands Include all nested commands in the output.
@@ -540,7 +565,7 @@ EXAMPLES
540565
$ mapps init -t SECRET_TOKEN
541566
```
542567

543-
_See code: [src/commands/init/index.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/init/index.ts)_
568+
_See code: [src/commands/init/index.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/init/index.ts)_
544569

545570
## `mapps scheduler:create`
546571

@@ -578,7 +603,7 @@ EXAMPLES
578603
$ mapps scheduler:create -a APP_ID -s "0 * * * *" -u "/my-endpoint" -r 3 -b 10 -t 60
579604
```
580605

581-
_See code: [src/commands/scheduler/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/scheduler/create.ts)_
606+
_See code: [src/commands/scheduler/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/scheduler/create.ts)_
582607

583608
## `mapps scheduler:delete`
584609

@@ -605,7 +630,7 @@ EXAMPLES
605630
$ mapps scheduler:delete -a APP_ID -n "my-job"
606631
```
607632

608-
_See code: [src/commands/scheduler/delete.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/scheduler/delete.ts)_
633+
_See code: [src/commands/scheduler/delete.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/scheduler/delete.ts)_
609634

610635
## `mapps scheduler:list`
611636

@@ -629,7 +654,7 @@ EXAMPLES
629654
$ mapps scheduler:list -a APP_ID
630655
```
631656

632-
_See code: [src/commands/scheduler/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/scheduler/list.ts)_
657+
_See code: [src/commands/scheduler/list.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/scheduler/list.ts)_
633658

634659
## `mapps scheduler:run`
635660

@@ -656,7 +681,7 @@ EXAMPLES
656681
$ mapps scheduler:run -a APP_ID -n "my-job"
657682
```
658683

659-
_See code: [src/commands/scheduler/run.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/scheduler/run.ts)_
684+
_See code: [src/commands/scheduler/run.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/scheduler/run.ts)_
660685

661686
## `mapps scheduler:update`
662687

@@ -694,7 +719,7 @@ EXAMPLES
694719
$ mapps scheduler:update -a APP_ID -n "my-job" -d "My description" -r 3 -b 10 -t 60
695720
```
696721

697-
_See code: [src/commands/scheduler/update.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/scheduler/update.ts)_
722+
_See code: [src/commands/scheduler/update.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/scheduler/update.ts)_
698723

699724
## `mapps storage:export`
700725

@@ -721,7 +746,7 @@ EXAMPLES
721746
$ mapps storage:export -a APP_ID -c CLIENT_ACCOUNT_ID -d FILE_FULL_PATH -f FILE_FORMAT
722747
```
723748

724-
_See code: [src/commands/storage/export.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/storage/export.ts)_
749+
_See code: [src/commands/storage/export.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/storage/export.ts)_
725750

726751
## `mapps storage:remove-data`
727752

@@ -747,7 +772,7 @@ EXAMPLES
747772
$ mapps storage:remove-data -a APP_ID -c CLIENT_ACCOUNT_ID
748773
```
749774

750-
_See code: [src/commands/storage/remove-data.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/storage/remove-data.ts)_
775+
_See code: [src/commands/storage/remove-data.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/storage/remove-data.ts)_
751776

752777
## `mapps storage:search`
753778

@@ -773,7 +798,7 @@ EXAMPLES
773798
$ mapps storage:search -a APP_ID -c CLIENT_ACCOUNT_ID -t TERM
774799
```
775800

776-
_See code: [src/commands/storage/search.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/storage/search.ts)_
801+
_See code: [src/commands/storage/search.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/storage/search.ts)_
777802

778803
## `mapps tunnel:create`
779804

@@ -804,5 +829,5 @@ EXAMPLES
804829
$ mapps tunnel:create -p PORT_FOR_TUNNEL -a APP_ID_FOR_TUNNEL
805830
```
806831

807-
_See code: [src/commands/tunnel/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.0/src/commands/tunnel/create.ts)_
832+
_See code: [src/commands/tunnel/create.ts](https://github.com/mondaycom/monday-apps-cli/blob/v4.7.2/src/commands/tunnel/create.ts)_
808833
<!-- commandsstop -->

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mondaycom/apps-cli",
3-
"version": "4.7.1",
3+
"version": "4.7.2",
44
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
55
"author": "monday.com Apps Team",
66
"type": "module",
@@ -134,6 +134,9 @@
134134
},
135135
"app-version": {
136136
"description": "Perform operations related to app versions in monday.com"
137+
},
138+
"database": {
139+
"description": "Perform operations related to app database"
137140
}
138141
},
139142
"hooks": {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Flags } from '@oclif/core';
2+
import chalk from 'chalk';
3+
4+
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
5+
import { VAR_UNKNOWN } from 'consts/messages';
6+
import { getDatabaseConnectionString } from 'services/database-service';
7+
import { DynamicChoicesService } from 'services/dynamic-choices-service';
8+
import { HttpError } from 'types/errors';
9+
import { AppId } from 'types/general';
10+
import logger from 'utils/logger';
11+
12+
export default class ConnectionString extends AuthenticatedCommand {
13+
static description = 'Get the connection string for your app database.';
14+
15+
static examples = ['<%= config.bin %> <%= command.id %> -a APP_ID'];
16+
17+
static flags = ConnectionString.serializeFlags({
18+
appId: Flags.integer({
19+
char: 'a',
20+
description: 'Select the app that you wish to retrieve the connection string for',
21+
}),
22+
});
23+
24+
public async run(): Promise<void> {
25+
const { flags } = await this.parse(ConnectionString);
26+
let { appId } = flags;
27+
try {
28+
if (!appId) {
29+
appId = await DynamicChoicesService.chooseApp();
30+
}
31+
32+
const result = await getDatabaseConnectionString(appId);
33+
34+
logger.log(chalk.green('✓ Connection string retrieved successfully:'));
35+
logger.log(chalk.cyan(result.connectionString));
36+
37+
this.preparePrintCommand(this, { appId });
38+
} catch (error: unknown) {
39+
logger.debug(error);
40+
if (error instanceof HttpError) {
41+
logger.error(`\n ${chalk.italic(chalk.red(error.message))}`);
42+
} else {
43+
logger.error(
44+
`An unknown error happened while fetching connection string for app id - "${appId || VAR_UNKNOWN}"`,
45+
);
46+
}
47+
48+
process.exit(1);
49+
}
50+
}
51+
}

src/consts/urls.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,7 @@ export const pullPromoteStatusUrl = (path: string): string => {
122122
export const appSchedulerUrl = (appId: AppId): string => {
123123
return `${BASE_MONDAY_CODE_URL}/${appId}/scheduler`;
124124
};
125+
126+
export const appStorageConnectionStringUrl = (appId: AppId): string => {
127+
return `${BASE_MONDAY_CODE_URL}/${appId}/storage/connection-string`;
128+
};

src/services/database-service.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { appStorageConnectionStringUrl } from 'consts/urls';
2+
import { execute } from 'services/api-service';
3+
import { databaseConnectionStringResponseSchema } from 'services/schemas/database-service-schemas';
4+
import { HttpError } from 'types/errors';
5+
import { AppId } from 'types/general';
6+
import { HttpMethodTypes } from 'types/services/api-service';
7+
import { DatabaseConnectionStringResponseSchema } from 'types/services/database-service';
8+
import logger from 'utils/logger';
9+
import { appsUrlBuilder } from 'utils/urls-builder';
10+
11+
export const getDatabaseConnectionString = async (appId: AppId): Promise<DatabaseConnectionStringResponseSchema> => {
12+
const DEBUG_TAG = 'get_database_connection_string';
13+
try {
14+
const baseUrl = appStorageConnectionStringUrl(appId);
15+
const url = appsUrlBuilder(baseUrl);
16+
const response = await execute<DatabaseConnectionStringResponseSchema>(
17+
{
18+
url,
19+
headers: { Accept: 'application/json' },
20+
method: HttpMethodTypes.GET,
21+
},
22+
databaseConnectionStringResponseSchema,
23+
);
24+
return response;
25+
} catch (error: any | HttpError) {
26+
logger.debug(error, DEBUG_TAG);
27+
if (error instanceof HttpError) {
28+
throw error;
29+
}
30+
31+
throw new Error('Failed to fetch database connection string.');
32+
}
33+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { z } from 'zod';
2+
3+
import { baseResponseHttpMetaDataSchema } from 'services/schemas/api-service-schemas';
4+
5+
export const databaseConnectionStringResponseSchema = z
6+
.object({
7+
connectionString: z.string(),
8+
})
9+
.merge(baseResponseHttpMetaDataSchema);

0 commit comments

Comments
 (0)